【发布时间】:2018-08-16 11:43:21
【问题描述】:
我无法使用SecurityContext.xml 添加页面角色。
我该怎么办?
使用配置类进行推送配置。 但 XML 配置不起作用:
我的 XML 配置
<?xml version="1.0" encoding="UTF-8" ?>
<beans:beans xmlns="http://www.springframework.org/schema/security"
xmlns:beans="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.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security.xsd">
<http auto-config="true">
<intercept-url pattern="/**" access="ROLE_USER" />
</http>
<authentication-manager>
<authentication-provider>
<user-service>
<user name="user" password="user" authorities="ROLE_USER" />
</user-service>
</authentication-provider>
</authentication-manager>
</beans:beans>
此配置在运行时产生此错误。
java.lang.IllegalArgumentException: 无法在 org.springframework.security.access.expression.ExpressionUtils.evaluateAsBoolean(ExpressionUtils.java:30) 评估表达式“ROLE_USER”~[spring-security-core-5.0.7.RELEASE .jar:5.0.7.RELEASE] 在 org.springframework.security.web.access.expression.WebExpressionVoter.vote(WebExpressionVoter.java:52) ~[spring-security-web-5.0.7.RELEASE.jar:5.0.7.RELEASE] 在
【问题讨论】:
-
access需要一个表达式,而不仅仅是角色的名称。类似于access="hasRole('ROLE_USER')"。
标签: xml spring spring-boot spring-security illegalargumentexception