shiro的URL配置

让我们再次回忆一下spring容器中shirofilter的配置:

 <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"/>
        <!-- The 'filters' property is not necessary since any declared javax.servlet.Filter bean
             defined will be automatically acquired and available via its beanName in chain
             definitions, but you can perform overrides or parent/child consolidated configuration
             here if you like: -->
        <!-- <property name="filters">
            <util:map>
                <entry key="aName" value-ref="someFilterPojo"/>
            </util:map>
        </property> -->
        <property name="filterChainDefinitions">
            <value>
                /favicon.ico = anon
                /logo.png = anon
                /shiro.css = anon
                /login.jsp = anon 
                # allow WebStart to pull the jars for the swing app:
                /*.jar = anon
                # everything else requires authentication:
                /** = authc
            </value>
        </property>
    </bean>

在上述的配置文件中,有一个名为filterChainDefinitions的属性,定义的是拦截器链,在这里可以配置各种资源的URL被访问所需要的权限。
其格式是url=拦截器[参数],拦截器[参数],anon是anonymous的缩写,表示匿名访问,也就是说该资源无需登陆,authc则是authentication的缩写,表示需要身份认证通过之后才能访问。URL支持ANT风格。

URL匹配优先级的问题

URL匹配采取第一次匹配优先的方式,即当一个或多个资源同时适用多个拦截器时,从头开始起第一个匹配上的拦截器生效。
例如:
/bb/**=filter1
/bb/aa=filter2
/**=filter3
如果访问的URL是“/bb/aa”,按照第一次匹配优先的规则,该访问将由filter1进行拦截。

猜你喜欢

转载自blog.csdn.net/ascend2015/article/details/78484892