Skip to content

Instantly share code, notes, and snippets.

@MafaldaLandeiro
Created March 31, 2016 22:11
Show Gist options
  • Select an option

  • Save MafaldaLandeiro/def2280e05f26087c99b7a14fcc93041 to your computer and use it in GitHub Desktop.

Select an option

Save MafaldaLandeiro/def2280e05f26087c99b7a14fcc93041 to your computer and use it in GitHub Desktop.
Access denied exception handler
package org.springSecurityLogin.exception;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;
public class AccessDeniedExceptionHandler implements AccessDeniedHandler {
private String errorPage;
public AccessDeniedExceptionHandler() {
}
public AccessDeniedExceptionHandler(String errorPage) {
this.errorPage = errorPage;
}
public String getErrorPage() {
return errorPage;
}
public void setErrorPage(String errorPage) {
this.errorPage = errorPage;
}
@Override
public void handle(HttpServletRequest arg0, HttpServletResponse arg1,
AccessDeniedException arg2) throws IOException, ServletException {
arg1.sendRedirect(errorPage);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment