序: 
本文使用springboot+mybatis+SpringSecurity 实现数据库动态的管理用户、角色、权限管理

本文细分角色和权限,并将用户、角色、权限和资源均采用数据库存储,并且自定义滤器,代替原有的FilterSecurityInterceptor过滤器, 
并分别实现AccessDecisionManager、InvocationSecurityMetadataSourceService和UserDetailsService,并在配置文件中进行相应配置。

spring security的简单原理:

使用众多的拦截器对url拦截,以此来管理权限。但是这么多拦截器,笔者不可能对其一一来讲,主要讲里面核心流程的两个。

首先,权限管理离不开登陆验证的,所以登陆验证拦截器AuthenticationProcessingFilter要讲; 
还有就是对访问的资源管理吧,所以资源管理拦截器AbstractSecurityInterceptor要讲;

但拦截器里面的实现需要一些组件来实现,所以就有了AuthenticationManager、accessDecisionManager等组件来支撑。

现在先大概过一遍整个流程,用户登陆,会被AuthenticationProcessingFilter拦截,调用AuthenticationManager的实现,而且AuthenticationManager会调用ProviderManager来获取用户验证信息(不同的Provider调用的服务不同,因为这些信息可以是在数据库上,可以是在LDAP服务器上,可以是xml配置文件上等),如果验证通过后会将用户的权限信息封装一个User放到spring的全局缓存SecurityContextHolder中,以备后面访问资源时使用。 
访问资源(即授权管理),访问url时,会通过AbstractSecurityInterceptor拦截器拦截,其中会调用FilterInvocationSecurityMetadataSource的方法来获取被拦截url所需的全部权限,在调用授权管理器AccessDecisionManager,这个授权管理器会通过spring的全局缓存SecurityContextHolder获取用户的权限信息,还会获取被拦截的url和被拦截url所需的全部权限,然后根据所配的策略(有:一票决定,一票否定,少数服从多数等),如果权限足够,则返回,权限不够则报错并调用权限不足页面。


重要

本文设计和代码是基于 上一篇博客(请点击)

springboot+mybatis+SpringSecurity 实现用户角色数据库管理

进行修改。


本文目录: 
1:数据库表设计 
2:权限表的业务 
3:springSecurity 配置修改 
4:修改home.html 文件 
5:修改HomeController.java 文件 
6:测试检验

目录结构如下:


1:数据库表设计

由于本文增加了权限表所以本文的数据库表为5个分别是: 用户表、角色表、权限表、用户角色中间表、角色权限中间表

初始化数据

  1.  
    注意:Sys_permission 表的url通配符为两颗星,比如说 /user下的所有url,应该写成 /user/**;
  2.  
    权限的名字可以随意起名
    1. insert into SYS_USER (id,username, password) values (1,'admin', 'admin');
    2. insert into SYS_USER (id,username, password) values (2,'abel', 'abel');
    3.  
    4. insert into SYS_ROLE(id,name) values(1,'ROLE_ADMIN');
    5. insert into SYS_ROLE(id,name) values(2,'ROLE_USER');
    6.  
    7. insert into SYS_ROLE_USER(SYS_USER_ID,ROLES_ID) values(1,1);
    8. insert into SYS_ROLE_USER(SYS_USER_ID,ROLES_ID) values(2,2);
    9.  
    10. BEGIN;
    11. INSERT INTO `Sys_permission` VALUES ('1', 'ROLE_HOME', 'home', '/', null), ('2', 'ROLE_ADMIN', 'ABel', '/admin', null);
    12. COMMIT;
    13.  
    14. BEGIN;
    15. INSERT INTO `Sys_permission_role` VALUES ('1', '1', '1'), ('2', '1', '2'), ('3', '2', '1');
    16. COMMIT;

      

2:权限表的业务代码

2.1 java bean

Permission.java

    1. package com.us.example.domain;
    2.  
    3. /**
    4. * Created by yangyibo on 17/1/20.
    5. */
    6. public class Permission {
    7.  
    8. private int id;
    9. //权限名称
    10. private String name;
    11.  
    12. //权限描述
    13. private String descritpion;
    14.  
    15. //授权链接
    16. private String url;
    17.  
    18. //父节点id
    19. private int pid;
    20.  
    21. public int getId() {
    22. return id;
    23. }
    24.  
    25. public void setId(int id) {
    26. this.id = id;
    27. }
    28.  
    29. public String getName() {
    30. return name;
    31. }
    32.  
    33. public void setName(String name) {
    34. this.name = name;
    35. }
    36.  
    37. public String getDescritpion() {
    38. return descritpion;
    39. }
    40.  
    41. public void setDescritpion(String descritpion) {
    42. this.descritpion = descritpion;
    43. }
    44.  
    45. public String getUrl() {
    46. return url;
    47. }
    48.  
    49. public void setUrl(String url) {
    50. this.url = url;
    51. }
    52.  
    53. public int getPid() {
    54. return pid;
    55. }
    56.  
    57. public void setPid(int pid) {
    58. this.pid = pid;
    59. }
    60. }

      

