...
Code Block | ||
---|---|---|
| ||
/** * Authenticates where the presented password is the integer length of the * username. */ public class UsernameLengthAuthnHandler implements AuthenticationHandler { public boolean authenticate(Credentials credentials) throws AuthenticationException { UsernamePasswordCredentials upCredentials = (UsernamePasswordCredentials) credentials; String username = upCredentials.getUsername(); String password = upCredentials.getPassword(); String correctPassword = Integer.toString(username.length()); return correctPassword.equals(password); } public boolean supports(Credentials credentials) { // we support credentials that bear usernames and passwords return credentials instanceof UsernamePasswordCredentials; } } |
See the RemoteUserAuthnHandler Using the REMOTE_USER example for a more advanced example of coding directly to AuthenticationHandler to accomplish something other than username and password authentication.
...