前面几篇我们已经介绍了Spring Cloud和oauth2的知识点,今天我们要利用Spring Cloud和oauth2进行commonservice-sso服务搭建,本节我们只是搭建commonservice-sso的基础平台,闲话少说,直接将步骤记录下来:

1. 创建maven项目commonservice-sso,其中pom.xml文件配置如下:

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  4. <modelVersion>4.0.0</modelVersion>
  5.  
  6. <parent>
  7. <groupId>com.ml.honghu</groupId>
  8. <artifactId>commonservice</artifactId>
  9. <version>0.0.1-SNAPSHOT</version>
  10. </parent>
  11.  
  12. <artifactId>commonservice-sso</artifactId>
  13. <packaging>jar</packaging>
  14.  
  15. <dependencies>
  16. <dependency>
  17. <groupId>org.springframework.cloud</groupId>
  18. <artifactId>spring-cloud-starter-eureka</artifactId>
  19. </dependency>
  20. <dependency>
  21. <groupId>org.springframework.cloud</groupId>
  22. <artifactId>spring-cloud-starter-config</artifactId>
  23. </dependency>
  24. <dependency>
  25. <groupId>org.springframework.boot</groupId>
  26. <artifactId>spring-boot-starter-actuator</artifactId>
  27. </dependency>
  28. <dependency>
  29. <groupId>org.springframework.boot</groupId>
  30. <artifactId>spring-boot-starter-data-rest</artifactId>
  31. </dependency>
  32. <dependency>
  33. <groupId>org.springframework.boot</groupId>
  34. <artifactId>spring-boot-starter-web</artifactId>
  35. </dependency>
  36. <dependency>
  37. <groupId>org.springframework.boot</groupId>
  38. <artifactId>spring-boot-starter-security</artifactId>
  39. </dependency>
  40.  
  41. <dependency>
  42. <groupId>org.springframework.security.oauth</groupId>
  43. <artifactId>spring-security-oauth2</artifactId>
  44. </dependency>
  45.  
  46. <dependency>
  47. <groupId>org.springframework.boot</groupId>
  48. <artifactId>spring-boot-starter-test</artifactId>
  49. </dependency>
  50. <dependency>
  51. <groupId>org.springframework.hateoas</groupId>
  52. <artifactId>spring-hateoas</artifactId>
  53. </dependency>
  54. <dependency>
  55. <groupId>org.springframework.boot</groupId>
  56. <artifactId>spring-boot-starter-data-rest</artifactId>
  57. </dependency>
  58. <dependency>
  59. <groupId>com.ml.honghu.common.framework</groupId>
  60. <artifactId>common-framework-dao</artifactId>
  61. <version>1.0.0-SNAPSHOT</version>
  62. </dependency>
  63. <dependency>
  64. <groupId>org.springframework.boot</groupId>
  65. <artifactId>spring-boot-starter-web</artifactId>
  66. </dependency>
  67. <dependency>
  68. <groupId>org.springframework.boot</groupId>
  69. <artifactId>spring-boot-starter-freemarker</artifactId>
  70. </dependency>
  71. <dependency>
  72. <groupId>com.ml.honghu</groupId>
  73. <artifactId>component-base</artifactId>
  74. </dependency>
  75. </dependency>
  76. </dependencies>
  77.  
  78. <!-- 打包插件,其中repackage、true是专门打spring boot专用包 -->
  79. <build>
  80. <plugins>
  81. <plugin>
  82. <groupId>org.springframework.boot</groupId>
  83. <artifactId>spring-boot-maven-plugin</artifactId>
  84. <executions>
  85. <execution>
  86. <id>1</id>
  87. <goals>
  88. <goal>repackage</goal>
  89. </goals>
  90. </execution>
  91. <execution>
  92. <id>2</id>
  93. <goals>
  94. <goal>build-info</goal>
  95. </goals>
  96. </execution>
  97. </executions>
  98. </plugin>
  99. </plugins>
  100. </build>
  101. </project>

