Validating the user through username and password through servlet

Posted by / 07-Feb-2020 22:48

Validating the user through username and password through servlet

Abstract Security Web Application Initializer; public class Spring Security Initializer extends Abstract Security Web Application Initializer package org.o7planning.springmvcsecurity.config; import org.o7planning.springmvcsecurity.authentication. Row Mapper; public class User Info Mapper implements Row Mapperpackage org.o7planning.impl; import String Http Message Converter; import org.servlet.config.annotation. Default Servlet Handler Configurer; import org.servlet.config.annotation. Enable Web Mvc; import org.servlet.config.annotation. Resource Handler Registry; import org.servlet.config.annotation. Web Mvc Configurer Adapter; @Configuration @Enable Web Mvc public class Web Mvc Config extends Web Mvc Configurer Adapter package org.o7planning.springmvcsecurity.config; import org.springframework.context. User Info DAO; import org.o7planning.springmvcsecurity.mapper. User Info Mapper; import org.o7planning.springmvcsecurity.model. User Info; import org.springframework.beans.factory.annotation. Jdbc Dao Support; import org.springframework.stereotype. Service; import org.springframework.transaction.annotation. Transactional; @Service @Transactional public class User Info DAOImpl extends Jdbc Dao Support implements User Info DAO package org.o7planning.springmvcsecurity.authentication; import Request Method; @Controller public class Main Controller The path above only allows the user with the ADMIN role (ROLE_ADMIN) to be allowed access: In case you have not logged in, the website will redirect to the login page, if you log in as ROLE_USER you will receive an "Access Denied" message.

This application also uses the custom validator class to validate the form data. The code for is: Listing 2: code The next step is to create and configure the inside the WEB-INF folder that will have all the configuration beans for handle the user requests. User Details; import org.springframework.userdetails. User Details Service; import org.springframework.userdetails. Username Not Found Exception; import org.springframework.stereotype. Service; @Service public class My DBAuthentication Service implements User Details Service package org.o7planning.springmvcsecurity.controller; import package org.o7planning.springmvcsecurity.config; import org.springframework.context. The application basically validates if user enters username as admin and password as admin.By doing so, the user is successfully validated and a success page is displayed.

validating the user through username and password through servlet-2validating the user through username and password through servlet-21validating the user through username and password through servlet-87

The code of the is: Listing 6: code The next step is to create the Login Form file that extends Simple Form Controller for controlling the login request and return.