SSO单点登录系统原理分析及功能实现

  1. Sso系统分析

    1. 什么是sso系统

SSO英文全称Single Sign On,单点登录。SSO是在多个应用系统中,用户只需要登录一次就可以访问所有相互信任的应用系统。它包括可以将这次主要的登录映射到其他应用中用于同一个用户的登录的机制。它是目前比较流行的企业业务整合的解决方案之一。

 

 

  1. 为什么要有单点登录系统

    1. 传统的登录实现方式

SSO单点登录系统原理分析及功能实现_第1张图片

 

此方式在只有一个web工程时是没有问题。

 

  1. 集群环境下

SSO单点登录系统原理分析及功能实现_第2张图片SSO单点登录系统原理分析及功能实现_第3张图片SSO单点登录系统原理分析及功能实现_第4张图片SSO单点登录系统原理分析及功能实现_第5张图片SSO单点登录系统原理分析及功能实现_第6张图片SSO单点登录系统原理分析及功能实现_第7张图片SSO单点登录系统原理分析及功能实现_第8张图片

 

 

 

 

 

 

 

 

SSO单点登录系统原理分析及功能实现_第9张图片

 

 

 

 

 

 

 

 

 

 

 

SSO单点登录系统原理分析及功能实现_第10张图片

 

 

 

 

集群环境下会出现要求用户多次登录的情况。

