Skip to content

Latest commit

 

History

History
102 lines (71 loc) · 2.3 KB

45.md

File metadata and controls

102 lines (71 loc) · 2.3 KB

[TOC]

BOS物流项目45———权限控制7_Shiro四种权限控制之总结

一、URL拦截权限控制(基于过滤器实现)

主要就是配置 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;
    }

五、总结

在真实的情况中,我们使用权限控制,是多种方式配合使用的。


六、源码下载

https://github.com/wimingxxx/bos-parent