2.2 dao 层

在 com.us.example.dao 包下新建PermissionDao.java 文件。

PermissionDao.java

    1. package com.us.example.dao;
    2. import com.us.example.config.MyBatisRepository;
    3. import com.us.example.domain.Permission;
    4. import java.util.List;
    5.  
    6. /**
    7. * Created by yangyibo on 17/1/20.
    8. */
    9. public interface PermissionDao {
    10. public List<Permission> findAll();
    11. public List<Permission> findByAdminUserId(int userId);
    12. }

      

在src/resource/mapper目录下新建对应的mapper.xml 文件

PermissionDaoMapper.xml

    1. <?xml version="1.0" encoding="UTF-8" ?>
    2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
    3. <mapper namespace="com.us.example.dao.PermissionDao">
    4. <select id="findAll" resultType="com.us.example.domain.Permission">
    5.  
    6. SELECT * from Sys_permission ;
    7. </select>
    8.  
    9. <select id="findByAdminUserId" parameterType="int" resultType="com.us.example.domain.Permission">
    10. select p.*
    11. from Sys_User u
    12. LEFT JOIN sys_role_user sru on u.id= sru.Sys_User_id
    13. LEFT JOIN Sys_Role r on sru.Sys_Role_id=r.id
    14. LEFT JOIN Sys_permission_role spr on spr.role_id=r.id
    15. LEFT JOIN Sys_permission p on p.id =spr.permission_id
    16. where u.id=#{userId}
    17. </select>
    18. </mapper>

3:springSecurity 配置修改

3.1 修改 WebSecurityConfig.java

修改com.us.example.config包下的 WebSecurityConfig.java 文件如下:

    1. package com.us.example.config;
    2.  
    3. import com.us.example.service.CustomUserService;
    4. import com.us.example.service.MyFilterSecurityInterceptor;
    5. import org.springframework.beans.factory.annotation.Autowired;
    6. import org.springframework.context.annotation.Bean;
    7. import org.springframework.context.annotation.Configuration;
    8. import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
    9. import org.springframework.security.config.annotation.web.builders.HttpSecurity;
    10. import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
    11. import org.springframework.security.core.userdetails.UserDetailsService;
    12. import org.springframework.security.web.access.intercept.FilterSecurityInterceptor;
    13.  
    14. /**
    15. * Created by yangyibo on 17/1/18.
    16. */
    17.  
    18. @Configuration
    19. @EnableWebSecurity
    20. public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
    21.  
    22. @Autowired
    23. private MyFilterSecurityInterceptor myFilterSecurityInterceptor;
    24.  
    25. @Bean
    26. UserDetailsService customUserService(){ //注册UserDetailsService 的bean
    27. return new CustomUserService();
    28. }
    29.  
    30. @Override
    31. protected void configure(AuthenticationManagerBuilder auth) throws Exception {
    32. auth.userDetailsService(customUserService()); //user Details Service验证
    33.  
    34. }
    35.  
    36. @Override
    37. protected void configure(HttpSecurity http) throws Exception {
    38. http.authorizeRequests()
    39. .anyRequest().authenticated() //任何请求,登录后可以访问
    40. .and()
    41. .formLogin()
    42. .loginPage("/login")
    43. .failureUrl("/login?error")
    44. .permitAll() //登录页面用户任意访问
    45. .and()
    46. .logout().permitAll(); //注销行为任意访问
    47. http.addFilterBefore(myFilterSecurityInterceptor, FilterSecurityInterceptor.class);
    48. }
    49. }

