【问题标题】:Getting error in <security:intercept-url pattern="/**" access="hasAnyRole('customer')"/> in spring security basic authentication?<security:intercept-url pattern="/**" access="hasAnyRole('customer')"/> 在 Spring Security 基本身份验证中出现错误?
【发布时间】: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


【解决方案1】:

改一下

<security:user name="xxx" password="xxx" authorities="customer" />

<security:user name="xxx" password="xxx" authorities="ROLE_customer" />

你就完成了

【讨论】:

    猜你喜欢
    • 2017-05-04
    • 2011-02-11
    • 2016-03-20
    • 1970-01-01
    • 1970-01-01
    • 2016-04-30
    • 2013-01-11
    • 2015-07-22
    • 2012-08-15
    相关资源
    最近更新 更多