接上文

springboot+springsecurity+mybatis plus之用户授权


一、@Secured

需要在类上开启该注解 @EnableGlobalMethodSecurity(securedEnabled = true)

@RestController
@RequestMapping("/test")
@EnableGlobalMethodSecurity(securedEnabled = true, prePostEnabled = true)
public class SecurityController { @GetMapping("/add")
@Secured({"ROLE_user","ROLE_admin"})
public String add() {
return "add merchandise";
}
}


该角色没有ROLE_user或者ROLE_admin权限,所以无法访问该方法

二、@PreAuthority

实现该注解需要在类上加入

@EnableGlobalMethodSecurity( prePostEnabled = true)

@RestController
@RequestMapping("/test")
@EnableGlobalMethodSecurity( prePostEnabled = true)
public class SecurityController { @GetMapping("/add")
@PreAuthorize("hasAuthority('admin')")
public String add() {
return "add";
} }


由于有该admin权限,所以可以猜到结果为add


三、@PostAuthorize

同样需要在类上加入

@EnableGlobalMethodSecurity(prePostEnabled = true)

这个注解会在方法执行之后进行权限判断

@RestController
@RequestMapping("/test")
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class SecurityController { @GetMapping("/update")
@PostAuthorize("hasAnyAuthority('user')")
public String update() {
System.out.println("update方法已经执行!");
return "update";
}
}

springboot+springsecurity+mybatis plus注解实现对方法的权限处理的更多相关文章

  1. SpringBoot Mybatis整合(注解版),SpringBoot集成Mybatis(注解版)

    SpringBoot Mybatis整合(注解版),SpringBoot集成Mybatis(注解版) ================================ ©Copyright 蕃薯耀 2 ...

  2. SpringBoot整合Mybatis关于分页查询的方法

    最近公司在用到SpringBoot整合Mybatis时当web端页面数据增多时需要使用分页查询以方便来展示数据.本人对分页查询进行了一些步骤的总结,希望能够帮助到有需要的博友.如有更好的方式,也希望评 ...

  3. SpringBoot整合Mybatis使用注解或XML的方式开发

    2018-6-4 补充mybatis-spring-boot注解的使用 1.导包 只需要再导入mysql+mybatis两个包 <dependency> <groupId>or ...

  4. springboot+springsecurity+mybatis plus之用户授权

    文章目录 前言 一.导入坐标 二.Users实体类及其数据库表的创建 三.controller,service,mapper层的实现 四.核心--编写配置文件 五.无权限界面和登录界面的实现 前言 即 ...

  5. springboot+springsecurity+mybatis plus之用户认证

    一.权限管理的概念 另一个安全框架shiro:shiro之权限管理的描述 导入常用坐标 <dependency> <groupId>org.springframework.bo ...

  6. springboot整合mybatis之注解方式

    1. 创建maven项目,工程目录如下图 2. 在pom.xml文件中添加mybatis依赖. 3. 创建实体类,并生成construct方法,getter和setter方法.同时在数据库中创建对应的 ...

  7. 基于SpringBoot+SpringSecurity+mybatis+layui实现的一款权限系统

    这是一款适合初学者学习权限以及springBoot开发,mybatis综合操作的后台权限管理系统 其中设计到的数据查询有一对一,一对多,多对多,联合分步查询,充分利用mybatis的强大实现各种操作, ...

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

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

  9. springBoot+springSecurity 数据库动态管理用户、角色、权限(二)

    序: 本文使用springboot+mybatis+SpringSecurity 实现数据库动态的管理用户.角色.权限管理 本文细分角色和权限,并将用户.角色.权限和资源均采用数据库存储,并且自定义滤 ...

随机推荐

  1. 基于jsp的百度Ueditor插件的使用

    初次使用百度的富文本编辑器Ueditor,写下使用经验以备不时之需 只是简单的应用,如有错误,请指正 首先去下载编辑器插件http://ueditor.baidu.com/website/downlo ...

  2. yum源出现 AppStream‘ 缓存失败,忽略这个 repo。同步仓库 ‘base‘ 缓存失败,忽略这个 repo 的问题解决办法

    今天安装Wget时出现如下错误 到 /etc/yum.repos.d/目录下编辑CentOS-Base.repo ,更改为如下内容. vim CentOS-Base.repo # CentOS-Bas ...

  3. Net中异步

    同步和异步1.同步是指只启动一个线程2.异步是指同时启动多个线程3.同步方法会卡界面,异步方法不会卡界面 原因:异步方法启动了子线程执行任务,主线程得到释放4.同步方法会慢.异步方法会快 原因:异步启 ...

  4. springcloud报错-------关于 hystrix 的异常 FallbackDefinitionException:fallback method wasn't found

    典型如下 第一种import java.util.List;@RestController@RequestMapping("/order")@DefaultProperties(d ...

  5. Mariadb开启密码复杂度

    mariadb开启密码复杂度 #安装插件# INSTALL SONAME 'simple_password_check'; #设置输入错误多少次锁定# set global max_password_ ...

  6. zookeeper可视化WEB工具(zkui)搭建与配置

    前提:zookeeper 可视化WEB工具zkui依赖java环境,因此需要安装jdk,同时zkui源码要Maven编译,需要安装apache-maven. JDK下载地址:https://www.o ...

  7. [SHA2017](web) writeup

    [SHA2017](web) writeup Bon Appétit (100) 打开页面查看源代码,发现如下 自然而然想到php伪协议,有个坑,看不了index.php,只能看 .htaccess ...

  8. MindSpore尝鲜之Vmap功能

    技术背景 Vmap是一种在python里面经常提到的向量化运算的功能,比如之前大家常用的就是numba和jax中的向量化运算的接口.虽然numpy中也使用到了向量化的运算,比如计算两个numpy数组的 ...

  9. 半吊子菜鸟学Web开发 -- PHP学习 4 --异常

    PHP异常处理 1 抛出一个异常 与Python的try except类似,PHP用try catch来捕获异常 基本语法 try{ //可能出现错误或异常的代码 //catch表示捕获,Except ...

  10. Anonymous Inner Class(匿名内部类)是否可以继承其它类?是否可以实现接口?

    可以继承其他类或实现其他接口,在 Swing 编程和 Android 开发中常用此方式来 实现事件监听和回调.