使用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. Git学习笔记(一) 安装及版本库介绍

    安装Git 最早Git是在Linux上开发的,很长一段时间内,Git也只能在Linux和Unix系统上跑.不过,慢慢地有人把它移植到了Windows上.现在,Git可以在Linux.Unix.Mac和 ...

  2. Easyui的numberbox无法输入以0开头的数字编号(转载)

    1.问题 项目中碰到这样一个问题,Easyui的numberbox在输入数字编号的时候不能以0开头 在我输入以0开头的数字编号后,离开输入框的时候,那个前缀0就自动去掉了. 接下来,我们查看API说明 ...

  3. [Android 4.4.4] 泛泰A850 三版通刷 Mokee4.4.4 KTU84P 20140626 RC2.2 by syhost

    RC2.1版地址: http://blog.csdn.net/syhost/article/details/34051923 2014.06.26 RC2.2 更新内容: 1 修复相机录像无声的bug ...

  4. Excel的列数以数字格式查看

    1.Excel中的列数默认是以字母形式显示的,当我们有大量数据并想知道任一数据是第多少行多少列时这样就不方便了,我们可以通过如下设置来达到让EXCEL以数字形式显示行数和列数的效果. 2.点击文件-- ...

  5. represent states with objects

    1. The behavior of objects in the real world is more complex than simply being in one state at a tim ...

  6. nav标签使用说明

    一.html nav标签语法与结构   -   TOP 1.基本语法 <nav>内容</nav> 2.nav加id <nav id=”abc”>内容</nav ...

  7. python中的ord,chr函数

    chr().unichr()和ord() chr()函数用一个范围在range(256)内的(就是0-255)整数作参数,返回一个对应的字符.unichr()跟它一样,只不过返回的是Unicode字符 ...

  8. 【Java】Java_10 常量与变量

    1.变量(variable) 1.1 我们通过变量来操纵存储空间中的数据,变量就是指代这个存储空间!空间位置是确定的,但是里面放置什么值不确定! 1.2 Java是一种强类型语言,每个变量都必须声明其 ...

  9. java的IO操作:System类对IO的支持。

    目标: 1,掌握SYStem对IO的三种支持: system.out system.in system.err 2,掌握system.out及system.err的区别. 3,掌握输入,输出重定向. ...

  10. Swift 泛型參数

    原文:http://www.cocoachina.com/newbie/basic/2014/0612/8802.html 本页内容包含:泛型形參语句和泛型实參语句 本节涉及泛型类型.泛型函数以及泛型 ...