Created
February 22, 2016 18:28
-
-
Save Cameron-C-Chapman/58b0a902ca64d16103d5 to your computer and use it in GitHub Desktop.
Spring Security custom AccessDeniedHandler
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package package.name; | |
import java.io.IOException; | |
import javax.servlet.ServletException; | |
import javax.servlet.http.HttpServletRequest; | |
import javax.servlet.http.HttpServletResponse; | |
import org.springframework.beans.factory.annotation.Value; | |
import org.springframework.security.access.AccessDeniedException; | |
import org.springframework.security.web.DefaultRedirectStrategy; | |
import org.springframework.security.web.RedirectStrategy; | |
import org.springframework.security.web.access.AccessDeniedHandler; | |
public class AccessDeniedHandlerImpl implements AccessDeniedHandler { | |
@Value("${accessDeniedUrl}") | |
private String accessDeniedUrl; | |
private RedirectStrategy redirectStrategy = new DefaultRedirectStrategy(); | |
@Override | |
public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException exception) throws IOException, ServletException { | |
redirectStrategy.sendRedirect(request, response, accessDeniedUrl); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment