本文章摘编、转载需要注明来源 http://blog.csdn.net/shadowsick/article/details/8868863
当我们自定义了spring security3 的过滤链的时候发现页面权限控制标签<sec:authorize之类的已经不能起效了,这是因为我们缺少一个必须的实例
所以找了下源码看到需要一个DefaultWebInvocationPrivilegeEvaluator决策器实例,直接配置一个实例然后注入FilterSecurityInterceptor的实例即可
<!-- 页面标签权限功能依赖 -->
<bean id="webInvocationFilter"
class="org.springframework.security.web.access.DefaultWebInvocationPrivilegeEvaluator">
<constructor-arg ref="filterSecurityInterceptor" />
</bean>
这样我们就可以在页面继续使用security的标签
<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix='sec' uri='http://www.springframework.org/security/tags' %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>SPRING SECURITY TEST CENTER</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
用户名:<sec:authentication property="name" />, 欢迎来到主页!<br>
拥有权限:<sec:authentication property="principal.authorities" /><br>
是否可用:<sec:authentication property="principal.enabled" /><br>
未被锁定:<sec:authentication property="principal.accountNonLocked" /><br>
<sec:authorize ifAnyGranted="ROLE_SUPERVISOR">您是超级管理员,可看到该信息:(这里可以用逗号分隔,加入多个角色你拥有管理员权限)</sec:authorize><br>
<sec:authorize url='/test.jsp'>你登陆成功了可以看到: <a href="<%=path %>/supervisor/index.jsp">管理页面</a></sec:authorize>
<br><a href="<%=path %>/logout">注销登录</a>
</body>
</html>