spring security 注解@EnableGlobalMethodSecurity详解
1、Spring Security默认是禁用注解的,要想开启注解,需要在继承WebSecurityConfigurerAdapter的类上加@EnableGlobalMethodSecurity注解,来判断用户对某个控制层的方法是否具有访问权限
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class OAuth2SecurityConfiguration extends WebSecurityConfigurerAdapter {
...........................
}
2、例如下面代码就表示如果用户具有admin角色,就能访问listAllUsers方法,但是如果方法前不加@preAuthorize注解,意味着所有用户都能访问listAllUsers
方法
@PreAuthorize("hasRole('admin')")
@RequestMapping(value = "/user/", method = RequestMethod.GET)
@ResponseBody
public List<User> listAllUsers() {
List<User> users = userService.findAll();
if(users.isEmpty()){
return null;
}
return users;
}
3、@EnableGlobalMethodSecurity详解
3.1、@EnableGlobalMethodSecurity(securedEnabled=true)
开启@Secured 注解过滤权限
3.2、@EnableGlobalMethodSecurity(jsr250Enabled=true)
开启@RolesAllowed 注解过滤权限
3.3、@EnableGlobalMethodSecurity(prePostEnabled=true)
使用表达式时间方法级别的安全性 4个注解可用
- @PreAuthorize 在方法调用之前,基于表达式的计算结果来限制对方法的访问
- @PostAuthorize 允许方法调用,但是如果表达式计算结果为false,将抛出一个安全性异常
- @PostFilter 允许方法调用,但必须按照表达式来过滤方法的结果
- @PreFilter 允许方法调用,但必须在进入方法之前过滤输入值
spring security 注解@EnableGlobalMethodSecurity详解的更多相关文章
- spring IOC注解方式详解
本文分为三个部分:概述.使用注解进行属性注入.使用注解进行Bean的自动定义. 一,概述 注释配置相对于 XML 配置具有很多的优势: 它可以充分利用 Java 的反射机制获取类结构信息,这些信息可以 ...
- spring @Transactional注解参数详解
事物注解方式: @Transactional 当标于类前时, 标示类中所有方法都进行事物处理 , 例子: @Transactional public class TestServiceBean imp ...
- spring @Transactional注解参数详解(转载)
事物注解方式: @Transactional 当标于类前时, 标示类中所有方法都进行事物处理 , 例子: 1 @Transactional public class TestServiceBean i ...
- spring @Transactional注解参数详解(13)
事物注解方式: @Transactional 当标于类前时, 标示类中所有方法都进行事物处理 , 例子: 1 @Transactional public class TestServiceBean i ...
- spring @Scheduled注解 定时任务 详解
scheduled的使用注解的方式进行调度 先要配置spring.xml xmlns:task="http://www.springframework.org/schema/task&quo ...
- spring security xml配置详解
security 3.x <?xml version="1.0" encoding="UTF-8"?> <beans:beans xmlns= ...
- Spring MVC 注解开发详解
@Controller控制器定义 1.Controller是单利模式,被多个线程请求共享,因此设计成无序状态. 2.通过@controller标注即可将class定义为一个controller类.为使 ...
- Spring 注解@Value详解
一.spring(基础10) 注解@Value详解[1] 一 配置方式 @value需要参数,这里参数可以是两种形式: [html] view plain copy @Value("#{co ...
- 转:springmvc常用注解标签详解
Spring5:@Autowired注解.@Resource注解和@Service注解 - IT·达人 - 博客园--这篇顺序渐进,讲得超级好--此人博客很不错http://www.cnblogs.c ...
随机推荐
- SDL相关学习
原文地址:https://www.cnblogs.com/landmark/category/311822.html 介绍SDL图形库的使用 SDL显示文字 摘要: 前面教程里,我们只显示图片,没提到 ...
- php性能分析工具xhprof
安装方法: wget http://pecl.php.net/get/xhprof-0.9.x.tgz cp xhprof-0.9.x.tgz /home/www/xhprof.tgz tar zxv ...
- sqlserver 在尝试加载程序集 ID 65537 时 Microsoft .NET Framework 出错.服务器可能资源不足
报错信息: 处理报表时出错. 对数据集“query”执行查询失败. 在尝试加载程序集 ID 65536 时 Microsoft .NET Framework 出错.服务器可能资源不足,或者不信任该程序 ...
- 如何给mysql用户分配权限
1,Mysql下创建新的用户 语法: 1.create user 用户名 identified by '密码'; 例:create user xiaogang identified by '12345 ...
- 《跟老男孩学Linux运维:Web集群实战》读书笔记
Linux 介绍 Linux 安装 Linux 调优 Web 基础 Nginx 应用 LNMP 应用 PHP 缓存加速 Nginx 调优 MySQL 应用 NFS 网络文件共享 Nginx 反向代理与 ...
- IRGAN:A Minimax Game for Unifying Generative and Discriminative Information Retrieval Models
https://arxiv.org/pdf/1705.10513.pdf 论文阅读笔记: https://www.cnblogs.com/liaohuiqiang/p/9694277.html htt ...
- python selenium 使用unittest 示例
python selenium 使用unittest 示例 并等待某个元素示例 from selenium.webdriver.support.ui import WebDriverWait from ...
- CentOS 7 设置iptables防火墙开放proftpd端口
由于ftp的被动模式是这样的,客户端跟服务器端的21号端口交互信令,服务器端开启21号端口能够使客户端登录以及查看目录.但是ftp被动模式用于传输数据的端口却不是21,而是大于1024的随机或配置文件 ...
- grub配置指南
GRUB(统一引导装入器)是基本的Linux引导装入器.其有四个作用,如下:1.选择操作系统(如果计算机上安装了多个操作系统).2.表示相应引导文件所在的分区.3.找到内核.4.运行初始内存盘,设置内 ...
- 在 Visual Studio 2017 中找回消失的“在浏览器中查看”命令
不知为何,在新安装 Visual Studio 2017 后,发现所有 Web 项目上右键菜单的"在浏览器中查看"命令消失了,只能以调试模式启动网站,非常别扭. 最后在 Stack ...