2016-08-25 4 views
0

Я пытаюсь выполнить процесс входа в систему с весенней загрузкой, oauth2 и весной. Я внедрил пользовательскую службу userdetails.Spring security userdetails: org.springframework.security.authentication.DisabledException

Вот код:

@Service("customUserDetailsService") 
public class CustomUserDetailsService implements UserDetailsService { 

    private final UserService userService; 

    @Autowired 
    public CustomUserDetailsService(UserService userService) { 
     this.userService = userService; 
    } 

    @Override 
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { 
     User user = userService.findByUsername(username); 
     if (user == null) 
      throw new UsernameNotFoundException(String.format("User %s does not exist!", username)); 
     return new UserRepositoryUserDetails(user); 
    } 

    private final static class UserRepositoryUserDetails extends User implements UserDetails { 

     private static final long serialVersionUID = 1L; 

     private UserRepositoryUserDetails(User user) { 
      super(user); 
     } 

     @Override 
     public Collection<? extends GrantedAuthority> getAuthorities() { 
      return getRoles(); 
     } 

     // another methods 

     @Override 
     public boolean isEnabled() { return super.isEnabled(); } 
    } 
} 

Пользователь объект:

@Entity 
@Table 
public class User implements Serializable { 

    private static final long serialVersionUID = 1L; 

    @Id 
    @GeneratedValue(generator = "uuid2") 
    @GenericGenerator(name = "uuid2", strategy = "uuid2") 
    @Column(name = "id", columnDefinition = "VARCHAR(50)") 
    private String userUUId; 

    // another parametes 
    @Column(nullable = false, columnDefinition = "TINYINT DEFAULT false") 
    @Type(type = "org.hibernate.type.NumericBooleanType") 
    private boolean enabled; 

    public User() { 
    } 

    public User(User user) { 
     super(); 
     this.userUUId = user.getUserUUId(); 
     this.roles = user.getRoles(); 
     this.name = user.getName(); 
     this.email = user.getEmail(); 
     this.enabled = isEnabled(); 
     this.password = user.getPassword(); 
    } 
    // ... 
    public boolean isEnabled() { 
     return enabled; 
    } 

    public void setEnabled(boolean enabled) { 
     this.enabled = enabled; 
    } 
} 

Конфигурация безопасности:

@Configuration 
public class SecurityConfiguration extends WebSecurityConfigurerAdapter { 

    @Autowired 
    private CustomUserDetailsService customUserDetailsService; 

    @Override 
    protected void configure(AuthenticationManagerBuilder auth) throws Exception { 
     auth.userDetailsService(customUserDetailsService); 
    } 

    @Override 
    @Bean 
    public AuthenticationManager authenticationManagerBean() throws Exception { 
     return super.authenticationManagerBean(); 
    } 
} 

И часть конфигурации authorizationserver:

@Configuration 
    @EnableAuthorizationServer 
    @Order(SecurityProperties.ACCESS_OVERRIDE_ORDER) 
    protected static class AuthorizationServerConfiguration extends AuthorizationServerConfigurerAdapter { 

     @Bean(name = "tokenStore") 
     public TokenStore tokenStore() { 
      return new InMemoryTokenStore(); 
     } 

     @Autowired 
     private CustomUserDetailsService customUserDetailsService; 

     @Autowired 
     private AuthenticationManager authenticationManager; 

     @Override 
     public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception { 
      endpoints 
       .tokenStore(tokenStore()) 
       .authenticationManager(authenticationManager) 
       .userDetailsService(customUserDetailsService); 
     } 

Здесь журнал ошибок:

type=AUTHENTICATION_FAILURE, data={type=org.springframework.security.authentication.DisabledException, message=User is disabled}] 
    [2016-08-25 09:23:17.774] boot - 21158 INFO [http-nio-8443-exec-1] --- TokenEndpoint: Handling error: InvalidGrantException, User is disabled 
[2016-08-25 09:23:17.832] boot - 21158 DEBUG [http-nio-8443-exec-1] --- OrderedRequestContextFilter: Cleared thread-bound request context: [email protected] 
[2016-08-25 09:23:17.837] boot - 21158 ERROR [http-nio-8443-exec-4] --- EndpointsAuthentification: org.springframework.web.client.HttpClientErrorException: 400 Bad Request 
[2016-08-25 09:23:17.839] boot - 21158 DEBUG [http-nio-8443-exec-4] --- OrderedRequestContextFilter: Cleared thread-bound request context: [email protected] 
[2016-08-25 09:23:17.840] boot - 21158 ERROR [http-nio-8443-exec-4] --- [dispatcherServlet]: Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause 
java.lang.NullPointerException 
     at com.x.server.controller.LoginController.login(LoginController.java:76) 

Но я уверен, что учетная запись пользователя включена. Вызов user.isEnabled возвращает true, но структура не может его обнаружить.

Любые идеи? Приветствие

+0

Вы можете разместить код пользователя? – mspapant

ответ

0

Вероятно включено поля в базе данных нуль или ложных

Смежные вопросы