3.2 修改CustomUserService

修改CustomUserService.java 内容如下:

    1. package com.us.example.service;
    2.  
    3. import com.us.example.dao.PermissionDao;
    4. import com.us.example.dao.UserDao;
    5. import com.us.example.domain.Permission;
    6. import com.us.example.domain.SysRole;
    7. import com.us.example.domain.SysUser;
    8. import org.springframework.beans.factory.annotation.Autowired;
    9. import org.springframework.security.core.GrantedAuthority;
    10. import org.springframework.security.core.authority.SimpleGrantedAuthority;
    11. import org.springframework.security.core.userdetails.User;
    12. import org.springframework.security.core.userdetails.UserDetails;
    13. import org.springframework.security.core.userdetails.UserDetailsService;
    14. import org.springframework.security.core.userdetails.UsernameNotFoundException;
    15. import org.springframework.stereotype.Service;
    16.  
    17. import java.util.ArrayList;
    18. import java.util.List;
    19.  
    20. /**
    21. * Created by yangyibo on 17/1/18.
    22. */
    23. @Service
    24. public class CustomUserService implements UserDetailsService { //自定义UserDetailsService 接口
    25.  
    26. @Autowired
    27. UserDao userDao;
    28. @Autowired
    29. PermissionDao permissionDao;
    30.  
    31. public UserDetails loadUserByUsername(String username) {
    32. SysUser user = userDao.findByUserName(username);
    33. if (user != null) {
    34. List<Permission> permissions = permissionDao.findByAdminUserId(user.getId());
    35. List<GrantedAuthority> grantedAuthorities = new ArrayList <>();
    36. for (Permission permission : permissions) {
    37. if (permission != null && permission.getName()!=null) {
    38.  
    39. GrantedAuthority grantedAuthority = new SimpleGrantedAuthority(permission.getName());
    40. //1:此处将权限信息添加到 GrantedAuthority 对象中,在后面进行全权限验证时会使用GrantedAuthority 对象。
    41. grantedAuthorities.add(grantedAuthority);
    42. }
    43. }
    44. return new User(user.getUsername(), user.getPassword(), grantedAuthorities);
    45. } else {
    46. throw new UsernameNotFoundException("admin: " + username + " do not exist!");
    47. }
    48. }
    49.  
    50. }

      

3.3 新增MyAccessDecisionManager

在com.us.example.service 包下新增 
MyAccessDecisionManager.java 文件

    1. package com.us.example.service;
    2.  
    3. import org.springframework.security.access.AccessDecisionManager;
    4. import org.springframework.security.access.AccessDeniedException;
    5. import org.springframework.security.access.ConfigAttribute;
    6. import org.springframework.security.authentication.InsufficientAuthenticationException;
    7. import org.springframework.security.core.Authentication;
    8. import org.springframework.security.core.GrantedAuthority;
    9. import org.springframework.stereotype.Service;
    10.  
    11. import java.util.Collection;
    12. import java.util.Iterator;
    13.  
    14. /**
    15. * Created by yangyibo on 17/1/19.
    16. */
    17. @Service
    18. public class MyAccessDecisionManager implements AccessDecisionManager {
    19.  
    20. // decide 方法是判定是否拥有权限的决策方法,
    21. //authentication 是释CustomUserService中循环添加到 GrantedAuthority 对象中的权限信息集合.
    22. //object 包含客户端发起的请求的requset信息,可转换为 HttpServletRequest request = ((FilterInvocation) object).getHttpRequest();
    23. //configAttributes 为MyInvocationSecurityMetadataSource的getAttributes(Object object)这个方法返回的结果,此方法是为了判定用户请求的url 是否在权限表中,如果在权限表中,则返回给 decide 方法,用来判定用户是否有此权限。如果不在权限表中则放行。
    24. @Override
    25. public void decide(Authentication authentication, Object object, Collection<ConfigAttribute> configAttributes) throws AccessDeniedException, InsufficientAuthenticationException {
    26.  
    27. if(null== configAttributes || configAttributes.size() <=0) {
    28. return;
    29. }
    30. ConfigAttribute c;
    31. String needRole;
    32. for(Iterator<ConfigAttribute> iter = configAttributes.iterator(); iter.hasNext(); ) {
    33. c = iter.next();
    34. needRole = c.getAttribute();
    35. for(GrantedAuthority ga : authentication.getAuthorities()) {//authentication 为在注释1 中循环添加到 GrantedAuthority 对象中的权限信息集合
    36. if(needRole.trim().equals(ga.getAuthority())) {
    37. return;
    38. }
    39. }
    40. }
    41. throw new AccessDeniedException("no right");
    42. }
    43.  
    44. @Override
    45. public boolean supports(ConfigAttribute attribute) {
    46. return true;
    47. }
    48.  
    49. @Override
    50. public boolean supports(Class<?> clazz) {
    51. return true;
    52. }
    53. }

