使用Spring Security、Spring Data Jpa实现的RBAC权限控制

声明:本文纯属个人随手笔记,如果对您有参考价值我十分开心,如果有存在错误,或者有更好的解决办法也麻烦您留言告诉我,大家共同成长,切勿恶言相。 欢迎加入资源共享QQ群:275343679,一起发现知识、了解知识、学习知识、分享知识。

个人网站www.itlantian.top  www.blueskyui.cn

=================================================================================



正好这几天不是那么忙,所以就研究了一下spring Security的使用,为了以后方便写篇帖子记录一下。

1.什么是Spring Security?

我想关于什么是Spring Security我都不需要在这里赘述,大家可以到网上百度一下,但是问了大家能快速的融入还是贴一下


Spring Security是一个能够为基于Spring的企业应用系统提供声明式的安全访问控制解决方案的安全框架。它提供了一组可以在Spring应用上下文中配置的Bean,充分利用了Spring IoC,DI(控制反转Inversion of Control ,DI:Dependency Injection 依赖注入)和AOP(面向切面编程)功能,为应用系统提供声明式的安全访问控制功能,减少了为企业系统安全控制编写大量重复代码的工作。

2.Spring Security有什么?

我们可以使用Spring Security做基于表单的登录认证(form-login)、弹窗的登录认证(http-basic)、对受保护资源的访问控制、单点登录等等。

3.要怎么使用Spring Security?

对于SpringSecurity的登录认证和密码加密等现在都不做讨论,主要说一下对受保护资源的访问控制。

在Spring Security中最做URL权限鉴定最关键的一个类就是FilterSecurityInterceptor,FilterSecurityInterceptor中还需要2个关键的类AccessDecisionManager 和SecurityMetadataSource,这是2个接口类,我们主要的的是他们的实现类。

他们的作用分别是:

AccessDecisionManager做权限的验证

主要方法就是:

void decide(Authentication authentication, Object object, Collection<ConfigAttribute> configAttributes) ,

SecurityMetadataSource是注入元数据

主要方法是:

public Collection<ConfigAttribute> getAttributes(Object object)
public Collection<ConfigAttribute> getAllConfigAttributes()

开始设计了

主要的domain类

  1. User
  2. UserGroup
  3. Role
  4. Permission
  5. Menu
  6. Resource

这里重点贴一下User.Java和Role.java

User.java

[java]  view plain  copy
 print ?
  1. package org.ylez.web.domain;  
  2.   
  3. import org.springframework.security.core.GrantedAuthority;  
  4. import org.springframework.security.core.userdetails.UserDetails;  
  5.   
  6. import javax.persistence.*;  
  7. import java.util.*;  
  8.   

  9. @Entity  
  10. @Table(name = "t_user")  
  11. public class User extends SuperClass implements UserDetails {  
  12.   
  13.     @Column(unique = true, nullable = false, length = 30)  
  14.     private String username;  
  15.   
  16.     @Column(nullable = false, length = 30)  
  17.     private String password;  
  18.   
  19.     private int age;  
  20.   
  21.     @Column(unique = true)  
  22.     private String email;  
  23.   
  24.     @Column(unique = true, length = 11)  
  25.     private String phone;  
  26.   
  27.     @ManyToMany(targetEntity = UserGroup.class, mappedBy = "users")  
  28.     private Set<UserGroup> userGroup = new HashSet();  
  29.   
  30.     @ManyToMany(targetEntity = Role.class, fetch = FetchType.EAGER)  
  31.     @JoinTable(name = "m_user_role", joinColumns = {@JoinColumn(name = "user_id")}, inverseJoinColumns = {@JoinColumn(name = "role_id")})  
  32.     private Set<Role> roles = new HashSet<>();  
  33.   
  34.     @Transient  
  35.     private Set<Role> authorities = new HashSet<>();  
  36.   
  37.   
  38.     @Override  
  39.     public Collection<? extends GrantedAuthority> getAuthorities() {  
  40.   
  41.         // 包裹用户单独赋予的角色  
  42.         authorities.addAll(roles);  
  43.   
  44.         return authorities;  
  45.     }  
  46.   
  47.     @Override  
  48.     public String getPassword() {  
  49.         return password;  
  50.     }  
  51.   
  52.     @Override  
  53.     public String getUsername() {  
  54.         return username;  
  55.     }  
  56.   
  57.     @Override  
  58.     public boolean isAccountNonExpired() {  
  59.         return true;  
  60.     }  
  61.   
  62.     @Override  
  63.     public boolean isAccountNonLocked() {  
  64.         return true;  
  65.     }  
  66.   
  67.     @Override  
  68.     public boolean isCredentialsNonExpired() {  
  69.         return true;  
  70.     }  
  71.   
  72.     public void setUsername(String username) {  
  73.         this.username = username;  
  74.     }  
  75.   
  76.     public void setPassword(String password) {  
  77.         this.password = password;  
  78.     }  
  79.   
  80.     public int getAge() {  
  81.         return age;  
  82.     }  
  83.   
  84.     public void setAge(int age) {  
  85.         this.age = age;  
  86.     }  
  87.   
  88.     public String getEmail() {  
  89.         return email;  
  90.     }  
  91.   
  92.     public void setEmail(String email) {  
  93.         this.email = email;  
  94.     }  
  95.   
  96.     public String getPhone() {  
  97.         return phone;  
  98.     }  
  99.   
  100.     public void setPhone(String phone) {  
  101.         this.phone = phone;  
  102.     }  
  103.   
  104.     public Set<UserGroup> getUserGroup() {  
  105.         return userGroup;  
  106.     }  
  107.   
  108.     public void setUserGroup(Set<UserGroup> userGroup) {  
  109.         this.userGroup = userGroup;  
  110.     }  
  111.   
  112.     public Set<Role> getRoles() {  
  113.         return roles;  
  114.     }  
  115.   
  116.     public void setRoles(Set<Role> roles) {  
  117.         this.roles = roles;  
  118.     }  
  119.   
  120.     public void setAuthorities(Set<Role> authorities) {  
  121.         this.authorities = authorities;  
  122.     }  
  123. }  

Role.java

