博客开发笔记四——Spring Secruity 3最小系统
1、配置
<?xml?version="1.0"?encoding="UTF-8"?><b:beans?xmlns="http://www.springframework.org/schema/security"xmlns:b="http://www.springframework.org/schema/beans"??????xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"??????xsi:schemaLocation="http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.4.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd????????????">create table users( username varchar_ignorecase(50) not null primary key, password varchar_ignorecase(50) not null, enabled boolean not null); create table authorities ( username varchar_ignorecase(50) not null, authority varchar_ignorecase(50) not null, constraint fk_authorities_users foreign key(username) references users(username)); create unique index ix_auth_username on authorities (username,authority);3、使用3.1用户注册? ? ? ? ? ? ? ? ? ? //密码进行编码保存? ? ? ? ? ? password =?passwordEncoder.encodePassword(password, username);????????????Vector<GrantedAuthority> authList =?new?Vector<GrantedAuthority>();??????????????????????//一定要加Authority,不然登陆不了??????? ?????authList.add(new?GrantedAuthorityImpl("ROLE_USERS"));????????????User user =?new?User(username, password,?true,?true,?true,?true, authList);????????????userDetailsManager.createUser(user);????????????return?"redirect:"?+ referer;3.2登陆页面<%@?page?language="java"?contentType="text/html; charset=ISO-8859-1"????pageEncoding="ISO-8859-1"%><%@?taglib?prefix='c'?uri='http://java.sun.com/jstl/core_rt'?%><!DOCTYPE?html?PUBLIC?"-//W3C//DTD HTML 4.01 Transitional//EN"?"http://www.w3.org/TR/html4/loose.dtd"><html><head><meta?http-equiv="Content-Type"?content="text/html; charset=ISO-8859-1"><title>Insert title here</title></head><body>????<c:if?test="${not empty?param.login_error}">??????<font?color="red">??????? Your login attempt was not successful, try again.<br/><br/>??????? Reason:?<c:out?value="${SPRING_SECURITY_LAST_EXCEPTION.message}"/>.??????</font>????</c:if>