首页 > 编程语言 > 详细

Spring shiro学习(二)

时间:2017-07-19 22:42:56      阅读:285      评论:0      收藏:0      [点我收藏+]

 

shiro 默认自带的过滤器如下:

Filter NameClass
anon org.apache.shiro.web.filter.authc.AnonymousFilter
authc org.apache.shiro.web.filter.authc.FormAuthenticationFilter
authcBasic org.apache.shiro.web.filter.authc.BasicHttpAuthenticationFilter
logout org.apache.shiro.web.filter.authc.LogoutFilter
noSessionCreation org.apache.shiro.web.filter.session.NoSessionCreationFilter
perms org.apache.shiro.web.filter.authz.PermissionsAuthorizationFilter
port org.apache.shiro.web.filter.authz.PortFilter
rest org.apache.shiro.web.filter.authz.HttpMethodPermissionFilter
roles org.apache.shiro.web.filter.authz.RolesAuthorizationFilter
ssl org.apache.shiro.web.filter.authz.SslFilter
user org.apache.shiro.web.filter.authc.UserFilter

我们平常用的就是 anon:任何人都可以访问;authc:必须登录才能访问,不包含rememberme ;user:登录用户才可以访问,包含rememberme ;perms:指定过滤规则,这个一般是扩展使用,不会使用原生的,例如springrain扩展的为frameperms.

filterChainDefinitions 就是指定过滤规则的,一般是把公共配置使用配置文件,例如 js  css img 这些资源文件是不拦截的,业务相关的url配置到数据库,有过滤器查询数据库进行权限判断.

<bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
        <property name="securityManager" ref="securityManager"/>
        <property name="loginUrl" value="${zheng.upms.sso.server.url}"/>
        <property name="successUrl" value="${zheng.upms.successUrl}"/>
        <property name="unauthorizedUrl" value="${zheng.upms.unauthorizedUrl}"/>
        <property name="filters">
            <util:map>
                <entry key="authc" value-ref="upmsAuthenticationFilter"/>
            </util:map>
        </property>
        <property name="filterChainDefinitions">
            <value>
                /manage/** = upmsSessionForceLogout,authc
                /manage/index = user
                /druid/** = user
                /swagger-ui.html = user
                /resources/** = anon
                /** = anon
            </value>
        </property>
    </bean>

 

filterChainDefinitions是定义拦截规则

拦截器的优先级是:从上至下,从左到右,如果有匹配的拦截器就会阻断并返回,例如 访问 /manage/index 第二个拦截器 user符合,就返回true了,不再往下匹配了.

最后一句是 /**=anon 意思就是除了上面的那些,其他的所有都要经过 anon.任何人都可以访问

 

Spring shiro学习(二)

原文:http://www.cnblogs.com/growingpains/p/7208499.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!