[java]  view plain  copy
 print ?
  1. package org.ylez.web.domain;  
  2.   
  3. import org.springframework.security.core.GrantedAuthority;  
  4.   
  5. import javax.persistence.*;  
  6. import java.util.ArrayList;  
  7. import java.util.HashSet;  
  8. import java.util.List;  
  9. import java.util.Set;  
  10.   

  11. @Entity  
  12. @Table(name = "t_role")  
  13. public class Role extends SuperClass implements GrantedAuthority {  
  14.   
  15.     @Column(nullable = false, length = 30)  
  16.     private String name;  
  17.   
  18.     @Column(nullable = false, length = 30)  
  19.     private String nickName;  
  20.   
  21.     private String comment;  
  22.   
  23.     @ManyToMany(targetEntity = Permission.class, fetch = FetchType.EAGER)  
  24.     @JoinTable(name = "m_role_permission", joinColumns = {@JoinColumn(name = "role_id")}, inverseJoinColumns = {@JoinColumn(name = "permission_id")})  
  25.     private Set<Permission> permissions = new HashSet<>();  
  26.   
  27.     @ManyToMany(targetEntity = User.class, mappedBy = "roles")  
  28.     private Set<User> users = new HashSet<>();  
  29.   
  30.     @ManyToMany(targetEntity = UserGroup.class, mappedBy = "roles")  
  31.     private Set<UserGroup> userGroups = new HashSet<>();  
  32.   
  33.     public String getName() {  
  34.         return name;  
  35.     }  
  36.   
  37.     public void setName(String name) {  
  38.         this.name = name;  
  39.     }  
  40.   
  41.     public String getNickName() {  
  42.         return nickName;  
  43.     }  
  44.   
  45.     public void setNickName(String nickName) {  
  46.         this.nickName = nickName;  
  47.     }  
  48.   
  49.     public String getComment() {  
  50.         return comment;  
  51.     }  
  52.   
  53.     public void setComment(String comment) {  
  54.         this.comment = comment;  
  55.     }  
  56.   
  57.     public Set<Permission> getPermissions() {  
  58.         return permissions;  
  59.     }  
  60.   
  61.     public void setPermissions(Set<Permission> permissions) {  
  62.         this.permissions = permissions;  
  63.     }  
  64.   
  65.     public Set<User> getUsers() {  
  66.         return users;  
  67.     }  
  68.   
  69.     public void setUsers(Set<User> users) {  
  70.         this.users = users;  
  71.     }  
  72.   
  73.     public Set<UserGroup> getUserGroups() {  
  74.         return userGroups;  
  75.     }  
  76.   
  77.     public void setUserGroups(Set<UserGroup> userGroups) {  
  78.         this.userGroups = userGroups;  
  79.     }  
  80.   
  81.     @Override  
  82.     public String getAuthority() {  
  83.         return name;  
  84.     }  
  85. }  

创建UserDetailsService在登录的时候加载用户信息


[java]  view plain  copy
 print ?
  1. package org.ylez.web.security.service;  
  2.   
  3. import org.springframework.beans.factory.annotation.Autowired;  
  4. import org.springframework.security.core.GrantedAuthority;  
  5. import org.springframework.security.core.authority.SimpleGrantedAuthority;  
  6. import org.springframework.security.core.userdetails.UserDetails;  
  7. import org.springframework.security.core.userdetails.UserDetailsService;  
  8. import org.springframework.security.core.userdetails.UsernameNotFoundException;  
  9. import org.ylez.web.domain.Role;  
  10. import org.ylez.web.domain.User;  
  11. import org.ylez.web.domain.UserGroup;  
  12. import org.ylez.web.service.UserService;  
  13.   
  14. import java.util.HashSet;  
  15. import java.util.List;  
  16. import java.util.Set;  
  17.   
  18. public class UserDetailsServiceImpl implements UserDetailsService {  
  19.   
  20.     @Autowired  
  21.     private UserService userService;  
  22.   
  23.     @Override  
  24.     public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {  
  25.         User user = userService.loadUserByUsername(username);  
  26.         if (user != null) {  
  27.             Set<UserGroup> userGroup = user.getUserGroup();  
  28.   
  29.             for (UserGroup group : userGroup) {  
  30.                 Set<Role> roles = group.getRoles();  
  31.                 user.setAuthorities(roles);  
  32.             }  
  33.             return user;  
  34.         }else {  
  35.             throw new UsernameNotFoundException("找不到指定的用户信息!!!");  
  36.         }  
  37.     }  
  38. }  


注意:

[java]  view plain  copy
 print ?
  1. for (UserGroup group : userGroup) {  
  2.     Set<Role> roles = group.getRoles();  
  3.     user.setAuthorities(roles);  
  4. }  
这里我讲用户所在的用户组所具有的角色也放置到用的 authorities

接下类创建一个AuthorizationSecurityInterceptor.java的类源码如下:

