Spring security实战(1)-----项目搭建

项目环境:IntelliJ IDEA、Maven
涉及技术:
       Spring Security 实现 (用户名+密码认证)+(手机号+短信认证) —-基于浏览器session
       Spring Social 实现第三方认证 ——-基于浏览器session
       Spring Security OAuth提供这三种方式的在app上的实现 —-基于token、作用:创建、管理、分发token用的
项目背景:
       企业级认证和授权需求:
              同时支持多种认证方式(用户名/密码,短信,QQ,微信)
              同时支持多种前端渠道(浏览器,App)
              支持集群环境,跨应用工作(SSO),session的数量,控制用户的权限,防护与身份认证相关的攻击

架构介绍:

  • rz-security: 主模块 (pom类型、包含下面四个子模块、目的:统一执行命令:打包、测试)
  • rz-security-core:核心业务逻辑(基本的安全认证方式:表单登录,手机验证码登录,第三方登录)
  • rz-security-browser 、rz-security-app:(浏览器安全特定代码、app安全特定代码)
  • rz-security-demo: 样例程序

项目初始化:
1. rz-security的pom.xml文件

<?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.rz.security</groupId>
    <artifactId>rz-security</artifactId>
    <packaging>pom</packaging>
    <version>1.0-SNAPSHOT</version>

    <!--当改变项目的版本时候,只需要改变该属性-->
    <properties>
        <rz-security-version>1.0-SNAPSHOT</rz-security-version>
    </properties>

    <dependencyManagement>
        <dependencies>
            <!--maven管理spring依赖的版本-->
            <dependency>
                <groupId>io.spring.platform</groupId>
                <artifactId>platform-bom</artifactId>
                <version>Brussels-SR5</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Dalston.SR4</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <plugins>
            <!--maven的编译插件-->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <modules>
        <!--作为子模块-->
        <module>../rz-security-core</module>
        <module>../rz-security-browser</module>
        <module>../rz-security-app</module>
        <module>../rz-security-demo</module>
    </modules>
</project>

2 . rz-security-core的pom.xml文件

    <?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>rz-security</artifactId>
        <groupId>com.rz.security</groupId>
        <version>1.0-SNAPSHOT</version>
        <relativePath>../rz-security/pom.xml</relativePath>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>rz-security-core</artifactId>
    <packaging>jar</packaging>


    <dependencies>
        <!-- app安全认证 -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-oauth2</artifactId>
        </dependency>
        <!-- 存储token,系统用户和第三方用户做一个绑定,存储绑定关系 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-redis</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>
        <!-- spring social实现第三方登录相关 -->
        <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>
        <!-- java操作工具包 -->
        <!--字符串操作-->
        <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>

3 . rz-security-bowser的pom.xml文件

<?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>rz-security</artifactId>
        <groupId>com.rz.security</groupId>
        <version>1.0-SNAPSHOT</version>
        <relativePath>../rz-security/pom.xml</relativePath>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>rz-security-browser</artifactId>

    <dependencies>
        <dependency>
            <artifactId>rz-security-core</artifactId>
            <groupId>com.rz.security</groupId>
            <version>${rz-security-version}</version>
        </dependency>
        <!-- 集群环境下的session管理 -->
        <dependency>
            <groupId>org.springframework.session</groupId>
            <artifactId>spring-session</artifactId>
        </dependency>
    </dependencies>

</project>

4 . rz-security-app的pom.xml文件

<?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>rz-security</artifactId>
        <groupId>com.rz.security</groupId>
        <version>1.0-SNAPSHOT</version>
        <relativePath>../rz-security/pom.xml</relativePath>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>rz-security-app</artifactId>
    <dependencies>
        <dependency>
            <artifactId>rz-security-core</artifactId>
            <groupId>com.rz.security</groupId>
            <version>${rz-security-version}</version>
        </dependency>

    </dependencies>
</project>

5 . rz-security-demo的pom.xml文件

<?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>rz-security</artifactId>
        <groupId>com.rz.security</groupId>
        <version>1.0-SNAPSHOT</version>
        <relativePath>../rz-security/pom.xml</relativePath>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>rz-security-demo</artifactId>

    <dependencies>
        <dependency>
            <groupId>com.rz.security</groupId>
            <artifactId>rz-security-browser</artifactId>
            <version>${rz-security-version}</version>
        </dependency>
    </dependencies>

</project>

项目框架初步搭建完成,接下来在rz-security-demo中编写RESTFul API

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章