[TOC]
主要就是配置 org.apache.shiro.spring.web.ShiroFilterFactoryBean 的时候,配置访问路径。例如
<!--配置shiroFilter框架的过滤器工程bean-->
<bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
<property name="securityManager" ref="securityManager"/>
<property name="loginUrl" value="/login.jsp"/>
<property name="successUrl" value="/index.jsp"/>
<property name="unauthorizedUrl" value="/unauthorized.jsp"/>
<property name="filterChainDefinitions">
<value>
/css/** = anon
/js/** = anon
/images/** = anon
/login.jsp* = anon
/validatecode.jsp* = anon
/userAction_login.action = anon
/page_base_staff.action = perms["staff-list"]
/* = authc
</value>
</property>
</bean>
在方法上添加 @RequiresPermissions("权限名称") 注解。例如
/**
* 取派员批量删除
*/
@RequiresPermissions("staff-delete")
public String deleteBatch(){
staffService.deleteBatch(ids);
return LIST;
}
使用 shiro:hasPermission 标签,判断时候具有指定的权限
<shiro:hasPermission name="staff-delete">
{
id : 'button-delete',
text : '作废',
iconCls : 'icon-cancel',
handler : doDelete
},
</shiro:hasPermission>
在方法中调用api判断权限。例如
/**
* 取派员批量删除
*/
public String deleteBatch(){
Subject subject = SecurityUtils.getSubject();
subject.checkPermission("staff-delete");
staffService.deleteBatch(ids);
return LIST;
}
在真实的情况中,我们使用权限控制,是多种方式配合使用的。