3.4 新增 MyFilterSecurityInterceptor

在com.us.example.service 包下新增 
MyFilterSecurityInterceptor.java 文件

    1. package com.us.example.service;
    2. import javax.servlet.Filter;
    3. import javax.servlet.FilterChain;
    4. import javax.servlet.FilterConfig;
    5. import javax.servlet.ServletException;
    6. import javax.servlet.ServletRequest;
    7. import javax.servlet.ServletResponse;
    8. import org.springframework.beans.factory.annotation.Autowired;
    9. import org.springframework.security.access.SecurityMetadataSource;
    10. import org.springframework.security.access.intercept.AbstractSecurityInterceptor;
    11. import org.springframework.security.access.intercept.InterceptorStatusToken;
    12. import org.springframework.security.web.FilterInvocation;
    13. import org.springframework.security.web.access.intercept.FilterInvocationSecurityMetadataSource;
    14. import org.springframework.stereotype.Service;
    15.  
    16. import java.io.IOException;
    17.  
    18. /**
    19. * Created by yangyibo on 17/1/19.
    20. */
    21. @Service
    22. public class MyFilterSecurityInterceptor extends AbstractSecurityInterceptor implements Filter {
    23.  
    24. @Autowired
    25. private FilterInvocationSecurityMetadataSource securityMetadataSource;
    26.  
    27. @Autowired
    28. public void setMyAccessDecisionManager(MyAccessDecisionManager myAccessDecisionManager) {
    29. super.setAccessDecisionManager(myAccessDecisionManager);
    30. }
    31.  
    32. @Override
    33. public void init(FilterConfig filterConfig) throws ServletException {
    34.  
    35. }
    36.  
    37. @Override
    38. public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
    39.  
    40. FilterInvocation fi = new FilterInvocation(request, response, chain);
    41. invoke(fi);
    42. }
    43.  
    44. public void invoke(FilterInvocation fi) throws IOException, ServletException {
    45. //fi里面有一个被拦截的url
    46. //里面调用MyInvocationSecurityMetadataSource的getAttributes(Object object)这个方法获取fi对应的所有权限
    47. //再调用MyAccessDecisionManager的decide方法来校验用户的权限是否足够
    48. InterceptorStatusToken token = super.beforeInvocation(fi);
    49. try {
    50. //执行下一个拦截器
    51. fi.getChain().doFilter(fi.getRequest(), fi.getResponse());
    52. } finally {
    53. super.afterInvocation(token, null);
    54. }
    55. }
    56.  
    57. @Override
    58. public void destroy() {
    59.  
    60. }
    61.  
    62. @Override
    63. public Class<?> getSecureObjectClass() {
    64. return FilterInvocation.class;
    65. }
    66.  
    67. @Override
    68. public SecurityMetadataSource obtainSecurityMetadataSource() {
    69. return this.securityMetadataSource;
    70. }
    71. }

3.5 新增 MyInvocationSecurityMetadataSourceService

