The project build

dependencies

The code structure

  • Security: the main module
  • Security-core: indicates the core service logic
  • Security-browser: browser security-specific code
  • Security-app :app specific code
  • Security-demo: sample program

Package introduced

The main module

<?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>

    <groupId>com.guosh.security</groupId>
    <artifactId>guosh-security</artifactId>
    <packaging>pom</packaging>
    <version>1.0 the SNAPSHOT</version>

    <! -- Declare variables -->
    <properties>
        <guosh.security.version>1.0 the SNAPSHOT</guosh.security.version>
    </properties>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>io.spring.platform</groupId>
                <artifactId>platform-bom</artifactId>
                <version>Brussels-SR16</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Dalston.SR5</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.8</source> <! -- Development version used for source code -->
                    <target>1.8</target> <! -- The compiled version of the target class file to be generated -->
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <modules>
        <module>guosh-security-core</module>
        <module>guosh-security-browser</module>
        <module>guosh-security-demo</module>
        <module>guosh-security-app</module>
    </modules>
</project>
Copy the code

The core module

<?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>guosh-security</artifactId>
        <groupId>com.guosh.security</groupId>
        <version>1.0 the SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>guosh-security-core</artifactId>
    <dependencies>
        <! - oauth2 authentication -- -- >
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-oauth2</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-redis</artifactId>
        </dependency>
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid-spring-boot-starter</artifactId>
            <version>1.1.10</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>
        <! -- Third-party login -->
        <dependency>
            <groupId>org.springframework.social</groupId>
            <artifactId>spring-social-config</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.social</groupId>
            <artifactId>spring-social-core</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.social</groupId>
            <artifactId>spring-social-security</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.social</groupId>
            <artifactId>spring-social-web</artifactId>
        </dependency>
        <! -- Tools -->
        <dependency>
            <groupId>commons-lang</groupId>
            <artifactId>commons-lang</artifactId>
        </dependency>
        <dependency>
            <groupId>commons-collections</groupId>
            <artifactId>commons-collections</artifactId>
        </dependency>
        <dependency>
            <groupId>commons-beanutils</groupId>
            <artifactId>commons-beanutils</artifactId>
        </dependency>
    </dependencies>
</project>
Copy the code

The browser module

<?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>guosh-security</artifactId>
        <groupId>com.guosh.security</groupId>
        <version>1.0 the SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>guosh-security-browser</artifactId>

    <dependencies>
        <dependency>
            <groupId>com.guosh.security</groupId>
            <artifactId>guosh-security-core</artifactId>
            <version>${guosh.security.version}</version>
        </dependency>
        <! - the session cluster -- -- >
        <dependency>
            <groupId>org.springframework.session</groupId>
            <artifactId>spring-session</artifactId>
        </dependency>
    </dependencies>

</project>
Copy the code

App module

<?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>guosh-security</artifactId>
        <groupId>com.guosh.security</groupId>
        <version>1.0 the SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>guosh-security-app</artifactId>

    <dependencies>
        <dependency>
            <groupId>com.guosh.security</groupId>
            <artifactId>guosh-security-core</artifactId>
            <version>${guosh.security.version}</version>
        </dependency>
    </dependencies>
</project>
Copy the code

The demo module

<?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>guosh-security</artifactId>
        <groupId>com.guosh.security</groupId>
        <version>1.0 the SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>guosh-security-demo</artifactId>


    <dependencies>
        <dependency>
            <groupId>com.guosh.security</groupId>
            <artifactId>guosh-security-browser</artifactId>
            <version>${guosh.security.version}</version>
        </dependency>
        <! --Spring Boot Test framework -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-aop</artifactId>
        </dependency>
    </dependencies>


    <build>
        <! -- Demo is the name of the package that the web application needs to run.
        <finalName>guoshsecurity</finalName>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>1.3.3. RELEASE</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>
Copy the code

The Hello program

Now I need to get the project up and running so I made a Demo

1. Create a YML file under Demo and connect to the database

server:
  port: 8080
  context-path: /guoshsecurity

spring:
  datasource:
    druid:
      url: jdbc:mysql://localhost:3306/guosecurity? useUnicode=true&characterEncoding=utf8&useSSL=true
      username: root
      password: root
      driver-class-name: com.mysql.jdbc.Driver
      The connection pool initialization size is minimum and maximum
      initial-size: 2
      min-idle: 2
      max-active: 2
      Set the connection wait timeout
      maxWait: 60000
      Configure how often to detect idle connections that need to be closed, in milliseconds
      timeBetweenEvictionRunsMillis: 60000
      Set the minimum time for a connection to live in the pool in milliseconds
      minEvictableIdleTimeMillis: 60000
      testWhileIdle: true
      testOnBorrow: false
      testOnReturn: false
      Turn on PSCache and specify the size of PSCache on each connection
      poolPreparedStatements: true
      maxPoolPreparedStatementPerConnectionSize: 20
      # Configure the filters for monitoring statistics interception. After removing the filters, the MONITORING interface SQL cannot be counted. 'wall' is used for the firewall
      filters: stat,wall,log4j
      # property to enable the mergeSql function; Slow SQL record
      connectionProperties: druid.stat.mergeSql=true; druid.stat.slowSqlMillis=5000
      SQL statement used to verify whether the connection is available
      validation-query: SELECT 1
      # DruidDataSource datasource
      useGlobalDataSourceStat: true
      # Monitor configuration
      web-stat-filter:
        url-pattern: / *
        exclusions: /druid/*,*.js,*.gif,*.jpg,*.png,*.css,*.ico
      stat-view-servlet:
        url-pattern: /druid/*
        login-username: guoadmin
        login-password: guoadmin
        Can you press the rework button
        reset-enable: true

  # Close Spring Session
  session:
    store-type: none

Turn off the security default
security:
  basic:
    enabled: false
Copy the code

2. Create the Spring Boot startup file and add a/Hello test

3. Run the main function to view the information

4. Pack the test

You can use the JAR package generated by using the Maven package command

Java-jar./ guoshSecurity.jar startsCopy the code