【问题标题】:Spring Security HTTP Basic AuthenticationSpring Security HTTP 基本身份验证
【发布时间】:2011-02-11 01:55:24
【问题描述】:

我正在尝试使用 Spring Security 进行非常简单的基本身份验证。我已经正确配置了命名空间,并且服务器中没有异常。在我的“servlet.xml”中,我得到了 Spring Security 的下一个:

<security:http>
    <security:http-basic></security:http-basic>
    <security:intercept-url method="POST" pattern="/**" access="ROLE_USER" />
</security:http>


<security:authentication-manager alias="authenticationManager">
    <security:authentication-provider>
        <security:user-service>
            <security:user name="cucu" password="tas" authorities="ROLE_USER" />
            <security:user name="bob" password="bobspassword" authorities="ROLE_USER" />
        </security:user-service>
    </security:authentication-provider>
</security:authentication-manager>

几乎一切都很完美:不是POST 的方法不会提示任何登录表单,POST 方法会提示它。问题是,cucubob 都不能在那里登录。谁能看到我做错了什么?

提前致谢! ;-)

【问题讨论】:

  • 你使用的是什么版本的 Spring Security?
  • 对不起,我忘记了,Spring Security 3
  • 你能发布实际错误的堆栈跟踪/输出吗?
  • 对不起,我想我应该更具描述性。问题是,即使我使用这两个用户登录,我也得到了未经授权的 401。谢谢你的时间,甘道夫 ;-)
  • 您的问题可能是配置 HTTP 基本身份验证的最清晰、最简洁的示例,我可以快速 google。为此+1 :)

标签: java spring-security basic-authentication


【解决方案1】:

自动回答

T_T 这两天我的脑袋撞到了这个代码......

看起来不是代码的问题。我正在使用 Weblogic,Weblogic 使用“授权”标头捕获请求,因此它不会到达我的身份验证管理器。我用 glassfish 试过,效果很好。

搜索一些信息,我在下一篇博客中发现了一个有用的条目: http://yplakosh.blogspot.com/2009/05/how-to-fix-basic-authentication-issue.html

在我的 Weblogic 服务器的 config.xml 中添加下一行(&lt;security-configuration&gt; 部分):

&lt;enforce-valid-basic-auth-credentials&gt;false&lt;/enforce-valid-basic-auth-credentials&gt;

Weblogic 不会再次捕获基本身份验证凭据,因此将由您的身份验证管理器来处理它。

我希望它可以为任何人节省一些时间:-)

【讨论】:

  • 非常感谢您发布此解决方案。我刚开始遇到这个问题,在谷歌搜索后找到了你的帖子。
  • 呵呵,我真的很高兴帮您节省了一些时间;-)
  • 截至 2019 年,这个问题似乎仍然存在。
【解决方案2】:

尝试:

<http auto-config="true>
   <security:intercept-url method="POST" pattern="/**" access="ROLE_USER" />
   <http-basic />
</http>

【讨论】:

  • 感谢您的建议。我也尝试过真正的自动配置,但我想我错过了其他东西......但不知道是什么。我认为我的代码很简单,应该没有问题。
猜你喜欢
  • 2013-01-11
  • 2016-03-20
  • 1970-01-01
  • 2016-04-30
  • 2015-07-22
  • 1970-01-01
  • 2013-05-13
  • 2023-03-20
  • 2012-08-15
相关资源
最近更新 更多