Java, Software Development, Spring

Spring Boot + Spring Security with Multiple Login Forms and User Types

Application Requirement

I’m working on some personal project that handles 4 different user types (e.g., students, instructors, registrar employees, security personnel). Each user type is stored in a separate user table. With these, I require four (4) login forms.

Software Requirement

For this blog, the following are used.

  1. IntelliJ IDEA (optional)
  2. JDK 8
  3. Spring Initizr (http://start.spring.io/)
  4. Spring Boot  1.4.2.RELEASE
    1. Thymeleaf
    2. Spring Security

The codes

Login Form

Using Thymeleaf, we have this studentLogin.html file. Now notice line # 17. We specify the type of user using a hidden field.

For other user types, you may need to specify different user types in a similar way.

[wp_ad_camp_2]

Custom Filter

We need a filter to get the additional parameter from the HttpServletRequest and set it as a HttpSession attribute.

Then include this new filter in the filter chain by modifying your security configuration Java file.

UserDetailService Implementation

You would then retrieve that parameter using RequestContextHolder.

Loading

Got comments or suggestions? We disabled the comments on this site to fight off spammers, but you can still contact us via our Facebook page!.


You Might Also Like

2 Comments

  1. 1

    SecurityUser give error “SecurityUser cannot be resolved to a type”
    at SecurityUser secUser=null

  2. 2

Comments are closed.