1. 程式人生 > >SSO單點登入系統原理分析及功能實現

SSO單點登入系統原理分析及功能實現

  1. Sso系統分析

    1. 什麼是sso系統

SSO英文全稱Single Sign On,單點登入。SSO是在多個應用系統中,使用者只需要登入一次就可以訪問所有相互信任的應用系統。它包括可以將這次主要的登入對映到其他應用中用於同一個使用者的登入的機制。它是目前比較流行的企業業務整合的解決方案之一。

  1. 為什麼要有單點登入系統

    1. 傳統的登入實現方式

此方式在只有一個web工程時是沒有問題。

  1. 叢集環境下

叢集環境下會出現要求使用者多次登入的情況。

解決方案:

  1. 配置tomcat叢集。配置tomcat Session複製。節點數不要超過5個。
  2. 可以使用Session伺服器,儲存Session資訊,使每個節點是無狀態。需要模擬Session。

    單點登入系統是使用redis模擬Session,實現Session的統一管理。

    1. Sso系統的實現

    需要建立一個sso服務工程,可以參考taotao-manager建立。

    1. 工程搭建

    Taotao-sso(pom聚合工程)

    |--taotao-sso-interface(jar)

    |--taotao-sso-Service(war)

    可以參考taotao-manager建立

    1. Taotao-sso

    Pom檔案

    <projectxmlns="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.taotao</groupId>

            <artifactId>taotao-parent</artifactId>

            <version>0.0.1-SNAPSHOT</version>

        </parent>

        <groupId>com.taotao</groupId>

        <artifactId>taotao

    -sso</artifactId>

        <version>0.0.1-SNAPSHOT</version>

        <packaging>pom</packaging>

        <dependencies>

            <dependency>

                <groupId>com.taotao</groupId>

                <artifactId>taotao-common</artifactId>

                <version>0.0.1-SNAPSHOT</version>

            </dependency>

        </dependencies>

        <!-- 配置tomcat外掛 -->

        <build>

            <plugins>

                <plugin>

                    <groupId>org.apache.tomcat.maven</groupId>

                    <artifactId>tomcat7-maven-plugin</artifactId>

                    <configuration>

                        <port>8087</port>

                        <path>/</path>

                    </configuration>

                </plugin>

            </plugins>

        </build>

    </project>

    1. taotao-sso-interface

    1. taotao-sso-service

    Pom檔案

    <projectxmlns="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.taotao</groupId>

            <artifactId>taotao-sso</artifactId>

            <version>0.0.1-SNAPSHOT</version>

        </parent>

        <artifactId>taotao-sso-service</artifactId>

        <packaging>war</packaging>

        <dependencies>

            <dependency>

                <groupId>com.taotao</groupId>

                <artifactId>taotao-manager-dao</artifactId>

                <version>0.0.1-SNAPSHOT</version>

            </dependency>

            <dependency>

                <groupId>com.taotao</groupId>

                <artifactId>taotao-sso-interface</artifactId>

                <version>0.0.1-SNAPSHOT</version>

            </dependency>

            <!-- spring的依賴 -->

            <!-- Spring -->

            <dependency>

                <groupId>org.springframework</groupId>

                <artifactId>spring-context</artifactId>

            </dependency>

            <dependency>

                <groupId>org.springframework</groupId>

                <artifactId>spring-beans</artifactId>

            </dependency>

            <dependency>

                <groupId>org.springframework</groupId>

                <artifactId>spring-webmvc</artifactId>

            </dependency>

            <dependency>

                <groupId>org.springframework</groupId>

                <artifactId>spring-jdbc</artifactId>

            </dependency>

            <dependency>

                <groupId>org.springframework</groupId>

                <artifactId>spring-aspects</artifactId>

            </dependency>

            <dependency>

                <groupId>org.springframework</groupId>

                <artifactId>spring-jms</artifactId>

            </dependency>

            <dependency>

                <groupId>org.springframework</groupId>

                <artifactId>spring-context-support</artifactId>

            </dependency>

            <!-- dubbo相關 -->

            <dependency>

                <groupId>com.alibaba</groupId>

                <artifactId>dubbo</artifactId>

                <!-- 排除依賴 -->

                <exclusions>

                    <exclusion>

                        <groupId>org.springframework</groupId>

                        <artifactId>spring</artifactId>

                    </exclusion>

                    <exclusion>

                        <groupId>org.jboss.netty</groupId>

                        <artifactId>netty</artifactId>

                    </exclusion>

                </exclusions>

            </dependency>

            <dependency>

                <groupId>org.apache.zookeeper</groupId>

                <artifactId>zookeeper</artifactId>

            </dependency>

            <dependency>

                <groupId>com.github.sgroschupf</groupId>

                <artifactId>zkclient</artifactId>

            </dependency>

            <!-- Redis客戶端 -->

            <dependency>

                <groupId>redis.clients</groupId>

                <artifactId>jedis</artifactId>

            </dependency>

        </dependencies>

    </project>

    1. 框架整合

    1. 表現層工程

    表現層工程包含登入和註冊頁面,需要呼叫sso服務實現。

    給app提供服務,restful形式的服務。

    Taotao-sso-web(war包)

    可以參考taotao-manager-web建立。

    <projectxmlns="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.taotao</groupId>

            <artifactId>taotao-parent</artifactId>

            <version>0.0.1-SNAPSHOT</version>

        </parent>

        <groupId>com.taotao</groupId>

        <artifactId>taotao-sso-web</artifactId>

        <version>0.0.1-SNAPSHOT</version>

        <packaging>war</packaging>

        <dependencies>

            <dependency>

                <groupId>com.taotao</groupId>

                <artifactId>taotao-sso-interface</artifactId>

                <version>0.0.1-SNAPSHOT</version>

            </dependency>

            <!-- Spring -->

            <dependency>

                <groupId>org.springframework</groupId>

                <artifactId>spring-context</artifactId>

            </dependency>

            <dependency>

                <groupId>org.springframework</groupId>

                <artifactId>spring-beans</artifactId>

            </dependency>

            <dependency>

                <groupId>org.springframework</groupId>

                <artifactId>spring-webmvc</artifactId>

            </dependency>

            <dependency>

                <groupId>org.springframework</groupId>

                <artifactId>spring-jdbc</artifactId>

            </dependency>

            <dependency>

                <groupId>org.springframework</groupId>

                <artifactId>spring-aspects</artifactId>

            </dependency>

            <dependency>

                <groupId>org.springframework</groupId>

                <artifactId>spring-jms</artifactId>

            </dependency>

            <dependency>

                <groupId>org.springframework</groupId>

                <artifactId>spring-context-support</artifactId>

            </dependency>

            <!-- JSP相關 -->

            <dependency>

                <groupId>jstl</groupId>

                <artifactId>jstl</artifactId>

            </dependency>

            <dependency>

                <groupId>javax.servlet</groupId>

                <artifactId>servlet-api</artifactId>

                <scope>provided</scope>

            </dependency>

            <dependency>

                <groupId>javax.servlet</groupId>

                <artifactId>jsp-api</artifactId>

                <scope>provided</scope>

            </dependency>

            <!-- dubbo相關 -->

            <dependency>

                <groupId>com.alibaba</groupId>

                <artifactId>dubbo</artifactId>

                <!-- 排除依賴 -->

                <exclusions>

                    <exclusion>

                        <groupId>org.springframework</groupId>

                        <artifactId>spring</artifactId>