@Component
public class CustomAuthenticationProvider 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);
}
}
1 回答
好像你需要实现自己的
AuthenticationProvider
. 见下面的代码:代码来自:http://www.baeldung.com/spring-security-authentication-provider
在
shouldAuthenticateAgainstThirdPartySystem
中,您可以检查请求(https://stackoverflow.com/a/26323545/878361)并决定使用ldap或sso .