安全性:授权访问=" hasRole()"不起作用

时间:2016-05-07 03:47:56

标签: java spring-mvc spring-security

我在pom.xml

中有安全依赖项
<!-- SpringSecurity dependencies -->
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-core</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-config</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-taglibs</artifactId>
    </dependency>

我也在使用

<dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>io.spring.platform</groupId>
                <artifactId>platform-bom</artifactId>
                <version>1.1.2.RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

我的问题只是我必须为USER和ADMIN显示两个不同的菜单

<ul id="menu_top">
    <security:authorize access="hasRole('ROLE_ADMIN')">
        <li><a href='<spring:url value="/admin/admin-stuff"/>'></a></li>

    </security:authorize>
    <security:authorize access="hasRole('ROLE_USER')">          
        <li><a href='<spring:url value="/user/user-stuff"/>'></a></li>           
   </security:authorize>             
</ul>

这一切都不起作用意味着当我以ADMIN登录或USER没有显示任何内容时,我也尝试hasAuthority('ROLE_USER'),但在这种情况下没有任何作用。

0 个答案:

没有答案