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代 ...
随机推荐
- 重写Router.prototype.push后还报NavigationDuplicated错误的解决方法
vue项目路由跳转时控制台出现NavigationDuplicated错误, message: "Navigating to current location (XXX) is not ...
- 线程(C++11)
不同平台.框架.语言所使用的线程函数不同.对于初学者选择一种适合自己的,用熟用透即可. Windows中,CreateThread() Linux中,pthread_create() MFC框架中,A ...
- HTML 009 CSS
HTML 样式- CSS CSS (Cascading Style Sheets) 用于渲染HTML元素标签的样式. Look! Styles and colors Manipulate Te ...
- 多路径技术:ALUA与SLUA
实现的核心 通过存储设备去适配操作系统,从而实现多路径技术,支持ALUA是其中主要部分. ALUA多路径技术 Asymmetric Logical Unit Access,非对称逻辑单元存取,其提 ...
- vue+elementui 开发的网站IE浏览器加载白屏(不兼容)解决办法
1.需要检查一下 export default { name: 'aa',-------vue的name是不可以重复的-----这个是决定性原因 data() { return {} } 2.变量声明 ...
- codeforces#1228E. Another Filling the Grid(容斥定理,思维)
题目链接: https://codeforces.com/contest/1228/problem/E 题意: 给n*n的矩阵填数,使得每行和每列最小值都是1 矩阵中可以填1到$k$的数 数据范围: ...
- journalnode Can't scan a pre-transactional edit log 异常处理
由于数据磁盘爆满,达到100%,导致journalnode宕掉,在启动journalnode以后,查看日志,提示Can't scan a pre-transactional edit log,这个时候 ...
- [转载]workbench分网---mapped face meshing面映射网格划分
原文地址:face meshing面映射网格划分">workbench分网---mapped face meshing面映射网格划分作者:一丝尘埃 face meshing面映射网格划 ...
- cross socket和msgpack的数据序列和还原
cross socket和msgpack的数据序列和还原 procedure TForm1.Button1Click(Sender: TObject); begin var pack: TSimple ...
- XMind 快捷键完整命令
XMind 快捷键完整命令 快捷键(Windows) 快捷键(Mac) 描述 + + 展开当前分支 - - 收缩当前分支 * * 展开所有分支 / / 收缩所有分支 Alt+- Alt+- 显示系 ...