[java]  view plain  copy
 print ?
  1. package org.ylez.web.security.interceptor;  
  2.   
  3. import java.io.IOException;  
  4.   
  5. import javax.servlet.Filter;  
  6. import javax.servlet.FilterChain;  
  7. import javax.servlet.FilterConfig;  
  8. import javax.servlet.ServletException;  
  9. import javax.servlet.ServletRequest;  
  10. import javax.servlet.ServletResponse;  
  11.   
  12. import org.springframework.security.access.SecurityMetadataSource;  
  13. import org.springframework.security.access.intercept.AbstractSecurityInterceptor;  
  14. import org.springframework.security.access.intercept.InterceptorStatusToken;  
  15. import org.springframework.security.web.FilterInvocation;  
  16. import org.springframework.security.web.access.intercept.FilterInvocationSecurityMetadataSource;  
  17.   

  18. public class AuthorizationSecurityInterceptor extends AbstractSecurityInterceptor implements Filter {  
  19.   
  20.     private static final String FILTER_APPLIED = "__Spring_Security_AuthorizationSecurityInterceptor_FilterApplied";  
  21.   
  22.     private FilterInvocationSecurityMetadataSource securityMetadataSource;  
  23.   
  24.     private boolean observeOncePerRequest = true;  
  25.   
  26.     @Override  
  27.     public void init(FilterConfig arg0) throws ServletException {  
  28.     }  
  29.   
  30.     @Override  
  31.     public void destroy() {  
  32.     }  
  33.   
  34.     @Override  
  35.     public void doFilter(ServletRequest request, ServletResponse response,  
  36.                          FilterChain chain) throws IOException, ServletException {  
  37.         FilterInvocation fi = new FilterInvocation(request, response, chain);  
  38.         invoke(fi);  
  39.     }  
  40.   
  41.     public FilterInvocationSecurityMetadataSource getSecurityMetadataSource() {  
  42.         return this.securityMetadataSource;  
  43.     }  
  44.   
  45.     @Override  
  46.     public SecurityMetadataSource obtainSecurityMetadataSource() {  
  47.         return this.securityMetadataSource;  
  48.     }  
  49.   
  50.     public void setSecurityMetadataSource(FilterInvocationSecurityMetadataSource newSource) {  
  51.         this.securityMetadataSource = newSource;  
  52.     }  
  53.   
  54.     @Override  
  55.     public Class<?> getSecureObjectClass() {  
  56.         return FilterInvocation.class;  
  57.     }  
  58.   
  59.     public void invoke(FilterInvocation fi) throws IOException, ServletException {  
  60.         if ((fi.getRequest() != null)  
  61.                 && (fi.getRequest().getAttribute(FILTER_APPLIED) != null)  
  62.                 && observeOncePerRequest) {  
  63.   
  64.             fi.getChain().doFilter(fi.getRequest(), fi.getResponse());  
  65.         }  
  66.         else {  
  67.             if (fi.getRequest() != null) {  
  68.                 fi.getRequest().setAttribute(FILTER_APPLIED, Boolean.TRUE);  
  69.             }  
  70.   
  71.             InterceptorStatusToken token = super.beforeInvocation(fi);  
  72.   
  73.             try {  
  74.                 fi.getChain().doFilter(fi.getRequest(), fi.getResponse());  
  75.             }  
  76.             finally {  
  77.                 super.finallyInvocation(token);  
  78.             }  
  79.   
  80.             super.afterInvocation(token, null);  
  81.         }  
  82.     }  
  83.   
  84.     public boolean isObserveOncePerRequest() {  
  85.         return observeOncePerRequest;  
  86.     }  
  87.   
  88.     public void setObserveOncePerRequest(boolean observeOncePerRequest) {  
  89.         this.observeOncePerRequest = observeOncePerRequest;  
  90.     }  
  91. }  

AuthorizationSecurityInterceptor的作用就是做URL的访问控制,需要注入AccessDecisionManager 和SecurityMetadataSource,可能有会奇怪为啥还要实现AuthorizationSecurityInterceptor,Spring Security不是为我们提供了FilterSecurityInterceptor吗?主要是SpringSecurity内部维护了一个FilterChain这个FilterChain是有一定的顺序的我们不能随便打乱,默认的FilterSecurityInterceptor也不太符合我们的需求,所以创建了AuthorizationSecurityInterceptor。

接下来创建AccessDecisionManagerImpl.java:

[java]  view plain  copy
 print ?
  1. package org.ylez.web.security.accessdecisionmanager;  
  2.   
  3. import org.springframework.context.MessageSource;  
  4. import org.springframework.context.support.MessageSourceAccessor;  
  5. import org.springframework.security.access.AccessDecisionManager;  
  6. import org.springframework.security.access.AccessDeniedException;  
  7. import org.springframework.security.access.ConfigAttribute;  
  8. import org.springframework.security.authentication.InsufficientAuthenticationException;  
  9. import org.springframework.security.core.Authentication;  
  10. import org.springframework.security.core.GrantedAuthority;  
  11. import org.springframework.security.core.SpringSecurityMessageSource;  
  12. import org.springframework.util.StringUtils;  
  13. import org.ylez.web.domain.Role;  
  14.   
  15. import java.util.Collection;  
  16.   

  17. public class AccessDecisionManagerImpl implements AccessDecisionManager {  
  18.   
  19.     protected MessageSourceAccessor messages = SpringSecurityMessageSource.getAccessor();  
  20.   
  21.     /** 
  22.      * @param authentication 当前认证通过的用户的认证信息 
  23.      * @param object 当前用户访问的受保护资源,如URL 
  24.      * @param configAttributes 当前受保护资源需要的角色,权限 
  25.      * @throws AccessDeniedException 
  26.      * @throws InsufficientAuthenticationException 
  27.      */  
  28.     @Override  
  29.     public void decide(Authentication authentication, Object object, Collection<ConfigAttribute> configAttributes) throws AccessDeniedException, InsufficientAuthenticationException {  
  30.   
  31.         Collection<? extends GrantedAuthority> authorities = authentication.getAuthorities();  
  32.   
  33.         for (GrantedAuthority authority : authorities) {  
  34.             // 角色名  
  35.             String roleName = authority.getAuthority();  
  36.   
  37.             for (ConfigAttribute configAttribute : configAttributes) {  
  38.                 if (configAttribute != null && !StringUtils.isEmpty(roleName)) {  
  39.                     if (configAttribute.getAttribute().equals(roleName)) {  
  40.                         return;  
  41.                     }  
  42.                 }  
  43.             }  
  44.         }  
  45.   
  46.         throw new AccessDeniedException(messages.getMessage(  
  47.                 "AbstractAccessDecisionManager.accessDenied""Access is denied"));  
  48.     }  
  49.   
  50.     public void setMessageSource(MessageSource messageSource) {  
  51.         this.messages = new MessageSourceAccessor(messageSource);  
  52.     }  
  53.   
  54.     /** 
  55.      * @param attribute 权限信息 
  56.      * @return 
  57.      */  
  58.     @Override  
  59.     public boolean supports(ConfigAttribute attribute) {  
  60.         return true;  
  61.     }  
  62.   
  63.     @Override  
  64.     public boolean supports(Class<?> clazz) {  
  65.         return true;  
  66.     }  
  67. }  


AccessDecisionManagerImpl中的 decide(Authentication authentication, Object object, Collection<ConfigAttribute> configAttributes)方法注入了三个参数

Authentication authentication 是用户登录成功后的认证信息包含了当前用户所具有的角色信息。
Object object 是当前用户请求的受保护的资源。

Collection<ConfigAttribute> configAttributes 是当前用户请求的受保护资源应该具备的角色。

decide方法的逻辑就是将authentication中包含的角色和configAttributes中的角色进行比较,看authentication中是否有configAttributes种需要的角色,如果有就标识权限认证成功直接return方法就好如果没有就抛出异常throw new AccessDeniedException(messages.getMessage("AbstractAccessDecisionManager.accessDenied", "Access is denied"));。


