Shiro与Spring MVC通配符权限不起作用

时间:2013-03-08 16:33:17

标签: spring-mvc shiro

我有几个权限:

inventory:po:view
inventory:po:create
inventory:po:update

在JSP中,下面有效:

<shiro:hasPermission name="inventory:po:create">
   <li><a href='<c:url value="/inventory/document/viewDocument?doctype=2" />'>Purchase Order</a></li>                   
</shiro:hasPermission>

但是,下面没有。

<shiro:hasPermission name="inventory:po:*">
</shiro:hasPermission>

Shiro版本是1.2.1。我也尝试使用subject.isPermitted()调用,但这也不起作用。

我确信这应该是非常简单的,但是在配置中有什么我想念以启用通配符支持吗?请指教。

Shiro配置:

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

<!-- Security Manager -->
<bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
    <property name="realm" ref="jdbcRealm" />
    <property name="cacheManager" ref="cacheManager"/>
</bean>

<!-- Caching -->
<bean id="cacheManager" class="org.apache.shiro.cache.ehcache.EhCacheManager">
    <property name="cacheManager" ref="ehCacheManager" />
</bean>

<bean id="ehCacheManager"
    class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean" />

<bean id="sessionDAO"
    class="org.apache.shiro.session.mgt.eis.EnterpriseCacheSessionDAO" />

<bean id="sessionManager"
    class="org.apache.shiro.web.session.mgt.DefaultWebSessionManager">
    <property name="sessionDAO" ref="sessionDAO" />
</bean>


<!-- JDBC Realm Settings -->
<bean id="jdbcRealm" class="org.apache.shiro.realm.jdbc.JdbcRealm">
    <property name="name" value="jdbcRealm" />
    <property name="dataSource" ref="dataSource" />
    <property name="authenticationQuery"
        value="SELECT password FROM system_user_accounts WHERE username=? and status=10" />
    <property name="userRolesQuery"
        value="SELECT role_code FROM system_roles r, system_user_accounts u, system_user_roles ur WHERE u.user_id=ur.user_id AND r.role_id=ur.role_id AND u.username=?" />
    <property name="permissionsQuery"
        value="SELECT code FROM system_roles r, system_permissions p, system_role_permission rp WHERE r.role_id=rp.role_id AND p.permission_id=rp.permission_id AND r.role_code=?" />



    <property name="permissionsLookupEnabled" value="true"></property>
    <property name="cachingEnabled" value="true" />
</bean>

<!-- Spring Integration -->
<bean id="lifecycleBeanPostProcessor" class="org.apache.shiro.spring.LifecycleBeanPostProcessor" />

<!-- Enable Shiro Annotations for Spring-configured beans. Only run after 
    the lifecycleBeanProcessor has run: -->
<bean id="annotationProxy"
    class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator"
    depends-on="lifecycleBeanPostProcessor" />
<bean id="authorizationAttributeSourceAdvisor"
    class="org.apache.shiro.sprinemphasized textg.security.interceptor.AuthorizationAttributeSourceAdvisor">
    <property name="securityManager" ref="securityManager" />
</bean>

<!-- Secure Spring remoting: Ensure any Spring Remoting method invocations 
    can be associated with a Subject for security checks. -->
<bean id="secureRemoteInvocationExecutor"
    class="org.apache.shiro.spring.remoting.SecureRemoteInvocationExecutor">
    <property name="securityManager" ref="securityManager" />
</bean>

<!-- Passthrough for Login page -->
<bean id="passThruLogin" class="org.apache.shiro.web.filter.authc.PassThruAuthenticationFilter">
    <property name="loginUrl" value="/login" />
</bean>

<!-- Shiro filter -->
<bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
    <property name="securityManager" ref="securityManager" />
    <property name="loginUrl" value="/login" />
    <property name="successUrl" value="/dashboard" />
    <property name="unauthorizedUrl" value="/error" />
    <property name="filters">
        <map>
            <entry key="authc" value-ref="passThruLogin" />
        </map>
    </property>
    <property name="filterChainDefinitions">
        <value> 
            <!-- !!! Order matters !!! -->
            /authenticate = anon
            /login = anon
            /logout = anon
            /error = anon
            /static/** = anon
            /** = authc
        </value>
    </property>
</bean>

1 个答案:

答案 0 :(得分:0)

* ”在shiro的许可检查中不是通配符,相反它意味着“需要所有值”。 你应该断言你自己的通配符(读取通常是一个很好的默认通配符权限),并在权限检查上明确。

相反,'*'表示' GRANT 用户所有权利',这让你与imho混淆。

来自检查权限 shiro's documentation about permission

的一部分
  

if ( SecurityUtils.getSubject().isPermitted("printer:print") ) { //print the document }

     

因此,这是一个不正确的检查。如果当前用户无法打印到任何打印机,但他们确实能够打印lp7200和epsoncolor打印机,该怎么办?然后上面的第二个例子永远不允许他们打印到lp7200打印机,即使他们已被授予这种能力!

相关问题