Login page through LDAP with Spring security (Part 3)

Friday, December 4th, 2015 (0 Comment)

In part 3, we develop login ldap, that mean is custom source code to login use account of LDAP (what is ldap ?  you need to search in the internet for more detail). A simple way, you think the following, ldap is server storing account to log in to Desktop Computer to daily working. We use this account to login and connect to Ldap to check username and password. You need to review and do part 1 before do part 3

At first, edit porn.xml: add code below under spring.security.version to use LDAP library

Step 1: add java class to handle login with LDAP

In com.demo.springmvc.security package, add 3 files following:

  • UserDetailsContextMapperImpl.java: if login success, custom or edit in this class
  • LoginSuccessHandler.java: the same UserDetailsContextMapperImpl.java, run after UserDetailsContextMapperImpl,java. this class depending on your purpose if any
  • LoginFailureHandler.java: if login failed, custom in this class

UserDetailsContextMapperImpl.java:

  • get role the same CustomAuthenticationProvider in part 2

LoginSuccessHandler.java: do not to need in here, I add to your purpose later

LoginFailureHandler.java: handle login failed

  • errorReason: out text error when login wrong, you can modify with your purpose.

Step 2: edit context-security.xml file to mapping to java class to handle LDAP

context-security.xml:

  • 123.123.12.123:389: IP Ldap server and port
  • line 37: config point to LoginSuccessHandler class
  • line 40: config point to LoginFailureHandler class
  • yourdomain.com: domain name of company
  • line 58: remove function login in part 2
  • line 53: add function ldap replace for line 58
  • line 65: the same, replace function in part 2

Step 3: edit layout login

login.jsp:

  • line 32: out error from LoginFailureHandler class

Build and run, will success, you only sure information about LDAP as ip, port and domain name … I must do spring mvc again step by step and run OK. In the next article, we will build layout template for our website (header, sidebar, top-menu, content and footer)

 

Tags: , , , , , ,

Related Posts

spring
How to create quartz spring dynamic in database
spring
Spring mvc mongodb crud users roles
spring
Java spring mvc tutorial on lvtutorial.com
spring
Angularjs spring mvc crud example

Related Posts

spring
How to create quartz spring dynamic in database
spring
Spring mvc mongodb crud users roles
spring
Java spring mvc tutorial on lvtutorial.com
spring
Angularjs spring mvc crud example

Leave a Reply

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