解决方案:

  1. 配置tomcat集群。配置tomcat Session复制。节点数不要超过5个。
  2. 可以使用Session服务器,保存Session信息,使每个节点是无状态。需要模拟Session。

     

    单点登录系统是使用redis模拟Session,实现Session的统一管理。

     

     

     

    1. Sso系统的实现

    SSO单点登录系统原理分析及功能实现_第11张图片

     

    需要创建一个sso服务工程,可以参考taotao-manager创建。

    1. 工程搭建

    Taotao-sso(pom聚合工程)

    |--taotao-sso-interface(jar)

    |--taotao-sso-Service(war)

     

    可以参考taotao-manager创建

     

    1. Taotao-sso

    SSO单点登录系统原理分析及功能实现_第12张图片

    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.0modelVersion>

        <parent>

            <groupId>com.taotaogroupId>

            <artifactId>taotao-parentartifactId>

            <version>0.0.1-SNAPSHOTversion>

        parent>

        <groupId>com.taotaogroupId>

        <artifactId>taotao-ssoartifactId>

        <version>0.0.1-SNAPSHOTversion>

        <packaging>pompackaging>

        <dependencies>

            <dependency>

                com.taotao

                taotao-common

                0.0.1-SNAPSHOT

            dependency>

        dependencies>

        

        <build>

            <plugins>

                <plugin>

                    <groupId>org.apache.tomcat.mavengroupId>

                    <artifactId>tomcat7-maven-pluginartifactId>

                    <configuration>

                        <port>8087port>

                        <path>/path>

                    configuration>

                plugin>

            plugins>

        build>

    project>

    1. taotao-sso-interface

    SSO单点登录系统原理分析及功能实现_第13张图片

    SSO单点登录系统原理分析及功能实现_第14张图片

    1. taotao-sso-service

    SSO单点登录系统原理分析及功能实现_第15张图片

    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.0modelVersion>

        <parent>

            <groupId>com.taotaogroupId>

            <artifactId>taotao-ssoartifactId>

            <version>0.0.1-SNAPSHOTversion>

        parent>

        <artifactId>taotao-sso-serviceartifactId>

        <packaging>warpackaging>

        <dependencies>

            <dependency>

                <groupId>com.taotaogroupId>

                <artifactId>taotao-manager-daoartifactId>

                <version>0.0.1-SNAPSHOTversion>

            dependency>

            <dependency>

                <groupId>com.taotaogroupId>

                <artifactId>taotao-sso-interfaceartifactId>

                <version>0.0.1-SNAPSHOTversion>

            dependency>

            

            

            <dependency>

                <groupId>org.springframeworkgroupId>

                <artifactId>spring-contextartifactId>

            dependency>

            <dependency>

                <groupId>org.springframeworkgroupId>

                <artifactId>spring-beansartifactId>

            dependency>

            <dependency>

                <groupId>org.springframeworkgroupId>

                <artifactId>spring-webmvcartifactId>

            dependency>

            <dependency>

                <groupId>org.springframeworkgroupId>

                <artifactId>spring-jdbcartifactId>

            dependency>

            <dependency>

                <groupId>org.springframeworkgroupId>

                <artifactId>spring-aspectsartifactId>

            dependency>

            <dependency>

                <groupId>org.springframeworkgroupId>

                <artifactId>spring-jmsartifactId>

            dependency>

            <dependency>

                <groupId>org.springframeworkgroupId>

                <artifactId>spring-context-supportartifactId>

            dependency>

            

            <dependency>

                <groupId>com.alibabagroupId>

                <artifactId>dubboartifactId>

                

                <exclusions>

                    <exclusion>

                        <groupId>org.springframeworkgroupId>

                        <artifactId>springartifactId>

                    exclusion>

                    <exclusion>

                        <groupId>org.jboss.nettygroupId>

                        <artifactId>nettyartifactId>

                    exclusion>

                exclusions>

            dependency>

            <dependency>

                <groupId>org.apache.zookeepergroupId>

                <artifactId>zookeeperartifactId>

            dependency>

            <dependency>

                <groupId>com.github.sgroschupfgroupId>

                <artifactId>zkclientartifactId>

            dependency>

            

            <dependency>

                <groupId>redis.clientsgroupId>

                <artifactId>jedisartifactId>

            dependency>

        dependencies>

    project>

     

    1. 框架整合

    SSO单点登录系统原理分析及功能实现_第16张图片

     

    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.0modelVersion>

        <parent>

            <groupId>com.taotaogroupId>

            <artifactId>taotao-parentartifactId>

            <version>0.0.1-SNAPSHOTversion>

        parent>

        <groupId>com.taotaogroupId>

        <artifactId>taotao-sso-webartifactId>

        <version>0.0.1-SNAPSHOTversion>

        <packaging>warpackaging>

        <dependencies>

            <dependency>

                <groupId>com.taotaogroupId>

                <artifactId>taotao-sso-interfaceartifactId>

                <version>0.0.1-SNAPSHOTversion>

            dependency>

            

            <dependency>

                <groupId>org.springframeworkgroupId>

                <artifactId>spring-contextartifactId>

            dependency>

            <dependency>

                <groupId>org.springframeworkgroupId>

                <artifactId>spring-beansartifactId>

            dependency>

            <dependency>

                <groupId>org.springframeworkgroupId>

                <artifactId>spring-webmvcartifactId>

            dependency>

            <dependency>

                <groupId>org.springframeworkgroupId>

                <artifactId>spring-jdbcartifactId>

            dependency>

            <dependency>

                <groupId>org.springframeworkgroupId>

                <artifactId>spring-aspectsartifactId>

            dependency>

            <dependency>

                <groupId>org.springframeworkgroupId>

                <artifactId>spring-jmsartifactId>

            dependency>

            <dependency>

                <groupId>org.springframeworkgroupId>

                <artifactId>spring-context-supportartifactId>

            dependency>

            

            <dependency>

                <groupId>jstlgroupId>

                <artifactId>jstlartifactId>

            dependency>

            <dependency>

                <groupId>javax.servletgroupId>

                <artifactId>servlet-apiartifactId>

                <scope>providedscope>

            dependency>

            <dependency>

                <groupId>javax.servletgroupId>

                <artifactId>jsp-apiartifactId>

                <scope>providedscope>

            dependency>

            

            <dependency>

                <groupId>com.alibabagroupId>

                <artifactId>dubboartifactId>

                

                <exclusions>

                    <exclusion>

                        <groupId>org.springframeworkgroupId>

                        <artifactId>springartifactId>

                    exclusion>

                    <exclusion>

                        <groupId>org.jboss.nettygroupId>

                        <artifactId>nettyartifactId>

                    exclusion>

                exclusions>

            dependency>

            <dependency>

                <groupId>org.apache.zookeepergroupId>

                <artifactId>zookeeperartifactId>

            dependency>

            <dependency>

                <groupId>com.github.sgroschupfgroupId>

                <artifactId>zkclientartifactId>

            dependency>

            <dependency>

                <groupId>junitgroupId>

                <artifactId>junitartifactId>

            dependency>

        dependencies>

        

        <build>

            <plugins>

                <plugin>

                    <groupId>org.apache.tomcat.mavengroupId>

                    <artifactId>tomcat7-maven-pluginartifactId>

                    <configuration>

                        <port>8088port>

                        <path>/path>

                    configuration>

                plugin>

            plugins>

        build>

    project>

     

    SSO单点登录系统原理分析及功能实现_第17张图片

你可能感兴趣的:(项目实战)