春季休息服务拒绝获得http 403访问权限

时间:2017-10-04 17:56:31

标签: rest spring-security basic-authentication

我的Spring REST有以下配置,我想让我的所有Web服务都通过基本身份验证:

弹簧sec.xml

window.attachEvent("onload", fn);

对于我的客户端代码,我有以下内容:

 <http auto-config="true" use-expressions="true">
        <intercept-url pattern="/*" access="hasRole('ROLE_ADMIN')"/>
        <http-basic/>
    </http>

    <!-- Authentication manager -->
    <authentication-manager>
        <authentication-provider>
        <user-service>
            <user name="admin" password="admin" authorities="ROLE_ADMIN"/>
            <user name="rest" password="rest" authorities="ROLE_REST"/>
            <user name="user" password="user" authorities="ROLE_USER"/>
         </user-service>
        </authentication-provider>
    </authentication-manager>

我的客户端的所有执行都被拒绝了http 403访问,但是从代码开始,我已经使用了配置的用户名和密码。我也从hasRole改为hasAuthority,但无济于事。请帮忙。谢谢!

的web.xml:

String encoding = Base64.getEncoder().encodeToString(("admin:admin").getBytes());

        String authHeader = "Basic " + encoding;

        System.out.println(authHeader);

        HttpPost post = new HttpPost(uri);
        post.setHeader("Content-Type", "application/octet-stream; boundary=\"---Content Boundary\"");
        post.setHeader("Authorization", authHeader);

1 个答案:

答案 0 :(得分:0)

设法在我的spring security xml配置中找到问题及其问题。从403错误,它被声明&#34;无法验证提供的CSRF令牌,因为你的会话在spring security&#34;中找不到。

由于Web服务仅由非浏览器客户端使用,我在xml配置中禁用csrf,然后它就像魅力一样!

只是想知道这是否会保存为我的网络服务? csrf如何运作?

相关问题