创建资源模块

我们需要引入oauth2.0包

<dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-oauth2</artifactId><version>2.1.0.RELEASE</version>
</dependency>

完整如下

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><parent><artifactId>springboot_security_oauth</artifactId><groupId>com.leon</groupId><version>1.0-SNAPSHOT</version></parent><modelVersion>4.0.0</modelVersion><artifactId>leon_oauth_source</artifactId><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-security</artifactId></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-oauth2</artifactId><version>2.1.0.RELEASE</version></dependency><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>5.1.47</version></dependency><dependency><groupId>org.mybatis.spring.boot</groupId><artifactId>mybatis-spring-boot-starter</artifactId><version>2.1.0</version></dependency></dependencies>
</project>

然后创建配置文件

server:port: 9002
spring:datasource:driver-class-name: com.mysql.jdbc.Driverurl: jdbc:mysql:///security_authorityusername: rootpassword: rootmain:allow-bean-definition-overriding: true #允许我们自己覆盖spring放入到IOC容器的对象
mybatis:type-aliases-package: com.leon.domainconfiguration:map-underscore-to-camel-case: true
logging:level:com.leon: debug

提供启动类

@SpringBootApplication
@MapperScan("com.itheima.mapper")
public class OauthSourceApplication {public static void main(String[] args) {SpringApplication.run(OauthSourceApplication.class, args);}
}

提供处理器

这里不再连数据库了

@RestController
@RequestMapping("/product")
public class ProductController {@GetMapping("/findAll")public String findAll(){return "产品列表查询成功!";}
}

启动项目测试

由于此刻,项目中添加的有SpringBoot的Security包,默认不通过认证是无法访问处理器的,这个结果咱们在第三 天都已经知道了!那么如何解决呢?第三天我们是采用单点登录的方式解决了这个问题,那么今天我们把这个资源交给OAuth2来管理,使用通行的token来访问资源!

SpringSecurity 案例之创建资源服务器准备工作相关推荐

  1. SpringSecurity分布式整合之资源服务器搭建和测试

    资源服务 说明 资源服务可以有很多个,这里只拿产品服务为例,记住,资源服务中只能通过公钥验证认证.不能签发token! 创建产品服务并导入jar包 根据实际业务导包即可,咱们就暂时和认证服务一样了. ...

  2. SpringSecurity案例之把资源交给OAuth2的资源服务管理

    将访问资源作为OAuth2的资源来管理 复制昨天项目中用户和角色对象,即便是用OAuth2管理资源,也一样需要认证,这两个对象还是需要的. SysRole.java public class SysR ...

  3. nodejs 创建一个静态资源服务器 +路由

    0.补充 1.Node.js 创建的第一个应用 1.引入 http 模块 var http = require("http"); 2.创建服务器 接下来我们使用 http.crea ...

  4. NodeJS 创建静态资源服务器

    最近,学习了一下 NodeJS 自己研究了一个静态资源服务器写的不好,希望高手多多指教 目录结构 文件详解 .gitignore 文件 这个文件主要是我们将本地项目上传到 GitHub 上时,忽略的文 ...

  5. SpringSecurity(二十)---OAuth2:实现资源服务器(上)资源服务器搭建以及直接调用授权服务器模式

    一. 前言 本章将讨论如何使用Spring Security实现一个资源服务器,资源服务器是管理用户资源的组件.另外,学习本章有个前提,需要先把前面搭建授权服务器的相关文章先给阅读,否则可能后面出现的 ...

  6. php静态资源服务器,Node实现静态资源服务器

    这次给大家带来Node实现静态资源服务器,Node实现静态资源服务器的注意事项有哪些,下面就是实战案例,一起来看一下. http的原理是对请求和响应进行了包装,当客户端连接上来之后先触发connect ...

  7. nodejs创建http服务器

    之前有简单介绍nodejs的一篇文章(http://www.cnblogs.com/fangsmile/p/6226044.html) HTTP服务器 Node内建有一个模块,利用它可以很容易创建基本 ...

  8. 使用Spring Security Oauth2 和 JWT保护微服务--资源服务器的编写

    编写hcnet-website的资源服务 依赖管理pom文件 hcnet-website工程的pom文件继承主maven的pom文件.在hcnet-website工程的pom文件中添加web功能的起步 ...

  9. 认证服务器,资源服务器

    oauth2.0–基础–03–简单搭建认证服务器,资源服务器 代码文章 https://gitee.com/DanShenGuiZu/learnDemo/tree/master/auth2.0--le ...

最新文章

  1. verilog基础--sign表达式
  2. 团队作业5-Alpha版本测试报告(彼岸芳华队)
  3. Python+OpenCV 十几行代码模仿世界名画
  4. datatable对两个csv的join操作
  5. 在中国做操作系统研发 20 年是种什么体验?
  6. 实现省市二级联动效果
  7. 阿诗玛的传说|阿诗玛民间故事
  8. knn算法实例python_Python实现的knn算法示例
  9. jQuery EasyUI教程之datagrid应用-1
  10. JavaSE基础——异常、File文件类
  11. 检察院计算机知识试卷,2014河南检察院考试备考:计算机专业课试题练习
  12. 金融计量模型(十):协整和误差修正模型
  13. java并发编程 第二期 CAS
  14. 【彩虹 钢琴伴奏】笔记
  15. 订阅号做了77天,没有挣钱,但是收获很多。
  16. 遇见未来 | 对话朱贤文: PostgreSQL是一匹即将发力的黑马
  17. Win10打开文件夹闪退怎么解决
  18. 这是最好的年代,也是最坏的年代?
  19. 矩阵的奇异值分解(SVD)及其应用
  20. 软件测试修炼之道之——重现问题

热门文章

  1. CodeIgniter模型
  2. System.IO 的三个抽象类
  3. spring+cxf
  4. 第三方支付账务系统设计难点 16
  5. iOS iCloud云存储数据
  6. kafka整理笔记笔记
  7. 基于python、虹软实现人脸检测,人脸识别
  8. 当当创始人李国庆谈吴秀波事件:呼吁释放陈昱霖 应核查税收
  9. Django在admin.py中设置date_hierarchy时报错
  10. 使用C#删除一个字符串数组中的空字符串