使用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. Java使用纯真IP库获取IP对应省份和城市

    原文:http://blog.csdn.net/chwshuang/article/details/78027873?locationNum=10&fps=1 Java使用纯真IP库获取IP对 ...

  2. [Linux] ubuntu 格式化u盘

    $sudo fdisks -l 基本功,格式化命令,以格式化 /dev/sdb4 分区为例:$ sudo umount /dev/sdb4    # 必须先卸载该分区 # 格式化为 FAT 分区$ s ...

  3. IE11快捷键 双击没反应的解决办法

    WIN + R,regedit,找到 HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main 对左侧树Main节点右键——权限. 正常情 ...

  4. win 8 远程桌面文件复制问题(图)

    用win7连接远程桌面.能够非常方便的在宿主机之间文件复制粘贴. 但用win8.1远程连接桌面时,却发现不能拷贝文件了.查看网上资料,最后总结实现此步骤例如以下: win+R,执行mstsc.例如以下 ...

  5. 利用Bootstrap制作一个流行的网页

    首先是html承载内容: <!DOCTYPE html> <html lang="zh_CN"> <head> <meta charset ...

  6. 在LoadRunner脚本中实现随机ThinkTime

    一般情况下,我们都是通过Run-Time Settings来设置Think Time(思考时间),可以设置回放脚本时忽略思考时间,或者是设置回放随机的一段思考时间. By default, when ...

  7. STM32f103按键检测程序实现长按短按

    背景 只要使用单片机,按键检测基本上是一定要实现的功能.按键检测要好用,最重要的是实时和去抖.初学者往往会在主循环调用按键检测程序(实时)并利用延时去抖(准确).这种在主循环内延时的做法对整个程序非常 ...

  8. oracle闪回某个时间段的数据

    闪回2013-08-08 08:08:08的数据: insert into  table_1   select * from table_2 as of timestamp to_date('2013 ...

  9. 《DirectX 9.0 3D游戏开发编程基础》 第二章 绘制流水线 读书笔记

    模型的表示 场景:物品或模型的集合 任何物品都可以用三角形网络逼近表示.我们经常用以下术语描述三角形网络:多边形(polygons).图元(primitives).网络几何单元(mesh geomet ...

  10. 用JS将json日期格式化成正常日期

       function ChangeDateFormat(cellval) {             var date = new Date(parseInt(cellval.replace(&qu ...