当前位置: 首页 > 知识库问答 >
问题:

Spring Security基本身份验证只发生一次

澹台奇略
2023-03-14

最近,我对REST服务使用Spring Security basic身份验证。

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:security="http://www.springframework.org/schema/security"
       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">

    <security:http pattern="/rest/**" create-session="never" use-expressions="true">
        <security:http-basic />
        <security:intercept-url pattern="/rest/auth/**" access="isAuthenticated()"/>
    </security:http>

    <security:authentication-manager alias="authenticationManager">
        <security:authentication-provider>
            <security:user-service>
                <security:user name="admin" password="admin" authorities="ROLE_ADMIN"/>
            </security:user-service>
        </security:authentication-provider>
        <security:authentication-provider user-service-ref="userDetailsService">
            <security:password-encoder hash="sha-256" />
        </security:authentication-provider>
    </security:authentication-manager>

    <security:global-method-security jsr250-annotations="enabled" pre-post-annotations="enabled"/>
</beans>
<springframework.version>4.1.0.RELEASE</springframework.version>
<spring.security.version>3.2.5.RELEASE</spring.security.version>

我希望浏览器总是提示我基本身份验证,因为我将create-session属性设置为never。

我是不是漏掉了什么?

共有1个答案

柏麒
2023-03-14

浏览器缓存凭据。有时清除缓存无济于事。唯一可靠的方法如何伪造它是使用Chrome的隐姓埋名窗口(CTRL+N)。但每个隐姓埋名窗口都有一个提示。所以当你想再次进入它们时,你需要新的隐姓埋名窗口。

这是我找到的手动测试基本身份验证的唯一方法。

 类似资料:
  • 问题内容: 从HttpClient 4.3开始,我一直在使用HttpClientBuilder。我正在连接到具有基本身份验证的REST服务。我将凭据设置如下: 但是,这不起作用(我正在使用的REST服务返回401)。怎么了? 问题答案: 从此处的 抢先身份验证 文档中: http://hc.apache.org/httpcomponents-client- ga/tutorial/html/aut

  • 目前我正在开发一个Java工具,它应该可以更新Confluence服务器页面。使用Curl一切都像一个符咒,但是当使用Postman或Java代码(HttpClient Java11)时,我得到了一个 HTTP状态401–未经授权 反应。 在下面的语句中使用curl curl--basic-u user:password-X PUT-H“内容类型:application/json”-d“@test

  • 几天没有任何进展,我需要你的帮助。 使用GWT,我试图与REST服务器通信,服务器位于不同的URL上(需要CORS)<我的配置:服务器spring boot 1.3.3 客户端-GWT 1.7-restygwt 2.0.3 当我在Spring中禁用安全性时,我可以在我的GWT客户端中获取数据。 但是当我启用它时,我总是收到401个请求。REST URL请求直接在Web浏览器中工作(带有其身份验证对

  • 我正在尝试使用OAuth2实现开发一个带有Spring Security性的rest api。但是如何删除基本身份验证呢。我只想向body发送用户名和密码,并在postman上获取令牌。 要删除基本身份验证,并从邮递员的get token中发送body标记中的用户名密码吗 我遇到了一些问题{"错误":"未经授权","error_description":"没有客户端身份验证。尝试添加适当的身份验证

  • 我尝试了angular.js,并从一个restful api的web-ui开始(使用超文本传输协议基本授权)。这真的很好,除了授权工作。 到目前为止,我使用的是设置密码,但大多数情况下浏览器会打开http basic auth的默认登录表单。另一个奇怪的行为是angular请求不包含授权头(选项和GET请求都不包含)。我还尝试使用header配置在每个请求上设置此header,但这也不起作用。 有

  • 我有一个基本的SOAP服务endpoint,实际上是SAP ECC,它表示一个服务。我已经使用SOAPUI4.5测试了该服务,使用HTTPAuth可以正常工作,可以根据事物的外观进行抢占。我看到一个出站“Authorization:Basic BASE64”,服务会做出相应响应。 我现在正试图将其引入Java。我想我会采取SAAJ方法: 但我无法在中添加HTTP身份验证。我相信SAAJ提供了控制S