在com.us.example.service 包下新增MyInvocationSecurityMetadataSourceService.java文件

    1. package com.us.example.service;
    2.  
    3. import com.us.example.dao.PermissionDao;
    4. import com.us.example.domain.Permission;
    5. import org.springframework.beans.factory.annotation.Autowired;
    6. import org.springframework.security.access.ConfigAttribute;
    7. import org.springframework.security.access.SecurityConfig;
    8. import org.springframework.security.web.FilterInvocation;
    9. import org.springframework.security.web.access.intercept.FilterInvocationSecurityMetadataSource;
    10. import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
    11. import org.springframework.stereotype.Service;
    12.  
    13. import javax.servlet.http.HttpServletRequest;
    14. import java.util.*;
    15.  
    16. /**
    17. * Created by yangyibo on 17/1/19.
    18. */
    19. @Service
    20. public class MyInvocationSecurityMetadataSourceService implements
    21. FilterInvocationSecurityMetadataSource {
    22.  
    23. @Autowired
    24. private PermissionDao permissionDao;
    25.  
    26. private HashMap<String, Collection<ConfigAttribute>> map =null;
    27.  
    28. /**
    29. * 加载权限表中所有权限
    30. */
    31. public void loadResourceDefine(){
    32. map = new HashMap<>();
    33. Collection<ConfigAttribute> array;
    34. ConfigAttribute cfg;
    35. List<Permission> permissions = permissionDao.findAll();
    36. for(Permission permission : permissions) {
    37. array = new ArrayList<>();
    38. cfg = new SecurityConfig(permission.getName());
    39. //此处只添加了用户的名字,其实还可以添加更多权限的信息,例如请求方法到ConfigAttribute的集合中去。此处添加的信息将会作为MyAccessDecisionManager类的decide的第三个参数。
    40. array.add(cfg);
    41. //用权限的getUrl() 作为map的key,用ConfigAttribute的集合作为 value,
    42. map.put(permission.getUrl(), array);
    43. }
    44.  
    45. }
    46.  
    47. //此方法是为了判定用户请求的url 是否在权限表中,如果在权限表中,则返回给 decide 方法,用来判定用户是否有此权限。如果不在权限表中则放行。
    48. @Override
    49. public Collection<ConfigAttribute> getAttributes(Object object) throws IllegalArgumentException {
    50. if(map ==null) loadResourceDefine();
    51. //object 中包含用户请求的request 信息
    52. HttpServletRequest request = ((FilterInvocation) object).getHttpRequest();
    53. AntPathRequestMatcher matcher;
    54. String resUrl;
    55. for(Iterator<String> iter = map.keySet().iterator(); iter.hasNext(); ) {
    56. resUrl = iter.next();
    57. matcher = new AntPathRequestMatcher(resUrl);
    58. if(matcher.matches(request)) {
    59. return map.get(resUrl);
    60. }
    61. }
    62. return null;
    63. }
    64.  
    65. @Override
    66. public Collection<ConfigAttribute> getAllConfigAttributes() {
    67. return null;
    68. }
    69.  
    70. @Override
    71. public boolean supports(Class<?> clazz) {
    72. return true;
    73. }
    74. }

4:修改home.html 文件

