1

我有几个权限:

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>

4

1 回答 1

1

* ”不是 shiro 权限检查中的通配符,相反它表示“需要所有值”。您应该声明自己的通配符权限(读取通常是一个很好的默认通配符权限)并在权限检查中明确。

相反,“*”表示“授予用户所有权利”,这让您与恕我直言混淆。

来自shiro 关于权限的文档的检查权限部分

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

因此,这是不正确的检查。如果当前用户没有能力打印到任何打印机,但他们确实有能力打印,比如 lp7200 和 epsoncolor 打印机,该怎么办。那么上面的第二个示例将永远不允许他们打印到 lp7200 打印机,即使他们已被授予该能力!

于 2015-02-11T09:54:17.823 回答