We've introduced the knowledge points of spring cloud and oauth2 in the previous few, and today we're going to use spring cloud and oauth2 to build Commonservice-sso services, In this section we are just building Commonservice-sso foundation platforms, gossiping less, directly documenting the steps:
1. Create the MAVEN project Commonservice-sso, where the Pom.xml file is configured as follows:
<?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" > <modelversion>4.0.0 </modelVersion> <parent> <groupId>com.ml.honghu</groupId> <ARTIFAC Tid>commonservice</artifactid> <version>0.0.1-SNAPSHOT</version> </parent> <artifactId>commonservice-sso</artifactId> <packaging>jar</packaging> <dependencie s> <dependency> <groupId>org.springframework.cloud</groupId> <a Rtifactid>spring-cloud-starter-eureka</artifactid> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactid>spring-cloud-starter-confi g</artifactid> </dependency> <dependency> <groupid>org.springframew Ork.boot</groupid> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <depende Ncy> <groupId>org.springframework.boot</groupId> <artifactid>spring-boot-st arter-data-rest</artifactid> </dependency> <dependency> <groupid>or G.springframework.boot</groupid> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency> <depe Ndency> <groupId>org.springframework.security.oauth</groupId> <artifactid>s pring-security-oauth2</artifactid> </dependency> <dependency> <group Id>org.springframeworK.boot</groupid> <artifactId>spring-boot-starter-test</artifactId> </dependency > <dependency> <groupId>org.springframework.hateoas</groupId> < Artifactid>spring-hateoas</artifactid> </dependency> <dependency> < Groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-data-rest</artif actid> </dependency> <dependency> <groupid>com.ml.honghu.common.framew Ork</groupid> <artifactId>common-framework-dao</artifactId> <version>1.0 .0-snapshot</version> </dependency> <dependency> <groupid>org.sprin Gframework.boot</groupid> <artifactId>spring-boot-starter-web</artifactId> </de Pendency> <dependency> <groupId>org.springframework.boot</groupId> <artifactid>sprin g-boot-starter-freemarker</artifactid> </dependency> <dependency> <gro Upid>com.ml.honghu</groupid> <artifactId>component-base</artifactId> </depen Dency> </dependency> </dependencies> <!--packaged plug-in, where repackage, true is dedicated to spring boot package- <build> <plugins> <plugin> <GROUPID>ORG.SPRINGFR Amework.boot</groupid> <artifactId>spring-boot-maven-plugin</artifactId> <executions> <execution> <id>1</id> <goals> <goal>repackage</goal> </go Als> </execution> <execution> <id>2</id> <goals> <goal>build-info</goal> < /goals> </execution> </executions> </plugin> </plugins> </build> </project>
2. Configuring the Bootstrap.yml File
Spring: application: name:commonservice-SSO profiles: active:dev,discoveryclient Cloud: config: discovery: true service-id: commonservice-config-Server Eureka: client: service-URL: defaultzone:http: //honghu:[email protected]:8761/eureka instance: prefer true
3. Configure the Project startup file
PackageCom.ml.honghu; Importorg.springframework.boot.SpringApplication; Importorg.springframework.boot.autoconfigure.SpringBootApplication; Importorg.springframework.cloud.netflix.eureka.EnableEurekaClient; @SpringBootApplication @EnableEurekaClient Public classssoapplication { Public Static voidMain (string[] args) {Springapplication.run (ssoapplication.class, args); } }
4. Create an SSO-related table:
Oauth_access_token, Oauth_approvals, Oauth_client_details, Oauth_client_token, Oauth_code, Oauth_refresh_token
The script is as follows:
/*Navicat MySQL Data Transfer source server:localhost source Server version:50621 Source Host: localhost:3306 Source database:honghu target server type:mysql target server version:50621 File Encoding : 65001 date:2017-10-26 20:12:56*/SET foreign_key_checks=0; --------------------------------Table structure for' Oauth_access_token '-- ----------------------------DROP TABLE IF EXISTS ' Oauth_access_token '; CREATE TABLE ' Oauth_access_token ' (' token_id ' varchar (256) DEFAULT NULL, ' token ' blob, ' authentication_id ' varchar (128) not NULL, ' user_name ' varchar (256) DEFAULT NULL, ' client_id ' varchar (256) DEFAULT NULL, ' Authentication ' blob, ' refresh_token ' varchar (256) DEFAULT NULL, PRIMARY KEY (' authentication_id ') ENGINE=innodb DEFAULT charset=UTF8; --------------------------------Table structure for' Oauth_approvals '-- ----------------------------DROP TABLE IF EXISTS ' oauth_approvals '; CREATE TABLE ' oauth_approvals ' (' userId ' varchar (256) DEFAULT NULL, ' clientId ' varchar (256) DEFAULT NULL, ' scope ' varchar (256) DEFAULT NULL, ' status ' varchar (10) default NULL, ' EXPIRESAT ' datetime default NULL, ' Lastmodifiedat ' datetime default null) ENGINE=innodb DEFAULT charset=UTF8; -- ---------------------------- --Records of Oauth_approvals--------------------------------------------------------------Table structure for' Oauth_client_details '-- ----------------------------DROP TABLE IF EXISTS ' oauth_client_details '; CREATE TABLE ' oauth_client_details ' (' client_id ' varchar (128) not NULL, ' resource_ids ' varchar (256) DEFAULT NULL, ' client_secret ' varchar (256) DEFAULT NULL, ' scope ' varchar (256) DEFAULT NULL, ' authorized_grant_types ' varchar (256) DEFAULT NULL, ' web_server_redirect_uri ' varchar (256) DEFAULT NULL, ' authorities ' varchar (256) DEFAULT NULL, ' access_token_validity 'int(11) DEFAULT NULL, ' refresh_token_validity 'int(11) DEFAULT NULL, ' additional_information ' varchar (4096) DEFAULT NULL, ' autoapprove ' varchar (256) DEFAULT NULL, PRIMARY KEY (' client_id ') ENGINE=innodb DEFAULT charset=UTF8; --------------------------------Table structure for' Oauth_client_token '-- ----------------------------DROP TABLE IF EXISTS ' Oauth_client_token '; CREATE TABLE ' Oauth_client_token ' (' token_id ' varchar (256) DEFAULT NULL, ' token ' blob, ' authentication_id ' varchar (128) not NULL, ' user_name ' varchar (256) DEFAULT NULL, ' client_id ' varchar (256) DEFAULT NULL, PRIMARY KEY (' authentication_id ') ENGINE=innodb DEFAULT charset=UTF8; -- ---------------------------- --Records of Oauth_client_token--------------------------------------------------------------Table structure for' Oauth_code '-- ----------------------------DROP TABLE IF EXISTS ' Oauth_code '; CREATE TABLE ' oauth_code ' (' Code ' varchar (256) DEFAULT NULL, ' Authentication ' blob) ENGINE=innodb DEFAULT charset=UTF8; -- ---------------------------- --Records of Oauth_code--------------------------------------------------------------Table structure for' Oauth_refresh_token '-- ----------------------------DROP TABLE IF EXISTS ' Oauth_refresh_token '; CREATE TABLE ' Oauth_refresh_token ' (' token_id ' varchar (256) DEFAULT NULL, ' token ' blob, ' authentication ' blob) ENGINE=innodb DEFAULT Charset=utf8;
Note: The related table for OAuth is used to store user token information and authentication information.
This section builds up first so many, behind the business code too much, we will in the later chapters to be released.
From now on, I will be documenting the process and essence of the recent development of the spring cloud micro-service cloud architecture to help more friends who are interested in developing the Spring cloud framework to explore the process of building the spring cloud architecture and how to use it in enterprise projects.
Source source technical support for complete projects 1791743380
Spring Cloud Cloud Architecture-Commonservice-sso Service Setup (i.)