认证、授权攻略三(5)、spring security自定义403页面

上一篇:【认证、授权攻略三(4)、spring security数据库认证JdbcDaoImpl(密码加密)】

spring-security.xml配置文件说明:



	
	
	
	
	
	
	
	
		
     	
     	
     	
     	
     	
      	
      	
      	
      	
      	
      	
      	
      	
     	
     	
     				
     	
     	
   	 
   	
   	
   	
   	
   	
   	
   	
   	
   	
      	
      		
      		
      	
   	
   	
       
       
       
       
       
       
    


ref:自定义用户没有权限访问资源时对应的AccessDeniedHandler实现类;
error-page:自定义403页面。

AccessDeniedHandlerImpl:

package com.javasgj.ssm.login.handler;

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;
import org.springframework.stereotype.Component;

@Component
public class AccessDeniedHandlerImpl implements AccessDeniedHandler {

	@Override
	public void handle(HttpServletRequest request, HttpServletResponse response,
			AccessDeniedException accessDeniedException) throws IOException, ServletException {

		response.sendRedirect(request.getContextPath() + "/accessDeny.jsp");
	}
}

注意要放开accessDeny.jsp权限。

你可能感兴趣的:(认证,授权)