Первый шаг ,
Ваш WebSecurityConfig должен быть таким,
@Configuration
@Order(SecurityProperties.ACCESS_OVERRIDE_ORDER)
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private CustomAuthenticationProvider authProvider;
@Override
protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http.formLogin().loginPage("/login").permitAll().and().requestMatchers()
.antMatchers("/login", "/oauth/authorize", "/oauth/confirm_access").and().authorizeRequests()
.anyRequest().authenticated();
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.authenticationProvider(authProvider);
}
}
Второй шаг ,
Вам нужно создать свой собственный класс для реализации AuthenticationProvider, это должно быть так
@Component
public class CustomAuthenticationProvider implements AuthenticationProvider {
public static final Logger logger = org.slf4j.LoggerFactory.getLogger(CustomAuthenticationProvider.class);
@Autowired
AuthenicationService authenicationService;
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
String name = authentication.getName();
String password = authentication.getCredentials().toString();
logger.info("Username:" + name + " Password:" + password);
ReturnResult result = authenicationService.authenicate(); // against third party authenicate
if (result.isStatus()) {
return new UsernamePasswordAuthenticationToken(name, password, new ArrayList<>());
} else {
throw new BadCredentialsException(result.getMsg());
}
}
@Override
public boolean supports(Class<?> authentication) {
return authentication.equals(UsernamePasswordAuthenticationToken.class);
}
}