使用hasRole

class Grant implements GrantedAuthority{

        @Override
public String getAuthority() {
return "ROLE_ADMIN";
}
}
@Override
public Collection<? extends GrantedAuthority> getAuthorities() { List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
authorities.add(new Grant());
return authorities;
}

匹配

.antMatchers("/hotel/**").access("hasRole('ADMIN')")

使用hasAnyAuthority

class Grant implements GrantedAuthority{

        @Override
public String getAuthority() {
return "ADMIN";
}
}
@Override
public Collection<? extends GrantedAuthority> getAuthorities() { List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
authorities.add(new Grant());
return authorities;
}

匹配

.antMatchers("/hotel/**").access("hasAnyAuthority('ADMIN')")

使用scope

{
"access_token": "3e261513-943c-497e-95b8-703ba96101ed",
"token_type": "bearer",
"expires_in": 199,
"scope": "write resource-server-read"
}

匹配

.antMatchers("/hotel/**").access("#oauth2.hasScope('resource-server-read')")

使用resource id

client中的 resource id信息

匹配

@Override
public void configure(ResourceServerSecurityConfigurer resources) {
// @formatter:off
resources
.resourceId("resource");
// @formatter:on
}

总结 ROLE 和 authority 是用户 自己的属性

scope 是 client的属性

参考

https://stackoverflow.com/questions/19525380/difference-between-role-and-grantedauthority-in-spring-security

spring oauth Role and Authority and scope的更多相关文章

  1. Spring boot --- Spring Oauth(一)

       文章部分图片来自参考资料,这篇文章主要讲 spring security  oauth 概述 上一篇我们学习了 SS 中重要的工作原理和几个大概的认证和授权过程.而 spring securit ...

  2. spring mvc 的Controller类默认Scope是单例(singleton)的

    使用Spring MVC有一段时间了,之前一直使用Struts2,在struts2中action都是原型(prototype)的, 说是因为线程安全问题,对于Spring MVC中bean默认都是(s ...

  3. Spring学习(二):Spring支持的5种Bean Scope

    序言 Scope是定义Spring如何创建bean的实例的.Spring容器最初提供了两种bean的scope类型:singleton和prototype,但发布2.0以后,又引入了另外三种scope ...

  4. spring中的bean的属性scope

    spring中bean的scope属性,有如下5种类型: singleton 表示在spring容器中的单例,通过spring容器获得该bean时总是返回唯一的实例 prototype表示每次获得be ...

  5. Spring boot --- Spring Oauth(三)

    本节将学习 spring security oauth  实现单点登录 概述 首先我们来了解什么是单点登录.看下面两张图就明白了. 很明显,单点登录最重要解决的就是登录和注销的功能,今天的例子,可以用 ...

  6. Spring配置文件中<bean>标签的scope属性

    转自:https://fj-sh-chz.iteye.com/blog/1775149 singleton  (默认属性) Spring将Bean放入Spring IOC容器的缓存池中,并将Bean引 ...

  7. (三)Spring 高级装配 bean的作用域@Scope

    1.默认情况下,spring通过@Autowared注入的bean是单例的bean,但有些情况是不满足的,例如:购物车,每个会话,或每个用户登录使用的购物车都是独立的 spring的定义的作用域: a ...

  8. 【Spring】bean的作用域(@Scope) - singleton、prototype

    已知spring 3+已拥有多种不同的作用域: singleton(默认).prototype.request.session.global session.(参考: spring中scope作用域( ...

  9. 【Spring注解驱动开发】使用@Scope注解设置组件的作用域

    写在前面 Spring容器中的组件默认是单例的,在Spring启动时就会实例化并初始化这些对象,将其放到Spring容器中,之后,每次获取对象时,直接从Spring容器中获取,而不再创建对象.如果每次 ...

随机推荐

  1. ZooKeeper服务器是用Java创建的,它在JVM上运行。

    ZooKeeper服务器是用Java创建的,它在JVM上运行. 创建配置文件 使用命令 vi conf/zoo.cfg 和所有以下参数设置为起点,打开名为 conf/zoo.cfg 的配置文件. $ ...

  2. [SpringMVC+redis]自定义aop注解实现控制器访问次数限制

    原文:http://www.cnblogs.com/xiaoyangjia/p/3762150.html?utm_source=tuicool 我们需要根据IP去限制用户单位时间的访问次数,防止刷手机 ...

  3. nagios学习记录

    这几天开始接触nagios,记录下学习的心得 监控机上需要安装nagios,nagios-plugins, nrpe 被监控机上需要安装nagios-plugins, nrpe nagios通过插件n ...

  4. [转载] 在Linux中,开机自动运行普通用户的脚本程序

    FROM:http://blog.csdn.net/sinboy/article/details/2466225 FROM:http://www.2cto.com/os/201006/50680.ht ...

  5. 【招聘App】—— React/Nodejs/MongoDB全栈项目:socket.io&聊天实现

    前言:最近在学习Redux+react+Router+Nodejs全栈开发高级课程,这里对实践过程作个记录,方便自己和大家翻阅.最终成果github地址:https://github.com/66We ...

  6. 9.11排序与查找(三)——给定一个排序后的数组,包括n个整数,但这个数组已被旋转过多次,找出数组中的某个元素

    /**  * 功能:给定一个排序后的数组.包括n个整数.但这个数组已被旋转过多次,次数不详.找出数组中的某个元素.  * 能够假定数组元素原先是按从小到大的顺序排列的.  */ /** * 思路:数组 ...

  7. javascript - 你不容错过的es6模板写法

    /** * ``即重音符(128键盘左上角ESC下面那个键盘) * 隶属:模板字符串 */ let unit = '4'; let keywords = 'uc'; // step1:模板变量 ${v ...

  8. CentOS最常用命令

    快捷键.常用命令: 文件和目录:# cd /home 进入 '/home' 目录# cd .. 返回上一级目录# cd ../.. 返回上两级目录# cd - 返回上次所在目录# cp file1 f ...

  9. Spring 注入简介

    注入方式有三种,setter,构造方法,接口注入.   常用的是setter注入和构造方法注入.   setter注入: <?xml version="1.0" encodi ...

  10. 用JDOM读取XML文件

    用JDOM读取XML文件需先用org.jdom.input.SAXBuilder对象的build()方法创建Document对象,然后用Document类.Element类等的方法读取所需的内容.IB ...