接下来再创建FilterInvocationSecurityMetadataSourceImpl.java:

[java]  view plain  copy
 print ?
  1. package org.ylez.web.security.metadatasource;  
  2.   
  3. import org.springframework.beans.factory.annotation.Autowired;  
  4. import org.springframework.security.access.ConfigAttribute;  
  5. import org.springframework.security.access.SecurityConfig;  
  6. import org.springframework.security.web.FilterInvocation;  
  7. import org.springframework.security.web.access.intercept.FilterInvocationSecurityMetadataSource;  
  8. import org.ylez.web.domain.Permission;  
  9. import org.ylez.web.domain.Resource;  
  10. import org.ylez.web.domain.Role;  
  11. import org.ylez.web.service.ResourceService;  
  12.   
  13. import java.util.*;  
  14.   

  15. public class FilterInvocationSecurityMetadataSourceImpl implements FilterInvocationSecurityMetadataSource {  
  16.   
  17.     @Autowired  
  18.     private ResourceService resourceService;  
  19.   
  20.     private Map<String, Collection<ConfigAttribute>> requestMap = new LinkedHashMap<>();;  
  21.     /** 
  22.      * @param object 当前用户访问的受保护的资源 
  23.      * @return 
  24.      * @throws IllegalArgumentException 
  25.      */  
  26.     @Override  
  27.     public Collection<ConfigAttribute> getAttributes(Object object) throws IllegalArgumentException {  
  28.   
  29.         System.err.println("-----------------------FilterInvocationSecurityMetadataSourceImpl.getAttributes-----------------------");  
  30.   
  31.         String address = ((FilterInvocation) object).getRequestUrl();  
  32.   
  33.         Resource resource = resourceService.findByAddress(address);  
  34.         if (resource != null) {  
  35.             String resourceName = resource.getName();  
  36.   
  37.             Collection<ConfigAttribute> configAttributes = requestMap.get(resourceName);  
  38.   
  39.             return configAttributes;  
  40.         }  
  41.   
  42.         return new HashSet<>();  
  43.     }  
  44.   
  45.     @Override  
  46.     public Collection<ConfigAttribute> getAllConfigAttributes() {  
  47.   
  48.         System.err.println("+++++++++++++++++++FilterInvocationSecurityMetadataSourceImpl.getAllConfigAttributes+++++++++++++++++++");  
  49.   
  50.         Set<ConfigAttribute> allAttributes = new HashSet<>();  
  51.   
  52.         List<Resource> resourceList = resourceService.findAll();  
  53.   
  54.         for (Resource resource : resourceList) {  
  55.   
  56.             Set<ConfigAttribute> itemAttributes = new HashSet<>();  
  57.   
  58.             Set<Permission> permissions = resource.getPermissions();  
  59.   
  60.             for (Permission permission : permissions) {  
  61.   
  62.                 Set<Role> roles = permission.getRoles();  
  63.   
  64.                 for (Role role : roles) {  
  65.   
  66.                     ConfigAttribute ca = new SecurityConfig(role.getAuthority());  
  67.   
  68.                     // 每一个请求资源对应的Role  
  69.                     itemAttributes.add(ca);  
  70.   
  71.                     // 所有的Role对象  
  72.                     allAttributes.add(ca);  
  73.                 }  
  74.             }  
  75.             String resourceName = resource.getName();  
  76.   
  77.             requestMap.put(resourceName, itemAttributes);  
  78.         }  
  79.         return allAttributes;  
  80.     }  
  81.   
  82.     @Override  
  83.     public boolean supports(Class<?> clazz) {  
  84.         return true;  
  85.     }  
  86. }  

FilterInvocationSecurityMetadataSourceImpl中主要方法

public Collection<ConfigAttribute> getAttributes(Object object)
public Collection<ConfigAttribute> getAllConfigAttributes()

getAllConfigAttributes() 是查询出所有的角色,该方法中我查询了所有的角色进行返回,该方法在程序启动的时候就会执行,所以做了一个requestMap

[java]  view plain  copy
 print ?
  1. private Map<String, Collection<ConfigAttribute>> requestMap = new LinkedHashMap<>();  

来缓存请求资源和角色的对应关系。在getAttributes(Object object)中我们就可以根据object直接从requestMap中取得。

getAttributes是根据访问的资源来查找对应所需角色,当请求过来时,我们可以根据参数object得到请求的URL去直接查询数据库,也可以在getAllConfigAttributes()查询所有做缓存我们从缓存中来查询,我这里做的还不是很好可以在优化一下。


现在就是在SecurityContext.xml中配置Spring Security了:

