title: In Spring security how initialise User -(org.springframework.security.core.userdetails.User)
body: <p>I just initialize User(org.springframework.security.core.userdetails.User) like this, in one service class, which implements UserDetailsService(org.springframework.security.core.userdetails),</p>
  
  <p><code>User user=new User(null, null, false, false, false, false, null);</code></p>
  
  <p>but it shows error </p>
  
  <p>java.lang.IllegalArgumentException: <strong>Cannot pass null or empty values to constructor</strong></p>
  
  <p>then how can I initialize this User object?</p>
  
  <p><strong>method</strong></p>
  
  <pre><code>public UserDetails loadUserByUsernameAndUsertype(String username, String type) throws
          UsernameNotFoundException {
  
      User user = new User(null, null, false, false, false, false, null);
  
      try {
  
          if (type.equals("normalUser")) {
              com.booktheservice.entity.NormalUser normalUser = normalUserService.readSpecific("name", username);
  
              boolean enabled = true;
              boolean accountNonExpired = true;
              boolean credentialsNonExpired = true;
              boolean accountNonLocked = true;
              user = new User(
                      normalUser.getName(),
                      normalUser.getPassword().toLowerCase(),
                      enabled,
                      accountNonExpired,
                      credentialsNonExpired,
                      accountNonLocked,
                      getAuthorities("normalUser", false));
  
  
          }
          if (type.equals("adminUser")) {
              com.booktheservice.entity.AdminUser adminUser = adminUserService.readSpecific("name", username);
  
              boolean enabled = true;
              boolean accountNonExpired = true;
              boolean credentialsNonExpired = true;
              boolean accountNonLocked = true;
  
              user = new User(
                      adminUser.getName(),
                      adminUser.getPassword().toLowerCase(),
                      enabled,
                      accountNonExpired,
                      credentialsNonExpired,
                      accountNonLocked,
                      getAuthorities("adminUser", false));
  
          }
  
          if (type.equals("serviceLister")) {
              com.booktheservice.entity.ServiceLister serviceLister = serviceListerService.readSpecific("name", username);
  
              boolean enabled = true;
              boolean accountNonExpired = true;
              boolean credentialsNonExpired = true;
              boolean accountNonLocked = true;
  
              user = new User(
                      serviceLister.getName(),
                      serviceLister.getPassword().toLowerCase(),
                      enabled,
                      accountNonExpired,
                      credentialsNonExpired,
                      accountNonLocked,
                      getAuthorities("serviceLister", false));
  
          }
          return user;
      } catch (Exception e) {
          e.printStackTrace();
          throw new RuntimeException(e);
      }
  }
  </code></pre>