Уже вы автоматически подключили провайдера CustomAuthentication с помощью
@Autowired
private SecurmailSecurityProvider provider;
, снова создавая компонент и передавая провайдеру CustomAuthentication
@Bean
protected AuthenticationProvider getKBServicesAuthenticationProvider() {
return new SecurmailSecurityProvider();
}
Вместо кода ниже
@Autowired
private SecurmailSecurityProvider provider;
@Override
protected void configure(AuthenticationManagerBuilder authentication) throws Exception {
authentication.authenticationProvider( getKBServicesAuthenticationProvider());
}
@Bean
protected AuthenticationProvider getKBServicesAuthenticationProvider() {
return new SecurmailSecurityProvider();
}
Используйте этот код
@Autowired
private SecurmailSecurityProvider provider;
@Override
protected void configure(AuthenticationManagerBuilder authentication) throws Exception {
authentication.authenticationProvider(provider);
}
А также реализация поставщика нестандартной аутентификации должна быть такой, как показано ниже:
@Component
public class SecurmailSecurityProvider implements AuthenticationProvider {
@Override
public Authentication authenticate(Authentication authentication)
throws AuthenticationException {
String name = authentication.getName();
String password = authentication.getCredentials().toString();
if (shouldAuthenticateAgainstThirdPartySystem()) {
// use the credentials
// and authenticate against the third-party system
return new UsernamePasswordAuthenticationToken(
name, password, new ArrayList<>());
} else {
return null;
}
}
@Override
public boolean supports(Class<?> authentication) {
return authentication.equals(UsernamePasswordAuthenticationToken.class);
}
}