spring security3教程系列--页面权限标签问题

46 篇文章 0 订阅
26 篇文章 0 订阅

本文章摘编、转载需要注明来源 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>



  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值