【发布时间】:2017-12-24 08:10:02
【问题描述】:
这是我的 rest-dispather-servlet-security.xml 文件
我在 Spring Security 中使用了基于 XML 的配置,但在 我的访问属性 access="hasAnyRole('customer')"。这是我的 xml 文件。
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:security="http://www.springframework.org/schema/security"
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
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security.xsd">
<security:authentication-manager>
<security:authentication-provider>
<security:user-service id="userService ">
<security:user name="xxx" password="xxx" authorities="customer" />
</security:user-service>
</security:authentication-provider>
</security:authentication-manager>
<security:http create-session="stateless"
use-expressions="true">
<security:intercept-url pattern="/**" access="hasAnyRole('customer')"/>
<security:http-basic />
</security:http>
</beans>
在通过邮递员访问它时,我能够验证 URL,但出现以下错误
HTTP Status 403 – Forbidden
Type Status Report
Message Access is denied
Description The server understood the request but refuses to authorise it.
Apache Tomcat/8.5.12
【问题讨论】:
-
不,先生,这是基于注释的配置,我尝试过,但又失败了。你能不能给它一些其他的解决方案。
-
这没什么区别,XML 也一样。它必须是
authorities="ROLE_customer"(带前缀)。
标签: spring spring-mvc spring-boot spring-security basic-authentication