修改src/resources/templates目录下 的home.html

    1. <!DOCTYPE html>
    2. <html xmlns:th="http://www.thymeleaf.org"
    3. xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity4">
    4. <head>
    5. <meta content="text/html;charset=UTF-8"/>
    6. <title sec:authentication="name"></title>
    7. <link rel="stylesheet" th:href="@{css/bootstrap.min.css}" />
    8. <style type="text/css">
    9. body {
    10. padding-top: 50px;
    11. }
    12. .starter-template {
    13. padding: 40px 15px;
    14. text-align: center;
    15. }
    16. </style>
    17. </head>
    18. <body>
    19. <nav class="navbar navbar-inverse navbar-fixed-top">
    20. <div class="container">
    21. <div class="navbar-header">
    22. <a class="navbar-brand" href="#">Spring Security演示</a>
    23. </div>
    24. <div id="navbar" class="collapse navbar-collapse">
    25. <ul class="nav navbar-nav">
    26. <li><a th:href="@{/}"> 首页 </a></li>
    27. <li><a th:href="@{/admin}"> admin </a></li>
    28. </ul>
    29. </div><!--/.nav-collapse -->
    30. </div>
    31. </nav>
    32.  
    33. <div class="container">
    34.  
    35. <div class="starter-template">
    36. <h1 th:text="${msg.title}"></h1>
    37.  
    38. <p class="bg-primary" th:text="${msg.content}"></p>
    39.  
    40. <div sec:authorize="hasRole('ROLE_HOME')"> <!-- 用户类型为ROLE_ADMIN 显示 -->
    41. <p class="bg-info" th:text="${msg.etraInfo}"></p>
    42. </div>
    43. <div sec:authorize="hasRole('ROLE_ADMIN')"> <!-- 用户类型为ROLE_ADMIN 显示 -->
    44. <p class="bg-info">恭喜您,您有 ROLE_ADMIN 权限 </p>
    45. </div>
    46.  
    47. <form th:action="@{/logout}" method="post">
    48. <input type="submit" class="btn btn-primary" value="注销"/>
    49. </form>
    50. </div>
    51.  
    52. </div>
    53.  
    54. </body>
    55. </html>

5:修改HomeController.java 文件

    1. package com.us.example.controller;
    2.  
    3. import com.us.example.domain.Msg;
    4. import org.springframework.stereotype.Controller;
    5. import org.springframework.ui.Model;
    6. import org.springframework.web.bind.annotation.RequestMapping;
    7. import org.springframework.web.bind.annotation.ResponseBody;
    8.  
    9. /**
    10. * Created by yangyibo on 17/1/18.
    11. */
    12. @Controller
    13. public class HomeController {
    14.  
    15. @RequestMapping("/")
    16. public String index(Model model){
    17. Msg msg = new Msg("测试标题","测试内容","欢迎来到HOME页面,您拥有 ROLE_HOME 权限");
    18. model.addAttribute("msg", msg);
    19. return "home";
    20. }
    21. @RequestMapping("/admin")
    22. @ResponseBody
    23. public String hello(){
    24. return "hello admin";
    25. }
    26. }

6.测试检验

启动访问 http://localhost:8080/ 到登录页面

  1.  
    由于数据库的配置 admin 用户拥有 访问 home和admin 页面的权限。
  2.  
    abel 用户只有访问 home 的权限
  • 1
  • 2
  • 3

使用admin 登录

点击 admin 按钮 会反回结果 “hello admin“

使用abel 用户登录 点击 点击 admin 按钮 页面会报403

源码地址:https://github.com/527515025/springBoot

参考资料: 
http://www.tuicool.com/articles/jq6fuur#c-23220 
http://blog.csdn.net/u012367513/article/details/38866465

