使用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. 理解SQL原理,写出高效代码

    做软件开发的,大部分人都离不开跟数据库打交道,特别是erp开发的,跟数据库打交道更是频繁,存储过程动不动就是上千行,数据量大,人员流动大,那么我们还能保证下一段时间系统还能流畅的运行吗?我们还能保证下 ...

  2. Bootstrap响应式折叠导航

    浏览器宽度缩小到一定值时,导航显示为 <nav class="navbar navbar-inverse navbar-fixed-top" role="navig ...

  3. IIS 日志

    查看工具: Log Parser + Log Parser Studio http://www.microsoft.com/en-us/download/details.aspx?displaylan ...

  4. nobr 不换行标签

    示例代码: <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> ...

  5. JavaScript里面向对象的继承:构造函数"继承"的六种方法

    //现在有一个"动物"对象的构造函数. function Animal(){ this.species = "动物"; } //还有一个"猫" ...

  6. 【AS3 Coder】任务六:人物换装(纸娃娃)系统的制作

    使用框架:AS3(Flash Professional CS5.0及更高版本 + Flash Buider)任务描述:了解人物换装系统的制作原理难度系数:2 本章源码下载:http://www.iam ...

  7. php中将SimpleXMLElement Object数组转化为普通数组

    做微信开发,鉴于微信POST的消息是XML数据包,通过SimpleXMLElement Object获取的数据不好操作,需要转化为普通数组. 网上找了很多方法都不理想,发现通过json_decode和 ...

  8. Java Web---登录验证和字符编码过滤器

    什么是过滤器? 在Java Web中,过滤器即Filter.Servlet API中提供了一个Filter接口(javax.servlet.Filter).开发web应用时,假设编写的Java类实现了 ...

  9. docker入门——管理容器

    除了交互式的容器(interactive container),我们也可以创建长期运行的容器.守护式容器(daemonized container)没有交互式会话,非常适合运行应用程序和服务.大多数时 ...

  10. 经典算法——Jump Game(II)

    Given an array of non-negative integers, you are initially positioned at the first index of the arra ...