2. 配置bootstrap.yml文件

  1. spring:
  2. application:
  3. name: commonservice-sso
  4. profiles:
  5. active: dev,discoveryClient
  6. cloud:
  7. config:
  8. discovery:
  9. enabled: true
  10. service-id: commonservice-config-server
  11. eureka:
  12. client:
  13. service-url:
  14. defaultZone: http://honghu:123456@localhost:8761/eureka
  15. instance:
  16. prefer-ip-address: true

3. 配置项目启动文件

  1. package com.ml.honghu;
  2.  
  3. import org.springframework.boot.SpringApplication;
  4. import org.springframework.boot.autoconfigure.SpringBootApplication;
  5. import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
  6.  
  7. @SpringBootApplication
  8. @EnableEurekaClient
  9. public class SSOApplication {
  10. public static void main(String[] args) {
  11. SpringApplication.run(SSOApplication.class, args);
  12. }
  13. }

4. 创建sso相关表:

oauth_access_token、oauth_approvals、

oauth_client_details、oauth_client_token、

oauth_code、oauth_refresh_token

  1. /*
  2. Navicat MySQL Data Transfer
  3.  
  4. Source Server : localhost
  5. Source Server Version : 50621
  6. Source Host : localhost:3306
  7. Source Database : honghu
  8.  
  9. Target Server Type : MYSQL
  10. Target Server Version : 50621
  11. File Encoding : 65001
  12.  
  13. Date: 2017-10-26 20:12:56
  14. */
  15.  
  16. SET FOREIGN_KEY_CHECKS=0;
  17.  
  18. -- ----------------------------
  19. -- Table structure for `oauth_access_token`
  20. -- ----------------------------
  21. DROP TABLE IF EXISTS `oauth_access_token`;
  22. CREATE TABLE `oauth_access_token` (
  23. `token_id` varchar(256) DEFAULT NULL,
  24. `token` blob,
  25. `authentication_id` varchar(128) NOT NULL,
  26. `user_name` varchar(256) DEFAULT NULL,
  27. `client_id` varchar(256) DEFAULT NULL,
  28. `authentication` blob,
  29. `refresh_token` varchar(256) DEFAULT NULL,
  30. PRIMARY KEY (`authentication_id`)
  31. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
  32.  
  33. -- ----------------------------
  34. -- Table structure for `oauth_approvals`
  35. -- ----------------------------
  36. DROP TABLE IF EXISTS `oauth_approvals`;
  37. CREATE TABLE `oauth_approvals` (
  38. `userId` varchar(256) DEFAULT NULL,
  39. `clientId` varchar(256) DEFAULT NULL,
  40. `scope` varchar(256) DEFAULT NULL,
  41. `status` varchar(10) DEFAULT NULL,
  42. `expiresAt` datetime DEFAULT NULL,
  43. `lastModifiedAt` datetime DEFAULT NULL
  44. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
  45.  
  46. -- ----------------------------
  47. -- Records of oauth_approvals
  48. -- ----------------------------
  49.  
  50. -- ----------------------------
  51. -- Table structure for `oauth_client_details`
  52. -- ----------------------------
  53. DROP TABLE IF EXISTS `oauth_client_details`;
  54. CREATE TABLE `oauth_client_details` (
  55. `client_id` varchar(128) NOT NULL,
  56. `resource_ids` varchar(256) DEFAULT NULL,
  57. `client_secret` varchar(256) DEFAULT NULL,
  58. `scope` varchar(256) DEFAULT NULL,
  59. `authorized_grant_types` varchar(256) DEFAULT NULL,
  60. `web_server_redirect_uri` varchar(256) DEFAULT NULL,
  61. `authorities` varchar(256) DEFAULT NULL,
  62. `access_token_validity` int(11) DEFAULT NULL,
  63. `refresh_token_validity` int(11) DEFAULT NULL,
  64. `additional_information` varchar(4096) DEFAULT NULL,
  65. `autoapprove` varchar(256) DEFAULT NULL,
  66. PRIMARY KEY (`client_id`)
  67. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
  68.  
  69. -- ----------------------------
  70. -- Table structure for `oauth_client_token`
  71. -- ----------------------------
  72. DROP TABLE IF EXISTS `oauth_client_token`;
  73. CREATE TABLE `oauth_client_token` (
  74. `token_id` varchar(256) DEFAULT NULL,
  75. `token` blob,
  76. `authentication_id` varchar(128) NOT NULL,
  77. `user_name` varchar(256) DEFAULT NULL,
  78. `client_id` varchar(256) DEFAULT NULL,
  79. PRIMARY KEY (`authentication_id`)
  80. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
  81.  
  82. -- ----------------------------
  83. -- Records of oauth_client_token
  84. -- ----------------------------
  85.  
  86. -- ----------------------------
  87. -- Table structure for `oauth_code`
  88. -- ----------------------------
  89. DROP TABLE IF EXISTS `oauth_code`;
  90. CREATE TABLE `oauth_code` (
  91. `code` varchar(256) DEFAULT NULL,
  92. `authentication` blob
  93. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
  94.  
  95. -- ----------------------------
  96. -- Records of oauth_code
  97. -- ----------------------------
  98.  
  99. -- ----------------------------
  100. -- Table structure for `oauth_refresh_token`
  101. -- ----------------------------
  102. DROP TABLE IF EXISTS `oauth_refresh_token`;
  103. CREATE TABLE `oauth_refresh_token` (
  104. `token_id` varchar(256) DEFAULT NULL,
  105. `token` blob,
  106. `authentication` blob
  107. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;

备注: oauth的相关表是用来存储用户的token信息和认证信息的。

本节搭建先搭建那么多,后面的业务代码太多,我们会在后面的章节中放出来。

从现在开始,我这边会将近期研发的spring cloud微服务云架构的搭建过程和精髓记录下来,帮助更多有兴趣研发spring cloud框架的朋友,大家来一起探讨spring cloud架构的搭建过程及如何运用于企业项目。源码来源

Spring Cloud云架构 - commonservice-sso服务搭建(一)的更多相关文章

  1. (十一) 整合spring cloud云架构 - SSO单点登录之OAuth2.0登录流程(2)

    上一篇是站在巨人的肩膀上去研究OAuth2.0,也是为了快速帮助大家认识OAuth2.0,闲话少说,我根据框架中OAuth2.0的使用总结,画了一个简单的流程图(根据用户名+密码实现OAuth2.0的 ...

  2. Spring Cloud云架构 - SSO单点登录之OAuth2.0 根据token获取用户信息(4)

    上一篇我根据框架中OAuth2.0的使用总结,画了SSO单点登录之OAuth2.0 登出流程,今天我们看一下根据用户token获取yoghurt信息的流程: /** * 根据token获取用户信息 * ...

  3. Spring Cloud云架构 - SSO单点登录之OAuth2.0登录流程(2)

    上一篇是站在巨人的肩膀上去研究OAuth2.0,也是为了快速帮助大家认识OAuth2.0,闲话少说,我根据框架中OAuth2.0的使用总结,画了一个简单的流程图(根据用户名+密码实现OAuth2.0的 ...

  4. 整合spring cloud云架构 - SSO单点登录之OAuth2.0登录认证(1)

    之前写了很多关于spring cloud的文章,今天我们对OAuth2.0的整合方式做一下笔记,首先我从网上找了一些关于OAuth2.0的一些基础知识点,帮助大家回顾一下知识点: 一.oauth中的角 ...

  5. Spring Cloud云架构 - SSO单点登录之OAuth2.0 登出流程(3)

    上一篇我根据框架中OAuth2.0的使用总结,画了一个根据用户名+密码实现OAuth2.0的登录认证的流程图,今天我们看一下logout的流程: /** * 用户注销 * @param accessT ...

  6. Spring Cloud云架构 - SSO单点登录之OAuth2.0登录认证(1)

    今天我们对OAuth2.0的整合方式做一下笔记,首先我从网上找了一些关于OAuth2.0的一些基础知识点,帮助大家回顾一下知识点: 一.oauth中的角色 client:调用资源服务器API的应用 O ...

  7. 整合spring cloud云架构 - 根据token获取用户信息

    根据用户token获取yoghurt信息的流程: /** * 根据token获取用户信息 * @param accessToken * @return * @throws Exception */ @ ...

  8. 整合SPRING CLOUD云服务架构 - 企业分布式微服务云架构构建

    整合SPRING CLOUD云服务架构 - 企业分布式微服务云架构构建 1.   介绍 Commonservice-system是一个大型分布式.微服务.面向企业的JavaEE体系快速研发平台,基于模 ...

  9. 从 Spring Cloud 开始,聊聊微服务架构实践之路

    [编者的话]随着公司业务量的飞速发展,平台面临的挑战已经远远大于业务,需求量不断增加,技术人员数量增加,面临的复杂度也大大增加.在这个背景下,平台的技术架构也完成了从传统的单体应用到微服务化的演进. ...

随机推荐

  1. Linux 下面根据端口号 查询 可执行程序的路劲的方法

    1. 安装上lsof 的包 2. 使用 lsof 命令查看相关进程 lsof -i: 效果为: 3. 根据/proc 的目录查看可执行目录的文件位置 ll /proc/procid # procid ...

  2. TableLayoutPanel

    1.简单属性 百度经验:https://jingyan.baidu.com/article/9113f81b7966df2b3314c775.html Name属性:tableLayoutPanel经 ...

  3. python——列表方法

    L.append():追加一个元素到列表末尾 L = [] L.append('boy') L.insert() :将一个元素插入到指定位置 L.insert(1, 'girl') L.extend( ...

  4. Mac中如何高亮显示当前git分支以及相关切换系统默认shell操作

    前言 在开发中对于使用git的同学,肯定会需要高亮显示当前分支,我们今天就来说一种最简单的办法,先来看一下效果图 实现 1.安装item2 https://www.iterm2.com 2.安装oh- ...

  5. qt嵌入式html和本地c++通信方式

    前沿:我们在做qt项目的时候,通常会把某个html网页直接显示到应用程序中.比如绘图.直接把html形式的图标嵌入到应用程序中 但是我们需要把数据从后台c++端传到html端,实现显示.qt实现了相关 ...

  6. 使用python 实现 微信好友 个性签名 并 制作 词云图

    环境搭建: pip install itchat numpy wordcloud matplotlib jieba 先把上面的几个包安装完成,直接上代码 import itchat from itch ...

  7. Centos下安装nc命令工具安装以及使用

    1)netcat(nc)是一个简单而有用的工具,被誉为网络安全界的“瑞士军刀”,不仅可以通过使用TCP或UDP协议的网络连接读写数据,同时还是一个功能强大的网络调试和探测工具,能够建立你需要的几乎所有 ...

  8. Python3零基础入门学习视频+源码+课件+习题-小甲鱼

    目录 1. 介绍 2. 目录 3. 下载地址 1. 介绍 适用人群 完全零基础入门,不需要任何前置知识. 课程概述 本系列教程面向零基础的同学,是一个深入浅出,通俗易懂的Python3视频教程. 前半 ...

  9. matlab 中figure的图像 抗锯齿

    linehandle = plot(xxxxxx); set( linehandle, 'linesmoothing', 'on' );

  10. Anaconda3安装及使用

    一.安装及环境变量配置 1.从这里下载Anaconda 2.根据提示安装即可 3.配置环境变量:%Anaconda%\Script 打开命令行,输入:conda --version,回显版本即完成安装 ...