Spring Security – Config Security for Web MVC by Spring Boot

Configure Spring Security for Spring MVC web application + SpringBoot

In the tutorial, JavaSampleApproach will show you how to configure Security for SpringMVC web application.

I. Technologies

– Apache Maven 3.5.2
– Spring Tool Suite – Version: 3.9.2.RELEASE
– Spring Boot – 1.5.10.RELEASE
– Bootstrap

II. Goal

We create a SpringBoot MVC Web Application as below:

Spring Security - project structure

With 5 urls:

– ‘/’: access by everyone.

Spring Security - home page

– ‘/user’: must authenticate and be accessed with user ROLE {USER, ADMIN}

Spring Security - user page

– ‘/admin’: accessed by user with role Admin

Spring Security - admin page

– ‘/login’: login page

Kotlin Spring Security - Persistent Token Remember-Me authentication - login page

– ‘/403’: HTTP Error 403 Forbidden

III. Practice

Step to do:
– Create Spring Boot project
– Create Controller
– Create View Pages
– Configure WebSecurity

1. Create Spring Boot project

Use SpringToolSuite to create a Kotlin SpringBoot project with below dependencies:

2. Create Controller

3. Create View Pages





4. Configure WebSecurity

Use WebSecurityConfigurerAdapter which provides a convenient base class to create a WebSecurityConfigurer instance.

Web application has 2 users:
– Admin: admin/admin
– User: user/user

IV. SourceCode

Spring Security

By JavaSampleApproach | October 15, 2016.

Last updated on February 18, 2018.

Related Posts

Got Something To Say:

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