【问题标题】:Is Spring security hasRole() and hasAnyRole casesensitive?Spring security hasRole() 和 hasAnyRole 是否区分大小写?
【发布时间】:2015-04-09 13:00:12
【问题描述】:

在角色表中,当我检查时,我将角色名称存储为“Admin”

<sec:authorize access="hasRole('ADMIN')">
    <c:out value='${message}'/> 
</sec:authorize>    

即使我以管理员用户身份登录,它也不会打印消息。

此表达式是否区分大小写

【问题讨论】:

标签: spring spring-security jstl


【解决方案1】:

如果你需要Spring jsp页面授权,请按照以下步骤,

第一步:需要在网络安全文件中激活网络授权

在 http 标记中使用-expressions="true" 在安全 xml 文件中

例如:&lt;http .... use-expressions="true"&gt;

然后你配置 pom.xml 以便下载 spring

<dependency>
    <groupId>org.springframework.security</groupId>
    <artifactId>spring-security-taglibs</artifactId>
    <version>3.2.5.RELEASE</version>
</dependency>

步骤 2。然后在你需要的jsp页面中添加标签库

例如:

<%@ taglib prefix="security" uri="http://www.springframework.org/security/tags" %>

Step3:然后检查jsp页面中的hasRole

例如:

<security:authorize access="hasRole('ROLE_USER')">
    This text is only visible to a user
    <br/>
</security:authorize>
<security:authorize access="hasRole('ROLE_ADMIN')">
    This text is only visible to an admin
    <br/>
</security:authorize>

在那个地方 userRole 区分大小写

您还可以提供基于角色的完整页面访问权限.. 使用以下示例代码

<intercept-url pattern="/user/**" access="hasRole('ROLE_USER')" />

此拦截允许该页面中的角色用户。

根据您的问题,您应该验证网络安全文件必须有use-expression="true"

如果正确请确认角色名。因为区分大小写

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-11-16
    • 1970-01-01
    • 2013-03-16
    • 2012-08-07
    • 2015-09-13
    • 1970-01-01
    • 2011-12-19
    相关资源
    最近更新 更多