[html]  view plain  copy
 print ?
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <beans xmlns="http://www.springframework.org/schema/beans"  
  3.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  4.        xmlns:security="http://www.springframework.org/schema/security"  
  5.        xmlns:context="http://www.springframework.org/schema/context"  
  6.        xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">  
  7.   
  8.     <context:property-placeholder location="classpath:settings.properties" />  
  9.   
  10.     <security:http pattern="/admin/login.html" security="none"/>  
  11.     <security:http pattern="/react/**" security="none"/>  
  12.     <security:http pattern="/static/**" security="none"/>  
  13.     <security:http auto-config="true">  
  14.         <security:form-login  
  15.             login-page="/admin/login.html"  
  16.             login-processing-url="/admin/login.htm"  
  17.             username-parameter="username"  
  18.             password-parameter="password"  
  19.             default-target-url="/admin/index.html"  
  20.             always-use-default-target="true" />  
  21.         <security:http-basic/>  
  22.         <security:remember-me remember-me-parameter="rememberMe" key="ylez-unique-key" remember-me-cookie="ylez" />  
  23.         <security:logout logout-url="/logout.htm" invalidate-session="true" delete-cookies="ylez"/>  
  24.         <security:session-management invalid-session-url="/admin/login.html" session-fixation-protection="newSession">  
  25.             <security:concurrency-control max-sessions="2" expired-url="/admin/login.html" />  
  26.         </security:session-management>  
  27.         <security:port-mappings>  
  28.             <security:port-mapping http="80" https="443"/>  
  29.         </security:port-mappings>  
  30.         <security:csrf disabled="true"/>  
  31.         <security:custom-filter ref="authorizationSecurityInterceptor" before="FILTER_SECURITY_INTERCEPTOR"/>  
  32.     </security:http>  
  33.   
  34.     <security:authentication-manager erase-credentials="false">  
  35.         <security:authentication-provider user-service-ref="userDetailsService">  
  36.             <security:password-encoder ref="passwordEncoder">  
  37.                 <security:salt-source ref="saltSource"/>  
  38.             </security:password-encoder>  
  39.         </security:authentication-provider>  
  40.     </security:authentication-manager>  
  41.   
  42.     <!-- 密码加密工具,在用户注册的时候也是这个加密的工具. -->  
  43.     <bean id="passwordEncoder" class="org.ylez.web.security.password.PasswordEncoderImpl">  
  44.         <!-- 密码加密的时候的散列算法 -->  
  45.         <constructor-arg name="algorithm" value="${passwordEncoder.algorithm}" />  
  46.         <!-- 密码加密的时候的加密次数 -->  
  47.         <constructor-arg name="iterations" value="${passwordEncoder.iterations}" />  
  48.     </bean>  
  49.   
  50.     <bean id="saltSource" class="org.ylez.web.security.salt.SaltSourceImpl" />  
  51.   
  52.     <bean id="authorizationSecurityInterceptor" class="org.ylez.web.security.interceptor.AuthorizationSecurityInterceptor">  
  53.         <property name="accessDecisionManager" ref="accessDecisionManager"/>  
  54.         <property name="securityMetadataSource" ref="securityMetadataSource" />  
  55.     </bean>  
  56.   
  57.     <bean id="accessDecisionManager" class="org.ylez.web.security.accessdecisionmanager.AccessDecisionManagerImpl" />  
  58.   
  59.     <bean id="securityMetadataSource" class="org.ylez.web.security.metadatasource.FilterInvocationSecurityMetadataSourceImpl" />  
  60.   
  61.     <bean id="userDetailsService" class="org.ylez.web.security.service.UserDetailsServiceImpl"/>  
  62. </beans>  


Spring的配置文件

[html]  view plain  copy
 print ?
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <beans xmlns="http://www.springframework.org/schema/beans"  
  3.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  4.        xmlns:context="http://www.springframework.org/schema/context"  
  5.        xmlns:aop="http://www.springframework.org/schema/aop"  
  6.        xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd         http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">  
  7.   
  8.     <context:component-scan base-package="org.ylez.web.config" />  
  9.   
  10.     <context:component-scan base-package="org.ylez.web.service" />  
  11.   
  12.     <context:property-placeholder location="classpath:settings.properties" />  
  13.   
  14.     <aop:aspectj-autoproxy expose-proxy="true"/>  
  15.   
  16.     <import resource="securityContext.xml" />  
  17. </beans>  

web.xml的配置

[html]  view plain  copy
 print ?
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"  
  3.          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  4.          xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"  
  5.          version="3.1">  
  6.   
  7.     <context-param>  
  8.         <param-name>contextConfigLocation</param-name>  
  9.         <param-value>classpath:applicationContext.xml</param-value>  
  10.     </context-param>  
  11.   
  12.     <listener>  
  13.         <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>  
  14.     </listener>  
  15.   
  16.     <!-- 处理配置了懒加载的问题 -->  
  17.     <filter>  
  18.         <filter-name>openEntityManagerInViewFilter</filter-name>  
  19.         <filter-class>org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter</filter-class>  
  20.     </filter>  
  21.     <filter-mapping>  
  22.         <filter-name>openEntityManagerInViewFilter</filter-name>  
  23.         <url-pattern>/*</url-pattern>  
  24.     </filter-mapping>  
  25.   
  26.     <filter>  
  27.         <filter-name>encodingFilter</filter-name>  
  28.         <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>  
  29.         <init-param>  
  30.             <param-name>encoding</param-name>  
  31.             <param-value>UTF-8</param-value>  
  32.         </init-param>  
  33.         <init-param>  
  34.             <param-name>forceEncoding</param-name>  
  35.             <param-value>true</param-value>  
  36.         </init-param>  
  37.     </filter>  
  38.     <filter-mapping>  
  39.         <filter-name>encodingFilter</filter-name>  
  40.         <url-pattern>/*</url-pattern>  
  41.     </filter-mapping>  
  42.   
  43.     <!-- 配置SpringSecurity的代理过滤器 -->  
  44.     <filter>  
  45.         <filter-name>springSecurityFilterChain</filter-name>  
  46.         <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>  
  47.     </filter>  
  48.     <filter-mapping>  
  49.         <filter-name>springSecurityFilterChain</filter-name>  
  50.         <url-pattern>/*</url-pattern>  
  51.     </filter-mapping>  
  52.   
  53.   
  54.   
  55.     <!-- 配置SpringMVC的Servlet -->  
  56.     <servlet>  
  57.         <servlet-name>dispatcherServlet</servlet-name>  
  58.         <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>  
  59.         <init-param>  
  60.             <param-name>contextConfigLocation</param-name>  
  61.             <param-value>classpath:safeApp-servlet.xml</param-value>  
  62.         </init-param>  
  63.         <load-on-startup>1</load-on-startup>  
  64.     </servlet>  
  65.     <servlet-mapping>  
  66.         <servlet-name>dispatcherServlet</servlet-name>  
  67.         <url-pattern>/*</url-pattern>  
  68.     </servlet-mapping>  
  69. </web-app>  

Jpa的配置:

[java]  view plain  copy
 print ?
  1. package org.ylez.web.config;  
  2.   
  3. import com.alibaba.druid.pool.DruidDataSource;  
  4. import org.springframework.context.annotation.Bean;  
  5. import org.springframework.context.annotation.Configuration;  
  6. import org.springframework.data.jpa.repository.config.EnableJpaRepositories;  
  7. import org.springframework.orm.jpa.JpaTransactionManager;  
  8. import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;  
  9. import org.springframework.orm.jpa.vendor.Database;  
  10. import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;  
  11. import org.springframework.transaction.PlatformTransactionManager;  
  12. import org.springframework.transaction.annotation.EnableTransactionManagement;  
  13.   
  14. import javax.persistence.EntityManagerFactory;  
  15. import javax.sql.DataSource;  
  16. import java.util.HashMap;  
  17. import java.util.Map;  
  18.   
  19. /** 
  20.  * @FileName: JpaConfig 
  21.  * @Author: 唐欢 
  22.  * @Date: 2016-05-11 14:15 
  23.  * @Tool: IntelliJ IDEA 
  24.  */  
  25. @Configuration  
  26. @EnableJpaRepositories(basePackages = "org.ylez.web.repository")  
  27. @EnableTransactionManagement  
  28. public class JpaConfig {  
  29.   
  30.     @Bean  
  31.     public DataSource dataSource() {  
  32.         DruidDataSource dataSource = new DruidDataSource();  
  33.         dataSource.setDriverClassName("com.mysql.jdbc.Driver");  
  34.         dataSource.setUrl("jdbc:mysql://localhost:3306/ylez?createDatabaseIfNotExist=true");  
  35.         dataSource.setUsername("root");  
  36.         dataSource.setPassword("admin");  
  37.   
  38.         dataSource.setInitialSize(10);  
  39.         dataSource.setMinIdle(10);  
  40.         dataSource.setMaxActive(50);  
  41.   
  42.         dataSource.setMaxWait(60000);  
  43.         dataSource.setTimeBetweenConnectErrorMillis(60000);  
  44.   
  45.         dataSource.setMinEvictableIdleTimeMillis(300000);  
  46.   
  47.         dataSource.setValidationQuery(" SELECT 'x' ");  
  48.         dataSource.setTestWhileIdle(true);  
  49.         dataSource.setTestOnBorrow(false);  
  50.         dataSource.setTestOnReturn(false);  
  51.   
  52.         dataSource.setPoolPreparedStatements(false);  
  53.         dataSource.setMaxPoolPreparedStatementPerConnectionSize(20);  
  54.   
  55.         return dataSource;  
  56.     }  
  57.   
  58.     @Bean  
  59.     public EntityManagerFactory entityManagerFactory() {  
  60.         LocalContainerEntityManagerFactoryBean entityManagerFactory = new LocalContainerEntityManagerFactoryBean();  
  61.         HibernateJpaVendorAdapter adapter = new HibernateJpaVendorAdapter();  
  62.         adapter.setGenerateDdl(true);  
  63.         adapter.setDatabase(Database.MYSQL);  
  64.         adapter.setShowSql(true);  
  65.   
  66.         entityManagerFactory.setJpaVendorAdapter(adapter);  
  67.         entityManagerFactory.setDataSource(dataSource());  
  68.         entityManagerFactory.setPackagesToScan("org.ylez.web.domain");  
  69.         Map<String, Object> propsMap = new HashMap<>();  
  70.         propsMap.put("hibernate.format_sql"true);  
  71.         propsMap.put("hibernate.dialect""org.hibernate.dialect.MySQL57InnoDBDialect");  
  72.         entityManagerFactory.setJpaPropertyMap(propsMap);  
  73.         entityManagerFactory.afterPropertiesSet();  
  74.         return entityManagerFactory.getObject();  
  75.     }  
  76.   
  77.     @Bean  
  78.     public PlatformTransactionManager transactionManager() {  
  79.         JpaTransactionManager transactionManager = new JpaTransactionManager(entityManagerFactory());  
  80.         return transactionManager;  
  81.     }  
  82. }  

