Actual username and password comparisons happen at authentication provider. UsernamePasswordAuthenticationFilter obtains username/pwd and passes on to authenticationManager, which inturn delegates it to authenticationProvider. In your case, you need to add a custom authentication provider as follows:
@Component
public class CustomAuthenticationProvider implements AuthenticationProvider {
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
String username = authentication.getName();
String password = authentication.getCredentials().toString();
if(username.equals("user123") && password.equals("password123")) {
List<GrantedAuthority> grantedAuths = new ArrayList<>();
grantedAuths.add(new SimpleGrantedAuthority("ROLE_USER")); //assign some role
Authentication auth = new UsernamePasswordAuthenticationToken(username, password, grantedAuths);
return auth; //return Authentication object, not true
} else {
return null;
}
}
@Override
public boolean supports(Class<?> authentication) {
return authentication.equals(UsernamePasswordAuthenticationToken.class);
}
}
declare the new authentication provider in our configuration:
<authentication-manager>
<authentication-provider ref="customAuthenticationProvider"/>
</authentication-manager>
Reference:
https://danielkaes.wordpress.com/2013/02/20/custom-authentication-provider-in-spring/