Spring Cloud(6.3):搭建OAuth2 Resource Server
配置web.xml
添加spring-cloud-starter-security,spring-security-oauth2-autoconfigure2个依赖。
<!-- Spring cloud starter: Security -->
<!-- Include: web, actuator, security, zuul, etc. -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-security</artifactId>
</dependency>
<!-- Spring Security OAuth2 Autoconfigure (optional in spring-cloud-security after 2.1) -->
<dependency>
<groupId>org.springframework.security.oauth.boot</groupId>
<artifactId>spring-security-oauth2-autoconfigure</artifactId>
</dependency>
此外,它还是一个Eureka Client和Config Client,如何配置Eureka Client和Config Client请看前面章节。
配置Application
添加@EnableResourceServer注解,声明为OAuth2 Resource Server。
@SpringBootApplication
@EnableResourceServer // Enable OAuth2 Resource Server
public class ResourceServerApplication {
public static void main(String[] args) {
SpringApplication.run(ResourceServerApplication.class, args);
}
}
配置Configer及参数
ResourceServerConfigurer.java
package com.mytools.config; import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter; @Configuration
public class ResourceServerConfigurer extends ResourceServerConfigurerAdapter { @Override
public void configure(HttpSecurity http) throws Exception {
//@formatter:off
http.authorizeRequests()
.antMatchers("/structure-search/**", "/data-search/**").hasAnyRole("SQL_USER")
.anyRequest().authenticated();
//@formatter:on
}
}
application.yml
## Security info
security:
oauth2:
resource:
# 定义一个回调URL调用Authorization Server来查看令牌是否有效
# use zuul to replace 'http://server-auth/server-auth/user'
userInfoUri: http://localhost:10020/server-zuul/s3/server-auth/user
Spring Cloud(6.3):搭建OAuth2 Resource Server的更多相关文章
- Spring Cloud(6.1):搭建OAuth2 Authorization Server
配置web.xml 添加spring-cloud-starter-security和spring-security-oauth2-autoconfigure两个依赖. </dependency& ...
- Spring Cloud 入门教程 - 搭建配置中心服务
简介 Spring Cloud 提供了一个部署微服务的平台,包括了微服务中常见的组件:配置中心服务, API网关,断路器,服务注册与发现,分布式追溯,OAuth2,消费者驱动合约等.我们不必先知道每个 ...
- 【译文】用Spring Cloud和Docker搭建微服务平台
by Kenny Bastani Sunday, July 12, 2015 转自:http://www.kennybastani.com/2015/07/spring-cloud-docker-mi ...
- 手把手教你使用spring cloud+dotnet core搭建微服务架构:服务治理(-)
背景 公司去年开始使用dotnet core开发项目.公司的总体架构采用的是微服务,那时候由于对微服务的理解并不是太深,加上各种组件的不成熟,只是把项目的各个功能通过业务层面拆分,然后通过nginx代 ...
- spring cloud+dotnet core搭建微服务架构:Api网关(三)
前言 国庆假期,一直没有时间更新. 根据群里面的同学的提问,强烈推荐大家先熟悉下spring cloud.文章下面有纯洁大神的spring cloud系列. 上一章最后说了,因为服务是不对外暴露的,所 ...
- spring cloud+dotnet core搭建微服务架构:配置中心(四)
前言 我们项目中有很多需要配置的地方,最常见的就是各种服务URL地址,这些地址针对不同的运行环境还不一样,不管和打包还是部署都麻烦,需要非常的小心.一般配置都是存储到配置文件里面,不管多小的配置变动, ...
- spring cloud+dotnet core搭建微服务架构:配置中心续(五)
前言 上一章最后讲了,更新配置以后需要重启客户端才能生效,这在实际的场景中是不可取的.由于目前Steeltoe配置的重载只能由客户端发起,没有实现处理程序侦听服务器更改事件,所以还没办法实现彻底实现这 ...
- spring cloud+dotnet core搭建微服务架构:Api授权认证(六)
前言 这篇文章拖太久了,因为最近实在太忙了,加上这篇文章也非常长,所以花了不少时间,给大家说句抱歉.好,进入正题.目前的项目基本都是前后端分离了,前端分Web,Ios,Android...,后端也基本 ...
- spring cloud+.net core搭建微服务架构:服务注册(一)
背景 公司去年开始使用dotnet core开发项目.公司的总体架构采用的是微服务,那时候由于对微服务的理解并不是太深,加上各种组件的不成熟,只是把项目的各个功能通过业务层面拆分,然后通过nginx代 ...
随机推荐
- Robot Framework--pybot命令
1.执行整个项目下的所有用例: pybot 项目路径.例如: pybot D:\robotPS:robot项目里面所有用例 2.执行某个suit中的所有用例: pybot 项目路径\suit文件名称. ...
- Python3 报错'latin-1' codec can't encode character 解决方案
Python3 报错'latin-1' codec can't encode character 解决方案 在更新数据库操作时,报错: UnicodeEncodeError: 'latin-1' co ...
- 在Vue中加入国际化(i18n)中英文功能
1.npm安装方法 npm install vue-i18n --save 2.在src资源文件下创建文件夹i18n,i18n下面创建index.js文件,引入VueI18n和导入语言包(按开发需求可 ...
- <load-on-startup>1</load-on-startup>的作用
1)load-on-startup元素标记容器是否在启动的时候就加载这个servlet(实例化并调用其init()方法).2)它的值必须是一个整数,表示servlet应该被载入的顺序3)当值为0或者大 ...
- ACWing P372 棋盘覆盖 题解
Analysis 这是一个经典的二分图问题,我们将图进行奇偶染色,注意边界条件的判断.再跑一遍匈牙利算法就行了,跟上一题很像. #include<iostream> #include< ...
- Python多线程笔记(二)
Lock对象 原语锁(互斥锁)是一个同步原语,状态是"已锁定"或者"未锁定"之一.两个方法acquire()和release()用于修改锁的状态.如果状态为已锁 ...
- P3119 [USACO15JAN]草鉴定
约翰有n块草场,编号1到n,这些草场由若干条单行道相连.奶牛贝西是美味牧草的鉴赏家,她想到达尽可能多的草场去品尝牧草. 贝西总是从1号草场出发,最后回到1号草场.她想经过尽可能多的草场,贝西在通一个草 ...
- JavaScript中,返回上一个页面时,如何保证上一个页面的不刷新?
history.back()和history.go(-1)都可以实现返回上一页并不刷新.History 对象包含用户(在浏览器窗口中)访问过的 URL. history.back() 等同于在浏览器点 ...
- 小程序can't read property 'push' of undefined
在某些情况下是因为没有初始化,所以初始化一下就好了
- 我需要关于fixedFluxPressure边界的解释【翻译】
翻译自:CFD-online 帖子地址:http://www.cfd-online.com/Forums/openfoam-solving/82581-i-need-explanations-abou ...