Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Basic Authentication in Spring Security( authentication failure message)

I am developing website(HTML, javascript, jQuery, Ajax, css) in which, I am using basic authentication in spring in server side. I am sending Basic="Base64 Endcoded Username & password" in Authorization header of HTTP request. Login works fine on correct username & password. But on failure, it shows me a default prompt to enter a username & password. What can I do to so that prompt is not shown, Instead I should get a error code. So that, I can display proper failure message.


Spring Security

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>

like image 390
Swapnil Godambe Avatar asked Sep 02 '26 00:09

Swapnil Godambe


1 Answers

After so much of hurdle .. finally I have done it.

I have posted it on my blog

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

like image 158
Swapnil Godambe Avatar answered Sep 04 '26 14:09

Swapnil Godambe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!