springBoot+springSecurity 数据库动态管理用户、角色、权限(二)的更多相关文章

  1. springBoot+springSecurity 数据库动态管理用户、角色、权限

    使用spring Security3的四种方法概述 那么在Spring Security3的使用中,有4种方法: 一种是全部利用配置文件,将用户.权限.资源(url)硬编码在xml文件中,已经实现过, ...

  2. SpringBoot学习- 10、设计用户角色权限表

    SpringBoot学习足迹 前几节已经基本了解了SpringBoot框架常用的技术,其他的消息队列,定时器等技术暂时用不到,真正项目中如果基于微信系,阿里系开发的话,还要了解平台专用的技术知识,学习 ...

  3. [.Net MVC] 用户角色权限管理_使用CLK.AspNet.Identity

    项目:后台管理平台 意义:一个完整的管理平台需要提供用户注册.登录等功能,以及认证和授权功能. 一.为何使用CLK.AspNet.Identity 首先简要说明所采取的权限控制方式.这里采用了基于角色 ...

  4. ASP.NET MVC+EF框架+EasyUI实现权限管理系列(21)-用户角色权限基本的实现说明

    原文:ASP.NET MVC+EF框架+EasyUI实现权限管理系列(21)-用户角色权限基本的实现说明     ASP.NET MVC+EF框架+EasyUI实现权限管系列 (开篇)   (1):框 ...

  5. java权限管理与用户角色权限设计

    java权限管理与用户角色权限设计 实现业务系统中的用户权限管理 B/S系统中的权限比C/S中的更显的重要,C/S系统因为具有特殊的客户端,所以访问用户的权限检测可以通过客户端实现或通过客户端+服务器 ...

  6. Asp.Net MVC+BootStrap+EF6.0实现简单的用户角色权限管理

    这是本人第一次写,写的不好的地方还忘包含.写这个的主要原因是想通过这个来学习下EF的CodeFirst模式,本来也想用AngularJs来玩玩的,但是自己只会普通的绑定,对指令这些不是很熟悉,所以就基 ...

  7. Asp.Net MVC+BootStrap+EF6.0实现简单的用户角色权限管理10

    今天把用户的菜单显示和页面的按钮显示都做好了,下面先来个效果图 接下来说下我实现的方法: 首先我在每个方法前面都加了这个属性, /// <summary> /// 表示当前Action请求 ...

  8. spring-boot-plus V1.4.0发布 集成用户角色权限部门管理

    RBAC用户角色权限 用户角色权限部门管理核心接口介绍 Shiro权限配置

  9. spring security中动态更新用户的权限

    在程序的执行过程中,有时有这么一种需求,需要动态的更新某些角色的权限或某些人对应的权限,当前在线的用户拥有这个角色或拥有这个权限时,在不退出系统的情况下,需要动态的改变的他所拥有的权限. 需求:张三 ...

随机推荐

  1. 在vue中使用async/await遇到的坑

    最近无聊在搞一些新的东西,今天就遇到一个async/await的坑: 因为我用的不是vue官方的脚手架,所以遇到这样的问题: await is a reserved word 这样的警告,我猜应该是缺 ...

  2. php文件上传错误信息说明对照表

    php文件上传错误信息说明对照表: UPLOAD_ERR_OK:其值为0,没有错误发生,文件上传成功UPLOAD_ERR_INI_SIZE:其值为1,上传的文件超过了php.ini中upload_ma ...

  3. event.target和event.currentTarget的区别----0605加深理解

    target:触发事件的元素.currentTarget:事件绑定的元素.两者在没有冒泡的情况下,是一样的值,但在用了事件委托的情况下,就不一样了,例如: <ul id="ulT&qu ...

  4. 如何在一个线程环境中使用一个线程非安全的java类

    在开发过程中 当我们拿到一个线程非安全的java类的时候,我们可以额外创建这个类的管理类 并在管理类中控制同步 比如 一个非线程安全的Pair类 package test.thread.sx.test ...

  5. 使用elasticdump导入导出数据

    一.安装elasticdump 终端中输入 npm install elasticdump -g -g表示全局可用,直接在终端输入 elasticdump --version,出现版本信息即表示安装成 ...

  6. 使用svn未响应卡死的几个原因,commit时checkout时

    1.commit 时 很可能是:检索文件内容过多导致,解决:不要在最外层文件夹目录下commit 2.checkout时 很可能是:地址错误

  7. mysql注入大全及防御

    0.明白存在的位置:get型 post型 cookie型 http头注入 1.先测试注入点,注册框.搜索框.地址栏啥的,判断是字符型,搜索型还是数字型 字符型 1' and '1'='1 成功, 1' ...

  8. laravel5.8 Auth::guide

    // 使用下面这个命令Laravel会自动为我们生成Auth路由和认证模块.跟着代码往下解读. php artisan make:auth // Http/Controllers/Auth/Login ...

  9. 搭建docker+k8s踩过的坑

    问题一: # yum install -y etcd kubernetes Error: docker-ce-cli conflicts with :docker--.gitb2f74b2.el7.c ...

  10. Linux学习--第十三天--日志、系统运行级别、grub加密

    日志 rsyslogd取代了syslogd. /var/log/cron #定时任务相关日志 /var/log/cups #打印信息相关日志 /var/log/dmesg #开机内核自检相关日志,dm ...