标签:
<bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
<property name="securityManager" ref="securityManager" />
<property name="loginUrl" value="/user/login.action" /> <!-- 没有权限或者失败后跳转的页面 -->
<property name="filterChainDefinitions">
<!-- , roles[admin], perms[document:read] -->
<value>
<!-- 对静态资源设置匿名访问 -->
/js/** = anon
/css/** = anon
/img/** = anon
/fonts/** = anon
/scripts/** = anon
/user/login.action = authc
/user/logout = logout
<!-- 进入后台需要权限:admin:* -->
/backstage/** = perms[admin:*]
/user/** = user
</value>
</property>
</bean>
<!-- 后台 -->
<package name="backstage" namespace="/backstage" extends="struts-default">
<default-action-ref name="index" />
<action name="index">
<result>/WEB-INF/jsp/backstage/index.jsp</result>
</action>
</package>
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
//从principals获取主身份信息
//将getPrimaryPrincipal()返回的值强制转换为真实身份信息【在上边的doGetAuthenticationInfo()认证通过填充到SimpleAuthenticationInfo中的身份信息】
String userCode = (String) principals.getPrimaryPrincipal();
//根据身份信息获取权限信息
//先链接数据库。。。
//模拟从数据库获取数据
List<String> permissions = new ArrayList<String>();
permissions.add("admin:*");//用户的创建权限
permissions.add("user:update");//用户的修改
permissions.add("item:add");//商品的添加权限
//....等等权限
//查到权限数据,返回
SimpleAuthorizationInfo simpleAuthorizationInfo = new SimpleAuthorizationInfo();
//将List里面的权限填充进去
simpleAuthorizationInfo.addStringPermissions(permissions);
return simpleAuthorizationInfo;
}
List<String> permissions = new ArrayList<String>();
permissions.add("admin:*");//用户的创建权限
permissions.add("user:update");//用户的修改
permissions.add("item:add");//商品的添加权限
//....等等权限
//将List里面的权限填充进去
simpleAuthorizationInfo.addStringPermissions(permissions);
<!-- 进入后台需要权限:admin:* -->
/backstage/** = perms[admin:*]
<!-- 通过unauthorizedUrl指定没有权限操作时跳转页面-->
<property name="unauthorizedUrl" value="/refuse.jsp" />
Shiro整合SSH开发4:Realm授权,perms过滤器测试和使用方法讲述
标签:
原文地址:http://blog.csdn.net/nthack5730/article/details/51226800