SQL代码:

[sql]  view plain  copy
 print ?
  1. /*  
  2.  Navicat Premium Data Transfer  
  3.   
  4.  Source Server         : 127.0.0.1  
  5.  Source Server Type    : MySQL  
  6.  Source Server Version : 50711  
  7.  Source Host           : 127.0.0.1  
  8.  Source Database       : ylez  
  9.   
  10.  Target Server Type    : MySQL  
  11.  Target Server Version : 50711  
  12.  File Encoding         : utf-8  
  13.   
  14.  Date: 05/17/2016 00:15:22 AM  
  15. */  
  16.   
  17. SET NAMES utf8;  
  18. SET FOREIGN_KEY_CHECKS = 0;  
  19.   
  20. -- ----------------------------  
  21. --  Table structure for `m_permission_menu`  
  22. -- ----------------------------  
  23. DROP TABLE IF EXISTS `m_permission_menu`;  
  24. CREATE TABLE `m_permission_menu` (  
  25.   `permission_id` bigint(20) NOT NULL,  
  26.   `menu_id` bigint(20) NOT NULL,  
  27.   PRIMARY KEY (`permission_id`,`menu_id`),  
  28.   KEY `FKrck475a4xibvhvbipdsbml4jo` (`menu_id`),  
  29.   CONSTRAINT `FK892mp1voq26r0krjfnoqqfy8e` FOREIGN KEY (`permission_id`) REFERENCES `t_permission` (`id`),  
  30.   CONSTRAINT `FKrck475a4xibvhvbipdsbml4jo` FOREIGN KEY (`menu_id`) REFERENCES `t_menu` (`id`)  
  31. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;  
  32.   
  33. -- ----------------------------  
  34. --  Table structure for `m_permission_resource`  
  35. -- ----------------------------  
  36. DROP TABLE IF EXISTS `m_permission_resource`;  
  37. CREATE TABLE `m_permission_resource` (  
  38.   `permission_id` bigint(20) NOT NULL,  
  39.   `resource_id` bigint(20) NOT NULL,  
  40.   PRIMARY KEY (`permission_id`,`resource_id`),  
  41.   KEY `FKqiqcr9msd3laua6pgk03gthth` (`resource_id`),  
  42.   CONSTRAINT `FK5wgud3b6ohn30iix2c4dhxgmm` FOREIGN KEY (`permission_id`) REFERENCES `t_permission` (`id`),  
  43.   CONSTRAINT `FKqiqcr9msd3laua6pgk03gthth` FOREIGN KEY (`resource_id`) REFERENCES `t_resource` (`id`)  
  44. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;  
  45.   
  46. -- ----------------------------  
  47. --  Records of `m_permission_resource`  
  48. -- ----------------------------  
  49. BEGIN;  
  50. INSERT INTO `m_permission_resource` VALUES ('1''1'), ('2''2');  
  51. COMMIT;  
  52.   
  53. -- ----------------------------  
  54. --  Table structure for `m_role_permission`  
  55. -- ----------------------------  
  56. DROP TABLE IF EXISTS `m_role_permission`;  
  57. CREATE TABLE `m_role_permission` (  
  58.   `role_id` bigint(20) NOT NULL,  
  59.   `permission_id` bigint(20) NOT NULL,  
  60.   PRIMARY KEY (`role_id`,`permission_id`),  
  61.   KEY `FKjsv718s6pysaxl3hwdbh32v16` (`permission_id`),  
  62.   CONSTRAINT `FK71nkax6g3ndcd1q4iue3xfksb` FOREIGN KEY (`role_id`) REFERENCES `t_role` (`id`),  
  63.   CONSTRAINT `FKjsv718s6pysaxl3hwdbh32v16` FOREIGN KEY (`permission_id`) REFERENCES `t_permission` (`id`)  
  64. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;  
  65.   
  66. -- ----------------------------  
  67. --  Records of `m_role_permission`  
  68. -- ----------------------------  
  69. BEGIN;  
  70. INSERT INTO `m_role_permission` VALUES ('1''1'), ('1''2'), ('2''2');  
  71. COMMIT;  
  72.   
  73. -- ----------------------------  
  74. --  Table structure for `m_user_role`  
  75. -- ----------------------------  
  76. DROP TABLE IF EXISTS `m_user_role`;  
  77. CREATE TABLE `m_user_role` (  
  78.   `user_id` bigint(20) NOT NULL,  
  79.   `role_id` bigint(20) NOT NULL,  
  80.   PRIMARY KEY (`user_id`,`role_id`),  
  81.   KEY `FK3kaylpusfxvtsulifg7u1o0cj` (`role_id`),  
  82.   CONSTRAINT `FK3kaylpusfxvtsulifg7u1o0cj` FOREIGN KEY (`role_id`) REFERENCES `t_role` (`id`),  
  83.   CONSTRAINT `FK6520i3b07huaey0kr9fw49ln` FOREIGN KEY (`user_id`) REFERENCES `t_user` (`id`)  
  84. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;  
  85.   
  86. -- ----------------------------  
  87. --  Records of `m_user_role`  
  88. -- ----------------------------  
  89. BEGIN;  
  90. INSERT INTO `m_user_role` VALUES ('1''1'), ('2''2');  
  91. COMMIT;  
  92.   
  93. -- ----------------------------  
  94. --  Table structure for `m_usergroup_role`  
  95. -- ----------------------------  
  96. DROP TABLE IF EXISTS `m_usergroup_role`;  
  97. CREATE TABLE `m_usergroup_role` (  
  98.   `usergroup_id` bigint(20) NOT NULL,  
  99.   `role_id` bigint(20) NOT NULL,  
  100.   PRIMARY KEY (`usergroup_id`,`role_id`),  
  101.   KEY `FKecy0fvxdsy58ku64uhsd1y1qd` (`role_id`),  
  102.   CONSTRAINT `FKecy0fvxdsy58ku64uhsd1y1qd` FOREIGN KEY (`role_id`) REFERENCES `t_role` (`id`),  
  103.   CONSTRAINT `FKksc98i8kfc50g8bo4imvep8uk` FOREIGN KEY (`usergroup_id`) REFERENCES `t_usergroup` (`id`)  
  104. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;  
  105.   
  106. -- ----------------------------  
  107. --  Records of `m_usergroup_role`  
  108. -- ----------------------------  
  109. BEGIN;  
  110. INSERT INTO `m_usergroup_role` VALUES ('1''1'), ('1''2');  
  111. COMMIT;  
  112.   
  113. -- ----------------------------  
  114. --  Table structure for `m_usergroup_user`  
  115. -- ----------------------------  
  116. DROP TABLE IF EXISTS `m_usergroup_user`;  
  117. CREATE TABLE `m_usergroup_user` (  
  118.   `usergroup_id` bigint(20) NOT NULL,  
  119.   `user_id` bigint(20) NOT NULL,  
  120.   PRIMARY KEY (`usergroup_id`,`user_id`),  
  121.   KEY `FKl53jhmxcy4qy79chcy26wlw4a` (`user_id`),  
  122.   CONSTRAINT `FKl53jhmxcy4qy79chcy26wlw4a` FOREIGN KEY (`user_id`) REFERENCES `t_user` (`id`),  
  123.   CONSTRAINT `FKml2qomhd7tkphcypjel80kbgj` FOREIGN KEY (`usergroup_id`) REFERENCES `t_usergroup` (`id`)  
  124. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;  
  125.   
  126. -- ----------------------------  
  127. --  Records of `m_usergroup_user`  
  128. -- ----------------------------  
  129. BEGIN;  
  130. INSERT INTO `m_usergroup_user` VALUES ('1''1');  
  131. COMMIT;  
  132.   
  133. -- ----------------------------  
  134. --  Table structure for `t_menu`  
  135. -- ----------------------------  
  136. DROP TABLE IF EXISTS `t_menu`;  
  137. CREATE TABLE `t_menu` (  
  138.   `id` bigint(20) NOT NULL AUTO_INCREMENT,  
  139.   `createTime` datetime(6) DEFAULT NULL,  
  140.   `enabled` bit(1) NOT NULL,  
  141.   `updateTime` datetime(6) DEFAULT NULL,  
  142.   `icon` varchar(30) DEFAULT NULL,  
  143.   `levelvarchar(30) NOT NULL,  
  144.   `namevarchar(30) NOT NULL,  
  145.   `status` int(11) NOT NULL,  
  146.   `url` varchar(50) NOT NULL,  
  147.   `parent_id` bigint(20) DEFAULT NULL,  
  148.   PRIMARY KEY (`id`),  
  149.   KEY `FK4paxqyebl0scq6ur9osr0f56k` (`parent_id`),  
  150.   CONSTRAINT `FK4paxqyebl0scq6ur9osr0f56k` FOREIGN KEY (`parent_id`) REFERENCES `t_menu` (`id`)  
  151. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;  
  152.   
  153. -- ----------------------------  
  154. --  Table structure for `t_permission`  
  155. -- ----------------------------  
  156. DROP TABLE IF EXISTS `t_permission`;  
  157. CREATE TABLE `t_permission` (  
  158.   `id` bigint(20) NOT NULL AUTO_INCREMENT,  
  159.   `createTime` datetime(6) DEFAULT NULL,  
  160.   `enabled` bit(1) NOT NULL,  
  161.   `updateTime` datetime(6) DEFAULT NULL,  
  162.   `comment` varchar(255) DEFAULT NULL,  
  163.   `namevarchar(30) NOT NULL,  
  164.   `nickName` varchar(30) NOT NULL,  
  165.   PRIMARY KEY (`id`)  
  166. ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;  
  167.   
  168. -- ----------------------------  
  169. --  Records of `t_permission`  
  170. -- ----------------------------  
  171. BEGIN;  
  172. INSERT INTO `t_permission` VALUES ('1''2016-05-16 17:18:41.000000', b'1''2016-05-16 17:18:47.000000''访问管理后台''MANAGE_INDEX''管理后台'), ('2''2016-05-16 17:19:36.000000', b'1''2016-05-16 17:19:42.000000''网站前台''INDEX''网站前台');  
  173. COMMIT;  
  174.   
  175. -- ----------------------------  
  176. --  Table structure for `t_resource`  
  177. -- ----------------------------  
  178. DROP TABLE IF EXISTS `t_resource`;  
  179. CREATE TABLE `t_resource` (  
  180.   `id` bigint(20) NOT NULL AUTO_INCREMENT,  
  181.   `createTime` datetime(6) DEFAULT NULL,  
  182.   `enabled` bit(1) NOT NULL,  
  183.   `updateTime` datetime(6) DEFAULT NULL,  
  184.   `address` varchar(30) NOT NULL,  
  185.   `namevarchar(30) NOT NULL,  
  186.   `type` varchar(30) NOT NULL,  
  187.   PRIMARY KEY (`id`)  
  188. ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;  
  189.   
  190. -- ----------------------------  
  191. --  Records of `t_resource`  
  192. -- ----------------------------  
  193. BEGIN;  
  194. INSERT INTO `t_resource` VALUES ('1''2016-05-16 17:35:56.000000', b'1''2016-05-16 17:36:03.000000''/admin/index.html''admin_index''a'), ('2''2016-05-16 17:37:20.000000', b'1''2016-05-16 17:37:25.000000''/index.html''index''b');  
  195. COMMIT;  
  196.   
  197. -- ----------------------------  
  198. --  Table structure for `t_role`  
  199. -- ----------------------------  
  200. DROP TABLE IF EXISTS `t_role`;  
  201. CREATE TABLE `t_role` (  
  202.   `id` bigint(20) NOT NULL AUTO_INCREMENT,  
  203.   `createTime` datetime(6) DEFAULT NULL,  
  204.   `enabled` bit(1) NOT NULL,  
  205.   `updateTime` datetime(6) DEFAULT NULL,  
  206.   `comment` varchar(255) DEFAULT NULL,  
  207.   `namevarchar(30) NOT NULL,  
  208.   `nickName` varchar(30) NOT NULL,  
  209.   PRIMARY KEY (`id`)  
  210. ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;  
  211.   
  212. -- ----------------------------  
  213. --  Records of `t_role`  
  214. -- ----------------------------  
  215. BEGIN;  
  216. INSERT INTO `t_role` VALUES ('1''2016-05-16 17:16:42.000000', b'1''2016-05-16 17:16:48.000000''管理员''ADMIN''管理员'), ('2''2016-05-16 17:17:17.000000', b'1''2016-05-16 17:17:24.000000''普通用户''USER''会员');  
  217. COMMIT;  
  218.   
  219. -- ----------------------------  
  220. --  Table structure for `t_user`  
  221. -- ----------------------------  
  222. DROP TABLE IF EXISTS `t_user`;  
  223. CREATE TABLE `t_user` (  
  224.   `id` bigint(20) NOT NULL AUTO_INCREMENT,  
  225.   `createTime` datetime(6) DEFAULT NULL,  
  226.   `enabled` bit(1) NOT NULL,  
  227.   `updateTime` datetime(6) DEFAULT NULL,  
  228.   `age` int(11) NOT NULL,  
  229.   `email` varchar(255) DEFAULT NULL,  
  230.   `passwordvarchar(30) NOT NULL,  
  231.   `phone` varchar(11) DEFAULT NULL,  
  232.   `username` varchar(30) NOT NULL,  
  233.   PRIMARY KEY (`id`),  
  234.   UNIQUE KEY `UK_jhib4legehrm4yscx9t3lirqi` (`username`),  
  235.   UNIQUE KEY `UK_i6qjjoe560mee5ajdg7v1o6mi` (`email`),  
  236.   UNIQUE KEY `UK_m5bu5erj83eubjsa1nyms0t89` (`phone`)  
  237. ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;  
  238.   
  239. -- ----------------------------  
  240. --  Records of `t_user`  
  241. -- ----------------------------  
  242. BEGIN;  
  243. INSERT INTO `t_user` VALUES ('1''2016-05-16 17:14:58.000000', b'1''2016-05-16 17:15:04.000000''23''[email protected]''tanghuan''18280206033''tanghuan'), ('2''2016-05-16 17:15:43.000000', b'1''2016-05-16 17:15:50.000000''22''[email protected]''xuran''12345678987''xuran');  
  244. COMMIT;  
  245.   
  246. -- ----------------------------  
  247. --  Table structure for `t_usergroup`  
  248. -- ----------------------------  
  249. DROP TABLE IF EXISTS `t_usergroup`;  
  250. CREATE TABLE `t_usergroup` (  
  251.   `id` bigint(20) NOT NULL AUTO_INCREMENT,  
  252.   `createTime` datetime(6) DEFAULT NULL,  
  253.   `enabled` bit(1) NOT NULL,  
  254.   `updateTime` datetime(6) DEFAULT NULL,  
  255.   `comment` varchar(255) DEFAULT NULL,  
  256.   `groupNum` varchar(255) NOT NULL,  
  257.   `namevarchar(255) NOT NULL,  
  258.   PRIMARY KEY (`id`),  
  259.   UNIQUE KEY `UK_daw8uwu1enonbvfjg2oau9gdm` (`groupNum`)  
  260. ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;  
  261.   
  262. -- ----------------------------  
  263. --  Records of `t_usergroup`  
  264. -- ----------------------------  
  265. BEGIN;  
  266. INSERT INTO `t_usergroup` VALUES ('1''2016-05-16 23:53:32.000000', b'1''2016-05-16 23:53:40.000000''管理员组''123456789''MANAGER_GROUP');  
  267. COMMIT;  
  268.   
  269. SET FOREIGN_KEY_CHECKS = 1;  

猜你喜欢

转载自blog.csdn.net/qq853632587/article/details/76532367