【问题标题】:Basic Authentication in Spring Security( authentication failure message)Spring Security 中的基本身份验证(身份验证失败消息)
【发布时间】:2012-08-15 12:26:00
【问题描述】:

我正在开发网站(HTML、javascript、jQuery、Ajax、css),我在服务器端使用 spring 中的基本身份验证。 我在 HTTP 请求的授权标头中发送 Basic="Base64 Endcoded Username & password"。 登录在正确的用户名和密码上工作正常。 但是在失败时,它会显示一个默认提示,让我输入用户名和密码。 我该怎么做才能不显示提示,而是应该得到一个错误代码。 这样,我就可以显示正确的失败消息。


春季安全

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-3.0.3.xsd">

<http create-session="never"> 
    <intercept-url pattern="/rest/user*" access="ROLE_USER" /> 
    <logout logout-success-url="/index.jsp" invalidate-session="true" />
    <http-basic />
</http> 

<authentication-manager>
    <authentication-provider>
    <password-encoder hash="md5"/>
        <jdbc-user-service data-source-ref="dataSource" 
            users-by-username-query="
                select UserName as username, Password as user_password,true 
                from User where username=?" 

            authorities-by-username-query="
                select UserName as username,'ROLE_USER' from User where username=?" 

        />
    </authentication-provider>

</authentication-manager>

【问题讨论】:

  • 你在xml文件中使用了标签吗?在日志中您是否收到身份验证失败错误?

标签: javascript jquery html spring-security basic-authentication


【解决方案1】:

经过这么多的障碍..终于我做到了。

我已经在我的博客上发布了

http://swapgo20.wordpress.com/2012/10/21/website-spring-security-basic-authorization-in-javascript/

【讨论】:

    【解决方案2】:

    默认情况下,当身份验证过程失败时,AuthenticationEntryPoint 类将用户重定向到登录页面。要更改默认行为并提供自定义身份验证失败页面,您可以在 security.xml 文件中指定一个条目

    <form-login login-processing-url="your-login-check" login-page="/login"
                username-parameter="j_username" password-parameter="j_password"
                authentication-failure-url="/login/authenticationFailure" /> 
    

    应该是这样的!您将被重定向到 xml 中 authentication-failure-url 属性中指定的页面。

    【讨论】:

    • 我没有使用表单登录。我正在将 http 请求中的授权标头发送到使用 Spring Security 的服务器。
    • 是的..我的意思是在服务器的spring security xml文件中的form-login标签中。
    • 不,我没有使用表单登录。
    • 那你是怎么配置spring security的呢?请使用这些详细信息更新问题。
    猜你喜欢
    • 2015-05-13
    • 2015-07-28
    • 1970-01-01
    • 2012-05-08
    • 2011-02-11
    • 2016-03-20
    • 1970-01-01
    • 2022-08-16
    • 2013-01-02
    相关资源
    最近更新 更多