Spring Security 3.1 login example with User details in File

In this tutorial we will learn how to create and use custom Login page in spring authentication. User Details will be saved here in security XML file.

Technologies Used :

  • Spring Framework 3.1.1
  • Spring Security 3.1.0

Tools Used

  • Eclipse Indigo

 

1. Create Dynamic Web Project

Create dynamic web project by choosing  File >> New >> Other select “Dynamic Web Project” and select the name as “JBTSpringSecurityLogin” and click Finish. For Full details how to create project click here.

2. Adding Dependent Jars

It’s now time to ass all dependent jars in WEB-INF >> Jar Folder.

Required Jars would be

  • com.springsource.org.apache.commons.lang-2.1.0.jar
  • com.springsource.org.apache.commons.logging-1.1.1.jar
  • jstl-1.2.jar (Used for Tags in Login JSP)
  • org.springframework.aop-3.1.1.RELEASE.jar
  • org.springframework.asm-3.1.1.RELEASE.jar
  • org.springframework.beans-3.1.1.RELEASE.jar
  • org.springframework.context-3.1.1.RELEASE.jar
  • org.springframework.core-3.1.1.RELEASE.jar
  • org.springframework.expression-3.1.1.RELEASE.jar
  • org.springframework.web-3.1.1.RELEASE.jar
  • org.springframework.web.servlet-3.1.1.RELEASE.jar
  • spring-security-config-3.1.0.RELEASE.jar
  • spring-security-core-3.1.0.RELEASE.jar
  • spring-security-web-3.1.0.RELEASE.jar
  • aopalliance-1.0.jar

 

3. Configure Web.XML

Now need to configure application to forward all request to pass through Spring framework and through Spring Security.

4.  Configuring Spring Security

Here we will configure which part of the appication should be secured and which part shouldn’t be. Also here we will configure our customize Login and logout page.

Now if we try to access “http://localhost:8080/JBTSpringSecurityLogin/index.jsp” Custom Login page will be displayed

Here you can see customize login page got displayed instead of Spring Provided Login page and user is authenticated against the credential available in XML file itself.

To get the code of this application click here

4 Comments Spring Security 3.1 login example with User details in File

  1. Subin

    Admin I’ve tried copying the .war file in webapps folder of Apache Tomcat 5.5 and tried the URL in my browser. But I’m sorry this didn’t work. Can you help me please?

    Reply
  2. Pingback: spring 3 login.jsp example

Leave A Comment

Your email address will not be published. Required fields are marked *