voy a tratar de explicar un poco el proceso de Spring security mas base de datos mysql
lo primero que debemos hacer es crearnos un base da datos mysql en nuestro servidor local
el script de la base de datos es el siguiente
create database autentificacion;
create table user_deatils (
username varchar(50) primary key,
password varchar(50) not null,
name varchar(300) not null,
address varchar(1000),
enabled boolean not null
)engine = InnoDb;
create table user_roles(
role_id integer primary key,
role varchar(50) not null
)engine = InnoDb;
create table users_role_map (
username varchar(50) not null,
role_id integer not null
) engine = InnoDb;
insert into user_deatils values('admin','21232f297a57a5a743894a0e4a801fc3','Victor Nazar','23 Street, Concepcion',1);
insert into user_roles values(1,'ROLE_ADMIN');
insert into users_role_map values('admin',1);
Bueno, ya que creamos nuestra pequeña base de datos con un usuario, vamos a crear un proyecto java de tipo web dinámica
así nos tiene que quedar la estructura de nuestra aplicación
index.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
web.xml
HelloWorldExampleWithSpring3MVCInEclipse
contextConfigLocation
/WEB-INF/configuracion.xml
springSecurityFilterChain
org.springframework.web.filter.DelegatingFilterProxy
Spring MVC Dispatcher Servlet
org.springframework.web.servlet.DispatcherServlet
contextConfigLocation
/WEB-INF/configuracion.xml
1
org.springframework.web.context.ContextLoaderListener
Spring MVC Dispatcher Servlet
*.htm
springSecurityFilterChain
/*
index.jsp
seguridadBD.xml
jdbc.properties
# database properties
app.jdbc.driverClassName=com.mysql.jdbc.Driver
app.jdbc.url=jdbc:mysql://localhost/autentificacion
app.jdbc.username=root
app.jdbc.password=102030
configuracion.xml
welcome.jsp
<%@ page session="true" %>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c"%>
Welcome!
${HelloMessage}
">Logout
WelcomeController.java
package controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
@Controller
public class WelcomeController {
@RequestMapping(value="/welcome",method=RequestMethod.GET)
public ModelAndView sayHello(Model model){
ModelAndView mv = new ModelAndView();
mv.setViewName("welcome");
model.addAttribute("HelloMessage", "Usted esta logeado.");
return mv;
}
}
login.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
Download lib
Download (war + lib)
-->