Thursday, 3 October 2013

Simple Login With Spring Security

Spring Security

here i have used form-login to configure spring security login.

if you want to restrict user to access all url and want to allow specific url portion then you can use do that by <intercept-url />

and using form-login we can control the user authentication filer or success.and we can display our custom login form.

when you are using <http-basic /> then web browser is displaying a log in dialog for user authentication.

To enable HTTP basic, just change “form-login” to “http-basic” tag.
<beans:beans xmlns=""
 <intercept-url pattern="/welcome*" access="ROLE_USER" />
                  <!-- this is for http basic

                                  <http-basic />
<form-login login-page="/login" default-target-url="/welcome"
   authentication-failure-url="/loginfailed" />
<logout logout-success-url="/logout" />
  <user name="jayesh" password="anki" authorities="ROLE_USER" />

<%@taglib uri="" prefix="spring"%>
<%@taglib uri="" prefix="form"%>

<title>Spring 3 MVC Series - Contact Manager</title>
<form action="j_spring_security_check" method="POST">

UserName: <input type="text" name="j_username" />
Password: <input type="password" name="j_password" />
<input type="submit" value="Login" />