Register ">Login CART ">logout 我-6ren">
gpt4 book ai didi

java - Spring Security 4中如何根据角色授权链接

转载 作者:行者123 更新时间:2023-12-02 04:57:24 24 4
gpt4 key购买 nike

我正在尝试根据角色授权链接。

我的页面:

<c:if test="${pageContext.request.userPrincipal.name==null}">
<li> <a href="<c:url value="/registration"/>"><span class="glyphicon glyphicon-user">Register</span></a> </li>
<li> <a href="<c:url value="/login"/>"><span class="glyphicon glyphicon-lock">Login</span></a> </li>
</c:if>

<c:if test="${pageContext.request.userPrincipal.name!=null}">

<security:authorize access="ROLE_USER">
<li><a href="cart.jsp"><span class="glyphicon glyphicon-shopping-cart">CART</span></a></li>
</security:authorize>

<li><a href="<c:url value="/j_spring_security_logout"></c:url>">logout</a></li>
</c:if>

我遇到以下异常:

with root cause
org.springframework.expression.spel.SpelEvaluationException:
EL1008E:(pos 0): Property or field 'ROLE_USER' cannot be found on object of type
'org.springframework.security.web.access.expression.WebSecurityExpressionRoot' - maybe not public?

最佳答案

试试这个..而不是 <security:authorize access="ROLE_USER">

<security:authorize access="hasRole('ROLE_USER')">

关于java - Spring Security 4中如何根据角色授权链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40464294/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com