Spring security tutorial

In order to get started with Spring security, we need three JARS as mentioned below.

All of these JARs are available in the maven repository.

Just by adding the dependencies in our pom file , our application would be able to download the JARs in it’s build path so that our code can refer the code downloaded by the JAR.

Below are the steps that we should be following to create a Spring security project

 

1.spring-security-web

<dependency>
   <groupId>org.springframework.security</groupId>
   <artifactId>spring-security-web</artifactId>
   <version>5.0.5.RELEASE</version>
</dependency>

2.spring-security-config

<dependency>
   <groupId>org.springframework.security</groupId>
   <artifactId>spring-security-config</artifactId>
   <version>5.0.5.RELEASE</version>
</dependency>

3.commons-logging

<dependency>
   <groupId>commons-logging</groupId>
   <artifactId>commons-logging</artifactId>
   <version>version</version>
</dependency>

4. modify web.xml

We should modify web.xml to add spring security support. First we should a Context Loader Listener.

<listener>
  <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

Mention the Config Location

<context-param>
   <param-name>contextConfigLocation</param-name>
   <param-value>/WEB-INF/config/security-config.xml</param-value>
</context-param>

Provide the application entry point

<filter>
  <filter-name>springSecurityFilterChain</filter-name>
  <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filte>



<filter-mapping>
   <filter-name>springSecurityFilterChain</filter-name>
   <url-pattern>/*</url-pattern>
</filter-mapping>
Doubts? WhatsApp me !