在< security:intercept-url pattern ="/**"中出现错误access =" hasAnyRole('customer')"/>在春季安全基本认证? [英] Getting error in <security:intercept-url pattern="/**" access="hasAnyRole('customer')"/> in spring security basic authentication?

查看:99
本文介绍了在< security:intercept-url pattern ="/**"中出现错误access =" hasAnyRole('customer')"/>在春季安全基本认证?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的rest-dispather-servlet-security.xml文件

This is my rest-dispather-servlet-security.xml file

我在春季安全性中使用了基于XML的配置,但是在 我的访问属性 access ="hasAnyRole('customer')" .这是我的xml文件.

I have used the XML based configuration in my spring security but I am getting an error in my access attribute access="hasAnyRole('customer')". Here is my xml file.

    <?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进行身份验证,但会收到以下错误消息

also while accessing it through postman I am able to authenticate the URL but getting the following error

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

推荐答案

更改此

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

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

您已经完成

这篇关于在&lt; security:intercept-url pattern ="/**"中出现错误access =" hasAnyRole('customer')"/&gt;在春季安全基本认证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