Spring Cloud Cloud Architecture-Commonservice-sso Service Setup (i.)

Source: Internet
Author: User
Tags oauth

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> <artifactId>commonservice</artifactId> <version>0.0.1 -snapshot</version> </parent> <artifactId>commonservice-sso</artifactId> <packaging >jar</packaging> <dependencies> <dependency> <groupid>org.springframework.cloud& lt;/groupid> <artifactId>spring-cloud-starter-eureka</artifactId> </dependency> &L T;dependency> <groupId>org.springframework.cloud</groupId> <artifactid>spring-cloud -starter-config</artifactid> </dependency> <d ependency> <groupId>org.springframework.boot</groupId> <artifactid>spring-boot-st arter-actuator</artifactid> </dependency> <dependency> <groupid>org.springframe Work.boot</groupid> <artifactId>spring-boot-starter-data-rest</artifactId> </dependency > <dependency> <groupId>org.springframework.boot</groupId> <artifactid>s pring-boot-starter-web</artifactid> </dependency> <dependency> &LT;GROUPID&GT;ORG.SPR Ingframework.boot</groupid> <artifactId>spring-boot-starter-security</artifactId> &LT;/DEP endency> <dependency> <groupId>org.springframework.security.oauth</groupId> &L t;artifactid>spring-security-oauth2</artifactid> </dependency> <dependency> <gr Oupid>org.springframeWork.boot</groupid> <artifactId>spring-boot-starter-test</artifactId> </dependency> <dependency> <groupId>org.springframework.hateoas</groupId> &LT;ARTIFACTID&GT;SPR ing-hateoas</artifactid> </dependency> <dependency> <groupid>org.springframewor K.boot</groupid> <artifactId>spring-boot-starter-data-rest</artifactId> </dependency&gt      ; <dependency> <groupId>com.ml.honghu.common.framework</groupId> <artifactid>commo n-framework-dao</artifactid> <version>1.0.0-SNAPSHOT</version> </dependency> &L T;dependency> <groupId>org.springframework.boot</groupId> <artifactid>spring-boot-s tarter-web</artifactid> </dependency> <dependency> <groupid>org.springframework . boot</groupid> <artifactId>spring-boot-starter-freemarker</artifactId> </dependency> <depend Ency> <groupId>com.ml.honghu</groupId> <artifactid>component-base</artifactid&gt      ; </dependency> </dependency> </dependencies> <!--packaged plug-in, where repackage, true is specially hit Spring boot special package--&gt  ; <build> <plugins> <plugin> <groupid>org.springframework.boot</groupi                  D> <artifactId>spring-boot-maven-plugin</artifactId> <executions>                          <execution> <id>1</id> <goals>                  <goal>repackage</goal> </goals> </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:       enabled: true      service-id: commonservice-config-server  eureka:   client:  service-url:    defaultZone: http://honghu:[email protected]:8761/eureka  instance:  prefer-ip-address: true  
  3. Configuring the Project Startup file
package com.ml.honghu;  import org.springframework.boot.SpringApplication;  import org.springframework.boot.autoconfigure.SpringBootApplication;  import org.springframework.cloud.netflix.eureka.EnableEurekaClient;  @SpringBootApplication  @EnableEurekaClient  public class SSOApplication {      public static void main(String[] args) {          SpringApplication.run(SSOApplication.class, args);      }  }  
    1. To create an SSO-related table:

Oauth_access_token, Oauth_approvals,
Oauth_client_details, Oauth_client_token,
Oauth_code, Oauth_refresh _token

/* Navicat MySQL Data Transfer source server:localhost source Server version:50621 Source Host:loc         alhost: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) DEFAULT NULL, ' token ' blob, ' authentication_id ' Varch AR (+) NOT NULL, ' user_name ' varchar default NULL, ' client_id ' varchar ($) default NULL, ' Authentication ' Blob, ' refresh_token ' varchar (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) default NULL, ' clientId ' varchar ' default null ', ' scope ' varchar (2  () default null, ' status ' varchar (TEN) 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 ($) NOT null, ' resource_ids ' varchar ' DEFAULT NULL, ' client_secret ' varchar default null, ' scope ' varchar default NULL, ' authorized_grant_types ' varchar (256 Default NULL, ' Web_server_redirect_uri ' varchar (in the default null, ' authorities ' varchar) default NULL, ' AC cess_token_validity ' int (one) DEFAULT NULL, ' refresh_token_validity ' int (one) DEfault null, ' additional_information ' varchar (4096) default null, ' autoapprove ' varchar () default NULL, Primar  Y 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) DEFAULT NULL, ' token ' blob, ' authentication_id ' Varch AR (+) NOT NULL, ' user_name ' varchar default NULL, ' client_id ' varchar ($) default NULL, PRIMARY KEY (' aut  hentication_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 () 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_toke  n ';  CREATE TABLE ' Oauth_refresh_token ' (' token_id ' varchar () 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.

Spring Cloud Cloud Architecture-Commonservice-sso Service Setup (i.)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.