private SecurityIdentity authenticate ( final String username , final String password ) { ServerAuthenticationContext context = this . securityDomain . createNewAuthenticationContext ( ) ; PasswordGuessEvidence evidence = null ; try { if ( password == null ) { if ( username == null ) { if ( context . authorizeAnonymous ( ) ) { context . succeed ( ) ; return context . getAuthorizedIdentity ( ) ; } else { context . fail ( ) ; return null ; } } else { // treat a non-null user name with a null password as a auth failure context . fail ( ) ; return null ; } } context . setAuthenticationName ( username ) ; evidence = new PasswordGuessEvidence ( password . toCharArray ( ) ) ; if ( context . verifyEvidence ( evidence ) ) { if ( context . authorize ( ) ) { context . succeed ( ) ; return context . getAuthorizedIdentity ( ) ; } else { context . fail ( ) ; MessagingLogger . ROOT_LOGGER . failedAuthorization ( username ) ; } } else { context . fail ( ) ; MessagingLogger . ROOT_LOGGER . failedAuthentication ( username ) ; } } catch ( IllegalArgumentException | IllegalStateException | RealmUnavailableException e ) { context . fail ( ) ; MessagingLogger . ROOT_LOGGER . failedAuthenticationWithException ( e , username , e . getMessage ( ) ) ; } finally { if ( evidence != null ) { evidence . destroy ( ) ; } } return null ; }
Attempt to authenticate and authorize an username with the specified password evidence .