spring-mvc
  • shiro
  • 2013-03-08 52 views 1 likes 
    1

    我有几个权限为:四郎与Spring MVC通配符权限不工作

    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()调用,这也不起作用。

    我敢肯定,这应该是相当直接的,但有什么我想在配置中启用通配符支持?请指教。

    四郎配置:

    <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> 
    

    回答

    0

    的 “*” 是不是在四郎的许可通配符检查,相反它的意思是 “需要的所有值”。 您应该声明自己的通配权(通常是一个很好的默认通配权限),并且在权限检查上是明确的。

    相反'*'的意思是'GRANT用户的所有权利',这让你与imho混淆。

    检查权限的shiro's documentation about permission

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

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

    相关问题