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>

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

            <dependency>

                <groupId>junit</groupId>

                <artifactId>junit</artifactId>

            </dependency>

        </dependencies>

        <!-- 配置tomcat插件 -->

        <build>

            <plugins>

                <plugin>

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

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

                    <configuration>

                        <port>8088</port>

                        <path>/</path>

                    </configuration>

                </plugin>

            </plugins>

        </build>

    </project>

     

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

学亮编程手记

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值