mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-06-26 22:02:41 +00:00
Added extra logging.
This commit is contained in:
parent
7109b7e183
commit
bf39a5bb36
@ -5,6 +5,9 @@ import java.io.IOException;
|
|||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simple implementation of <tt>RedirectStrategy</tt> which is the default used throughout the framework.
|
* Simple implementation of <tt>RedirectStrategy</tt> which is the default used throughout the framework.
|
||||||
*
|
*
|
||||||
@ -13,6 +16,8 @@ import javax.servlet.http.HttpServletResponse;
|
|||||||
* @since 3.0
|
* @since 3.0
|
||||||
*/
|
*/
|
||||||
public class DefaultRedirectStrategy implements RedirectStrategy {
|
public class DefaultRedirectStrategy implements RedirectStrategy {
|
||||||
|
protected final Log logger = LogFactory.getLog(getClass());
|
||||||
|
|
||||||
private boolean contextRelative;
|
private boolean contextRelative;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -46,6 +51,10 @@ public class DefaultRedirectStrategy implements RedirectStrategy {
|
|||||||
finalUrl = url;
|
finalUrl = url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (logger.isDebugEnabled()) {
|
||||||
|
logger.debug("Redirecting to '" + finalUrl + "'");
|
||||||
|
}
|
||||||
|
|
||||||
response.sendRedirect(response.encodeRedirectURL(finalUrl));
|
response.sendRedirect(response.encodeRedirectURL(finalUrl));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,6 +6,8 @@ import javax.servlet.ServletException;
|
|||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.springframework.security.core.AuthenticationException;
|
import org.springframework.security.core.AuthenticationException;
|
||||||
import org.springframework.security.web.DefaultRedirectStrategy;
|
import org.springframework.security.web.DefaultRedirectStrategy;
|
||||||
import org.springframework.security.web.RedirectStrategy;
|
import org.springframework.security.web.RedirectStrategy;
|
||||||
@ -26,6 +28,8 @@ import org.springframework.util.Assert;
|
|||||||
* @since 3.0
|
* @since 3.0
|
||||||
*/
|
*/
|
||||||
public class SimpleUrlAuthenticationFailureHandler implements AuthenticationFailureHandler {
|
public class SimpleUrlAuthenticationFailureHandler implements AuthenticationFailureHandler {
|
||||||
|
protected final Log logger = LogFactory.getLog(getClass());
|
||||||
|
|
||||||
private String defaultFailureUrl;
|
private String defaultFailureUrl;
|
||||||
private boolean forwardToDestination = false;
|
private boolean forwardToDestination = false;
|
||||||
private RedirectStrategy redirectStrategy = new DefaultRedirectStrategy();
|
private RedirectStrategy redirectStrategy = new DefaultRedirectStrategy();
|
||||||
@ -39,12 +43,18 @@ public class SimpleUrlAuthenticationFailureHandler implements AuthenticationFail
|
|||||||
|
|
||||||
public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response,
|
public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response,
|
||||||
AuthenticationException exception) throws IOException, ServletException {
|
AuthenticationException exception) throws IOException, ServletException {
|
||||||
|
|
||||||
if (defaultFailureUrl == null) {
|
if (defaultFailureUrl == null) {
|
||||||
|
logger.debug("No failure URL set, sending 401 Unauthorized error");
|
||||||
|
|
||||||
response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Authentication Failed: " + exception.getMessage());
|
response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Authentication Failed: " + exception.getMessage());
|
||||||
} else {
|
} else {
|
||||||
if (forwardToDestination) {
|
if (forwardToDestination) {
|
||||||
|
logger.debug("Forwarding to " + defaultFailureUrl);
|
||||||
|
|
||||||
request.getRequestDispatcher(defaultFailureUrl).forward(request, response);
|
request.getRequestDispatcher(defaultFailureUrl).forward(request, response);
|
||||||
} else {
|
} else {
|
||||||
|
logger.debug("Redirecting to " + defaultFailureUrl);
|
||||||
redirectStrategy.sendRedirect(request, response, defaultFailureUrl);
|
redirectStrategy.sendRedirect(request, response, defaultFailureUrl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user