"RequestParameterAuthenticationFilter.DEBUG_AUTH_USERID", username ) ); //$NON-NLS-1$
}
if ( ( username != null ) && ( password != null ) ) {
// Only reauthenticate if username doesn't match SecurityContextHolder and user isn't authenticated (see SEC-53)
Authentication existingAuth = SecurityContextHolder.getContext().getAuthentication();
password = Encr.decryptPasswordOptionallyEncrypted( password );
if ( ( existingAuth == null ) || !existingAuth.getName().equals( username ) || !existingAuth.isAuthenticated() ) {
UsernamePasswordAuthenticationToken authRequest = new UsernamePasswordAuthenticationToken( username, password );
authRequest.setDetails( new WebAuthenticationDetails( httpRequest ) );
Authentication authResult;
try {
authResult = authenticationManager.authenticate( authRequest );
} catch ( AuthenticationException failed ) {
// Authentication failed
if ( RequestParameterAuthenticationFilter.logger.isDebugEnabled() ) {
RequestParameterAuthenticationFilter.logger.debug( Messages.getInstance().getString(
"RequestParameterAuthenticationFilter.DEBUG_AUTHENTICATION_REQUEST", username, failed.toString() ) ); //$NON-NLS-1$
}
SecurityContextHolder.getContext().setAuthentication( null );
if ( ignoreFailure ) {
chain.doFilter( wrapper, response );
} else {
authenticationEntryPoint.commence( wrapper, response, failed );
}
return;
}
// Authentication success
if ( RequestParameterAuthenticationFilter.logger.isDebugEnabled() ) {
RequestParameterAuthenticationFilter.logger.debug( Messages.getInstance().getString(
"RequestParameterAuthenticationFilter.DEBUG_AUTH_SUCCESS", authResult.toString() ) ); //$NON-NLS-1$
}
SecurityContextHolder.getContext().setAuthentication( authResult );
}
}