mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-06-27 06:12:27 +00:00
Add hook methods to AbstractProcessingFilter.
This commit is contained in:
parent
67d642cfeb
commit
823a2e990b
@ -311,83 +311,110 @@ public abstract class AbstractProcessingFilter implements Filter,
|
|||||||
logger.debug("Request is to process authentication");
|
logger.debug("Request is to process authentication");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onPreAuthentication(httpRequest, httpResponse);
|
||||||
|
|
||||||
Authentication authResult;
|
Authentication authResult;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
authResult = attemptAuthentication(httpRequest);
|
authResult = attemptAuthentication(httpRequest);
|
||||||
} catch (AuthenticationException failed) {
|
} catch (AuthenticationException failed) {
|
||||||
// Authentication failed
|
// Authentication failed
|
||||||
String failureUrl = authenticationFailureUrl;
|
unsuccessfulAuthentication(httpRequest, httpResponse, failed);
|
||||||
|
|
||||||
if (failed instanceof AuthenticationServiceException
|
|
||||||
&& (authenticationServiceFailureUrl != null)) {
|
|
||||||
failureUrl = authenticationServiceFailureUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (failed instanceof BadCredentialsException
|
|
||||||
&& (this.authenticationCredentialCheckFailureUrl != null)) {
|
|
||||||
failureUrl = authenticationCredentialCheckFailureUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (failed instanceof DisabledException
|
|
||||||
&& (authenticationDisabledFailureUrl != null)) {
|
|
||||||
failureUrl = authenticationDisabledFailureUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (failed instanceof LockedException
|
|
||||||
&& (authenticationLockedFailureUrl != null)) {
|
|
||||||
failureUrl = authenticationLockedFailureUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (failed instanceof ProxyUntrustedException
|
|
||||||
&& (authenticationProxyUntrustedFailureUrl != null)) {
|
|
||||||
failureUrl = authenticationProxyUntrustedFailureUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (logger.isDebugEnabled()) {
|
|
||||||
logger.debug("Authentication request failed: "
|
|
||||||
+ failed.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
httpRequest.getSession().setAttribute(ACEGI_SECURITY_LAST_EXCEPTION_KEY,
|
|
||||||
failed);
|
|
||||||
httpRequest.getSession().removeAttribute(HttpSessionIntegrationFilter.ACEGI_SECURITY_AUTHENTICATION_KEY);
|
|
||||||
httpResponse.sendRedirect(httpResponse.encodeRedirectURL(httpRequest
|
|
||||||
.getContextPath() + failureUrl));
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Authentication success
|
// Authentication success
|
||||||
if (logger.isDebugEnabled()) {
|
successfulAuthentication(httpRequest, httpResponse, authResult);
|
||||||
logger.debug("Authentication success: " + authResult.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
httpRequest.getSession().setAttribute(HttpSessionIntegrationFilter.ACEGI_SECURITY_AUTHENTICATION_KEY,
|
|
||||||
authResult);
|
|
||||||
|
|
||||||
String targetUrl = (String) httpRequest.getSession().getAttribute(ACEGI_SECURITY_TARGET_URL_KEY);
|
|
||||||
httpRequest.getSession().removeAttribute(ACEGI_SECURITY_TARGET_URL_KEY);
|
|
||||||
|
|
||||||
if (alwaysUseDefaultTargetUrl == true) {
|
|
||||||
targetUrl = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (targetUrl == null) {
|
|
||||||
targetUrl = httpRequest.getContextPath() + defaultTargetUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (logger.isDebugEnabled()) {
|
|
||||||
logger.debug(
|
|
||||||
"Redirecting to target URL from HTTP Session (or default): "
|
|
||||||
+ targetUrl);
|
|
||||||
}
|
|
||||||
|
|
||||||
httpResponse.sendRedirect(httpResponse.encodeRedirectURL(targetUrl));
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
chain.doFilter(request, response);
|
chain.doFilter(request, response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void onPreAuthentication(HttpServletRequest request,
|
||||||
|
HttpServletResponse response) throws IOException {}
|
||||||
|
|
||||||
|
protected void onSuccessfulAuthentication(HttpServletRequest request,
|
||||||
|
HttpServletResponse response) throws IOException {}
|
||||||
|
|
||||||
|
protected void onUnsuccessfulAuthentication(HttpServletRequest request,
|
||||||
|
HttpServletResponse response) throws IOException {}
|
||||||
|
|
||||||
|
protected void successfulAuthentication(HttpServletRequest request,
|
||||||
|
HttpServletResponse response, Authentication authResult)
|
||||||
|
throws IOException {
|
||||||
|
if (logger.isDebugEnabled()) {
|
||||||
|
logger.debug("Authentication success: " + authResult.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
request.getSession().setAttribute(HttpSessionIntegrationFilter.ACEGI_SECURITY_AUTHENTICATION_KEY,
|
||||||
|
authResult);
|
||||||
|
|
||||||
|
String targetUrl = (String) request.getSession().getAttribute(ACEGI_SECURITY_TARGET_URL_KEY);
|
||||||
|
request.getSession().removeAttribute(ACEGI_SECURITY_TARGET_URL_KEY);
|
||||||
|
|
||||||
|
if (alwaysUseDefaultTargetUrl == true) {
|
||||||
|
targetUrl = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (targetUrl == null) {
|
||||||
|
targetUrl = request.getContextPath() + defaultTargetUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (logger.isDebugEnabled()) {
|
||||||
|
logger.debug(
|
||||||
|
"Redirecting to target URL from HTTP Session (or default): "
|
||||||
|
+ targetUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
onSuccessfulAuthentication(request, response);
|
||||||
|
|
||||||
|
response.sendRedirect(response.encodeRedirectURL(targetUrl));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void unsuccessfulAuthentication(HttpServletRequest request,
|
||||||
|
HttpServletResponse response, AuthenticationException failed)
|
||||||
|
throws IOException {
|
||||||
|
String failureUrl = authenticationFailureUrl;
|
||||||
|
|
||||||
|
if (failed instanceof AuthenticationServiceException
|
||||||
|
&& (authenticationServiceFailureUrl != null)) {
|
||||||
|
failureUrl = authenticationServiceFailureUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (failed instanceof BadCredentialsException
|
||||||
|
&& (this.authenticationCredentialCheckFailureUrl != null)) {
|
||||||
|
failureUrl = authenticationCredentialCheckFailureUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (failed instanceof DisabledException
|
||||||
|
&& (authenticationDisabledFailureUrl != null)) {
|
||||||
|
failureUrl = authenticationDisabledFailureUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (failed instanceof LockedException
|
||||||
|
&& (authenticationLockedFailureUrl != null)) {
|
||||||
|
failureUrl = authenticationLockedFailureUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (failed instanceof ProxyUntrustedException
|
||||||
|
&& (authenticationProxyUntrustedFailureUrl != null)) {
|
||||||
|
failureUrl = authenticationProxyUntrustedFailureUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (logger.isDebugEnabled()) {
|
||||||
|
logger.debug("Authentication request failed: " + failed.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
request.getSession().setAttribute(ACEGI_SECURITY_LAST_EXCEPTION_KEY,
|
||||||
|
failed);
|
||||||
|
request.getSession().removeAttribute(HttpSessionIntegrationFilter.ACEGI_SECURITY_AUTHENTICATION_KEY);
|
||||||
|
|
||||||
|
onUnsuccessfulAuthentication(request, response);
|
||||||
|
|
||||||
|
response.sendRedirect(response.encodeRedirectURL(request.getContextPath()
|
||||||
|
+ failureUrl));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -52,6 +52,7 @@
|
|||||||
<action dev="benalex" type="update">Made DaoAuthenticationProvider detect null in Authentication.principal</action>
|
<action dev="benalex" type="update">Made DaoAuthenticationProvider detect null in Authentication.principal</action>
|
||||||
<action dev="benalex" type="update">Improved JaasAuthenticationProvider startup error detection</action>
|
<action dev="benalex" type="update">Improved JaasAuthenticationProvider startup error detection</action>
|
||||||
<action dev="benalex" type="update">Refactored EH-CACHE implementations to use Spring IoC defined caches instead</action>
|
<action dev="benalex" type="update">Refactored EH-CACHE implementations to use Spring IoC defined caches instead</action>
|
||||||
|
<action dev="benalex" type="update">AbstractProcessingFilter now has various hook methods to assist subclasses</action>
|
||||||
<action dev="benalex" type="fix">Fixed ambiguous column references in JdbcDaoImpl default query</action>
|
<action dev="benalex" type="fix">Fixed ambiguous column references in JdbcDaoImpl default query</action>
|
||||||
<action dev="benalex" type="fix">Fixed AbstractProcessingFilter to use removeAttribute (JRun compatibility)</action>
|
<action dev="benalex" type="fix">Fixed AbstractProcessingFilter to use removeAttribute (JRun compatibility)</action>
|
||||||
<action dev="benalex" type="fix">Fixed GrantedAuthorityEffectiveAclResolver support of UserDetails principals</action>
|
<action dev="benalex" type="fix">Fixed GrantedAuthorityEffectiveAclResolver support of UserDetails principals</action>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user