Max-maker-gif преди 4 години
ревизия
f155194784
променени са 44 файла, в които са добавени 1447 реда и са изтрити 0 реда
  1. 2 0
      SSODemo/.idea/.gitignore
  2. 13 0
      SSODemo/.idea/artifacts/SSOAuth_war_exploded.xml
  3. 13 0
      SSODemo/.idea/artifacts/SSODemo_war_exploded.xml
  4. 13 0
      SSODemo/.idea/artifacts/SSOWebDemo01_war_exploded.xml
  5. 13 0
      SSODemo/.idea/artifacts/SSOWebDemo02_war_exploded.xml
  6. 6 0
      SSODemo/.idea/encodings.xml
  7. 6 0
      SSODemo/.idea/misc.xml
  8. 11 0
      SSODemo/.idea/modules.xml
  9. 6 0
      SSODemo/.idea/vcs.xml
  10. 36 0
      SSODemo/SSOAuth/SSOAuth.iml
  11. 164 0
      SSODemo/SSOAuth/src/com/hei/servlet/AuthServlet.java
  12. BIN
      SSODemo/SSOAuth/web/WEB-INF/classes/com/hei/servlet/AuthServlet.class
  13. 33 0
      SSODemo/SSOAuth/web/WEB-INF/web.xml
  14. 134 0
      SSODemo/SSOAuth/web/image.jsp
  15. 16 0
      SSODemo/SSOAuth/web/index.jsp
  16. 1 0
      SSODemo/SSOAuth/web/js/jquery/jquery-1.7.2.min.js
  17. 140 0
      SSODemo/SSOAuth/web/login.jsp
  18. 23 0
      SSODemo/SSODemo.iml
  19. 36 0
      SSODemo/SSOWebDemo01/SSOWebDemo01.iml
  20. 31 0
      SSODemo/SSOWebDemo01/web/WEB-INF/web.xml
  21. 61 0
      SSODemo/SSOWebDemo01/web/index.jsp
  22. 1 0
      SSODemo/SSOWebDemo01/web/js/jquery/jquery-1.7.2.min.js
  23. 16 0
      SSODemo/SSOWebDemo01/web/test.jsp
  24. 36 0
      SSODemo/SSOWebDemo02/SSOWebDemo02.iml
  25. 28 0
      SSODemo/SSOWebDemo02/web/WEB-INF/web.xml
  26. 61 0
      SSODemo/SSOWebDemo02/web/index.jsp
  27. 1 0
      SSODemo/SSOWebDemo02/web/js/jquery/jquery-1.7.2.min.js
  28. BIN
      SSODemo/out/artifacts/SSOAuth_war_exploded/WEB-INF/classes/com/hei/servlet/AuthServlet.class
  29. BIN
      SSODemo/out/artifacts/SSOAuth_war_exploded/WEB-INF/classes/org/servlet/AuthServlet.class
  30. 33 0
      SSODemo/out/artifacts/SSOAuth_war_exploded/WEB-INF/web.xml
  31. 134 0
      SSODemo/out/artifacts/SSOAuth_war_exploded/image.jsp
  32. 16 0
      SSODemo/out/artifacts/SSOAuth_war_exploded/index.jsp
  33. 1 0
      SSODemo/out/artifacts/SSOAuth_war_exploded/js/jquery/jquery-1.7.2.min.js
  34. 1 0
      SSODemo/out/artifacts/SSOAuth_war_exploded/js/jquery/jquery-3.2.1.min.js
  35. 140 0
      SSODemo/out/artifacts/SSOAuth_war_exploded/login.jsp
  36. 31 0
      SSODemo/out/artifacts/SSOWebDemo01_war_exploded/WEB-INF/web.xml
  37. 61 0
      SSODemo/out/artifacts/SSOWebDemo01_war_exploded/index.jsp
  38. 1 0
      SSODemo/out/artifacts/SSOWebDemo01_war_exploded/js/jquery/jquery-1.7.2.min.js
  39. 16 0
      SSODemo/out/artifacts/SSOWebDemo01_war_exploded/test.jsp
  40. 28 0
      SSODemo/out/artifacts/SSOWebDemo02_war_exploded/WEB-INF/web.xml
  41. 61 0
      SSODemo/out/artifacts/SSOWebDemo02_war_exploded/index.jsp
  42. 1 0
      SSODemo/out/artifacts/SSOWebDemo02_war_exploded/js/jquery/jquery-1.7.2.min.js
  43. 6 0
      SSODemo/web/WEB-INF/web.xml
  44. 16 0
      SSODemo/web/index.jsp

+ 2 - 0
SSODemo/.idea/.gitignore

@@ -0,0 +1,2 @@
+# Default ignored files
+/workspace.xml

+ 13 - 0
SSODemo/.idea/artifacts/SSOAuth_war_exploded.xml

@@ -0,0 +1,13 @@
+<component name="ArtifactManager">
+  <artifact type="exploded-war" name="SSOAuth:war exploded">
+    <output-path>$PROJECT_DIR$/out/artifacts/SSOAuth_war_exploded</output-path>
+    <root id="root">
+      <element id="javaee-facet-resources" facet="SSOAuth/web/Web" />
+      <element id="directory" name="WEB-INF">
+        <element id="directory" name="classes">
+          <element id="module-output" name="SSOAuth" />
+        </element>
+      </element>
+    </root>
+  </artifact>
+</component>

+ 13 - 0
SSODemo/.idea/artifacts/SSODemo_war_exploded.xml

@@ -0,0 +1,13 @@
+<component name="ArtifactManager">
+  <artifact type="exploded-war" name="SSODemo:war exploded">
+    <output-path>$PROJECT_DIR$/out/artifacts/SSODemo_war_exploded</output-path>
+    <root id="root">
+      <element id="javaee-facet-resources" facet="SSODemo/web/Web" />
+      <element id="directory" name="WEB-INF">
+        <element id="directory" name="classes">
+          <element id="module-output" name="SSODemo" />
+        </element>
+      </element>
+    </root>
+  </artifact>
+</component>

+ 13 - 0
SSODemo/.idea/artifacts/SSOWebDemo01_war_exploded.xml

@@ -0,0 +1,13 @@
+<component name="ArtifactManager">
+  <artifact type="exploded-war" name="SSOWebDemo01:war exploded">
+    <output-path>$PROJECT_DIR$/out/artifacts/SSOWebDemo01_war_exploded</output-path>
+    <root id="root">
+      <element id="javaee-facet-resources" facet="SSOWebDemo01/web/Web" />
+      <element id="directory" name="WEB-INF">
+        <element id="directory" name="classes">
+          <element id="module-output" name="SSOWebDemo01" />
+        </element>
+      </element>
+    </root>
+  </artifact>
+</component>

+ 13 - 0
SSODemo/.idea/artifacts/SSOWebDemo02_war_exploded.xml

@@ -0,0 +1,13 @@
+<component name="ArtifactManager">
+  <artifact type="exploded-war" name="SSOWebDemo02:war exploded">
+    <output-path>$PROJECT_DIR$/out/artifacts/SSOWebDemo02_war_exploded</output-path>
+    <root id="root">
+      <element id="javaee-facet-resources" facet="SSOWebDemo02/web/Web" />
+      <element id="directory" name="WEB-INF">
+        <element id="directory" name="classes">
+          <element id="module-output" name="SSOWebDemo02" />
+        </element>
+      </element>
+    </root>
+  </artifact>
+</component>

+ 6 - 0
SSODemo/.idea/encodings.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="Encoding">
+    <file url="file://$PROJECT_DIR$/SSOAuth/src/com/hei/servlet/AuthServlet.java" charset="GBK" />
+  </component>
+</project>

+ 6 - 0
SSODemo/.idea/misc.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
+    <output url="file://$PROJECT_DIR$/out" />
+  </component>
+</project>

+ 11 - 0
SSODemo/.idea/modules.xml

@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="ProjectModuleManager">
+    <modules>
+      <module fileurl="file://$PROJECT_DIR$/SSOAuth/SSOAuth.iml" filepath="$PROJECT_DIR$/SSOAuth/SSOAuth.iml" />
+      <module fileurl="file://$PROJECT_DIR$/SSODemo.iml" filepath="$PROJECT_DIR$/SSODemo.iml" />
+      <module fileurl="file://$PROJECT_DIR$/SSOWebDemo01/SSOWebDemo01.iml" filepath="$PROJECT_DIR$/SSOWebDemo01/SSOWebDemo01.iml" />
+      <module fileurl="file://$PROJECT_DIR$/SSOWebDemo02/SSOWebDemo02.iml" filepath="$PROJECT_DIR$/SSOWebDemo02/SSOWebDemo02.iml" />
+    </modules>
+  </component>
+</project>

+ 6 - 0
SSODemo/.idea/vcs.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="VcsDirectoryMappings">
+    <mapping directory="$PROJECT_DIR$/.." vcs="Git" />
+  </component>
+</project>

+ 36 - 0
SSODemo/SSOAuth/SSOAuth.iml

@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module type="JAVA_MODULE" version="4">
+  <component name="FacetManager">
+    <facet type="web" name="Web">
+      <configuration>
+        <descriptors>
+          <deploymentDescriptor name="web.xml" url="file://$MODULE_DIR$/web/WEB-INF/web.xml" />
+        </descriptors>
+        <webroots>
+          <root url="file://$MODULE_DIR$/web" relative="/" />
+        </webroots>
+      </configuration>
+    </facet>
+  </component>
+  <component name="NewModuleRootManager">
+    <output url="file://$MODULE_DIR$/web/WEB-INF/classes" />
+    <output-test url="file://$MODULE_DIR$/web/WEB-INF/classes" />
+    <exclude-output />
+    <content url="file://$MODULE_DIR$">
+      <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
+    </content>
+    <orderEntry type="jdk" jdkName="1.8" jdkType="JavaSDK" />
+    <orderEntry type="sourceFolder" forTests="false" />
+    <orderEntry type="module-library">
+      <library>
+        <CLASSES>
+          <root url="file://$MODULE_DIR$/web/WEB-INF/lib" />
+        </CLASSES>
+        <JAVADOC />
+        <SOURCES />
+        <jarDirectory url="file://$MODULE_DIR$/web/WEB-INF/lib" recursive="false" />
+      </library>
+    </orderEntry>
+    <orderEntry type="library" scope="PROVIDED" name="tomcat9-8888" level="application_server_libraries" />
+  </component>
+</module>

+ 164 - 0
SSODemo/SSOAuth/src/com/hei/servlet/AuthServlet.java

@@ -0,0 +1,164 @@
+package com.hei.servlet;
+
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletException;
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+
+/**
+ * SSOAuth:统一认证中心
+ *
+ * 本类实现简单的实现验证操作
+ *
+ * @author mincong
+ */
+public class AuthServlet extends HttpServlet {
+
+    /**
+     * 调用父类的构造方法
+     */
+    public AuthServlet() {
+        super();
+    }
+
+    /**
+     * 调用父类的销毁方法
+     */
+    public void destroy() {
+        super.destroy();
+    }
+
+    /**
+     * servlet的doGet方法
+     * 当表单的标签值方法等于get时,将调用此方法。
+     *
+     * @param request  由客户端发送到服务器的请求
+     * @param response 由服务器发送到客户端的响应
+     * @throws ServletException 如果发生错误
+     * @throws IOException      如果发生错误
+     */
+    public void doGet(HttpServletRequest request, HttpServletResponse response)
+            throws ServletException, IOException {
+
+        doPost(request, response);
+    }
+
+    /**
+     * servlet的doPost方法。
+     * 当表单的标签值方法等于post时,调用此方法
+     *
+     * @param request  由客户端发送到服务器的请求
+     * @param response 由服务器发送到客户端的响应
+     * @throws ServletException 如果发生错误
+     * @throws IOException      如果发生错误
+     */
+    public void doPost(HttpServletRequest request, HttpServletResponse response)
+            throws ServletException, IOException {
+        // 解决中文乱码问题
+        request.setCharacterEncoding("UTF-8");
+        response.setCharacterEncoding("UTF-8");
+
+        System.out.println("进入servlet了");
+        /**
+         * DomainName和CookName这2个参数在web.xml的context-param标签中定义
+         * 校验是否请求登录了,然后存到Cookie那里
+         */
+        DomainName = request.getSession().getServletContext().getInitParameter("DomainName");
+        CookName = request.getSession().getServletContext().getInitParameter("CookieName");
+
+        System.out.println("---------" + DomainName + "----------------跳转了-------------" + CookName + "----------------");
+
+        // 定义登录页面
+        String location = request.getContextPath() + "/login.jsp";
+        // 获取随机生成的附加码
+        String ccode = (String) request.getSession().getAttribute("rand");
+        // 获取我们输入的附加码
+        String checkcode = request.getParameter("checkcode");
+
+        System.out.println("ccode:" + ccode + ", checkcode:" + checkcode);
+
+        // 接收“goto”这个参数来保存用户最初访问的URL:登录失败时暂存,登录成功时调用此url
+        String gotoURL = request.getParameter("goto");
+        System.out.println("gotoURL:" + gotoURL);
+
+        // 判断附加码是否相等
+        // 附加码不等,重定向到认证系统
+        if (!checkcode.equals(ccode)) {
+            response.sendRedirect(gotoURL);
+            System.out.println("error1");
+        } else {
+            // 附加码相等,判断登录账户是否正确
+            System.out.println("success1");
+            // 获取用户输入的用户名
+            String username = request.getParameter("username");
+            // 获取用户输入的密码
+            String userpassword = request.getParameter("userpassword");
+            // 根据预先设定好的用户集合(accounts)的用户名获取对应的密码
+            String key = accounts.get(username);
+            // 密码为空,重定向到认证系统
+            if (key == null) {
+                response.sendRedirect(gotoURL);
+            } else {
+                // 密码不为空,判断密码是否相等
+                // 如果密码相等,保存sessionId到Cookie便于实现SSO
+                if (key.equals(userpassword)) {
+                    String sessionId = request.getSession().getId();
+                    // 新建Cookie,将用户的信息存进cookie中
+                    Cookie cookie = new Cookie(CookName, sessionId);
+                    //设置Cookie最大生存时间,单位:秒
+                    // 设置Cookie路径 如果不使用这个方法或者参数为负数的话,当浏览器关闭的时候,这个cookie就失效了。
+                    cookie.setMaxAge(100);
+                    // 让所有访问地址以path开头的servlet共享该cookie,即这种情况下浏览器都可以访问该cookie
+                    cookie.setPath("/");
+                    // 将Cookie添加到Response中,使之生效
+                    response.addCookie(cookie);
+                    // 如果用户最初想访问的URL不为空,则登陆成功,跳转到主页面
+                    if (gotoURL != null) {
+                        System.out.println("gotoURL:" + gotoURL);
+                        response.sendRedirect(gotoURL);
+                        System.out.println("登录成功!!!!" + cookie + "----------------" + sessionId);
+                    } else {
+                     //   如果用户最初想访问的URL为空,重定向到认证系统
+                        response.sendRedirect(location);
+                    }
+                } else {
+                    // 如果密码不相等,重定向到认证系统
+                    response.sendRedirect(location);
+                }
+            }
+        }
+    }
+
+
+    /**
+     * 声明用户账号数组
+     */
+    static private ConcurrentMap<String, String> accounts;
+    /**
+     * 保留sessionId的Cookie
+     */
+    String CookName;
+    /**
+     * 域名
+     */
+    String DomainName;
+    /**
+     * 初始化Servlet时,给系统添加了三个合法的用户
+     * init()方法:当servlet第一次被创建才会调用,整个生命周期内仅调用一次。
+     * @param config  初始化参数
+     * @throws ServletException  如果发生错误
+     */
+    @Override
+    public void init(ServletConfig config) throws ServletException {
+        accounts = new ConcurrentHashMap<String, String>();
+        accounts.put("joylife", "123456");
+        accounts.put("admin", "123456");
+        accounts.put("json", "123456");
+    }
+
+}

BIN
SSODemo/SSOAuth/web/WEB-INF/classes/com/hei/servlet/AuthServlet.class


+ 33 - 0
SSODemo/SSOAuth/web/WEB-INF/web.xml

@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
+         version="4.0">
+    <servlet>
+        <description>This is the description of my J2EE component</description>
+        <display-name>This is the display name of my J2EE component</display-name>
+        <servlet-name>AuthServlet</servlet-name>
+        <servlet-class>com.hei.servlet.AuthServlet</servlet-class>
+    </servlet>
+    <servlet-mapping>
+        <servlet-name>AuthServlet</servlet-name>
+        <url-pattern>/AuthServlet.do</url-pattern>
+    </servlet-mapping>
+    <!--    认证系统域名-->
+    <context-param>
+        <param-name>DomainName</param-name>
+        <param-value>localhost</param-value>
+    </context-param>
+    <!--    认证系统名称-->
+    <context-param>
+        <param-name>CookieName</param-name>
+        <param-value>XiaoHaibingDesktopSSOID</param-value>
+    </context-param>
+    <!--
+        welcome-file-list是一个配置在web.xml中的一个欢迎页,
+        用于当用户在url中输入工程名称或者输入web容器url(如http://localhost:8888/)时直接跳转的页面.
+    -->
+    <welcome-file-list>
+        <welcome-file>index.jsp</welcome-file>
+    </welcome-file-list>
+</web-app>

+ 134 - 0
SSODemo/SSOAuth/web/image.jsp

@@ -0,0 +1,134 @@
+<%@ page  pageEncoding = "gb2312" contentType="image/jpeg" import = "javax.imageio.*,java.util.*,java.awt.image.*,java.awt.*" %>
+
+<%!
+
+    //在此处 获取并生成随机颜色
+
+    Color getRandColor(Random random, int ff, int cc) {
+
+        if (ff > 255)
+
+            ff = 255;
+
+        if (cc > 255)
+
+            cc = 255;
+
+        int r = ff + random.nextInt(cc - ff);
+
+        int g = ff + random.nextInt(cc - ff);
+
+        int b = ff + random.nextInt(cc - ff);
+
+        return new Color(r, g, b);
+
+    } %>
+
+<%
+
+    //在此处 设置JSP页面无缓存
+
+    response.setHeader( "Pragma" , "No-cache" );
+
+    response.setHeader( "Cache-Control" , "no-cache" );
+
+    response.setDateHeader( "Expires" , 0);
+
+    // 设置图片的长宽
+
+    int width = 130;
+    int height = 30;
+
+    //设定被随机选取的中文字,此处中文字内容过多,不一一列出,只是举例说明下。
+    String base = "\u9752\u534a\u706b\u6cd5\u9898\u5efa\u8d76\u4f4d\u5531\u6d77\u4e03\u5973\u4efb\u4ef6\u611f\u51c6\u97f3\u7b54\u54e5\u9645\u65e7\u795e\u5ea7\u7ae0\u538b\u6162\u53d4\u80cc\u7ec6" ;
+
+    //设置 备选随机汉字的个数
+
+    int length = base.length();
+
+    // 创建缓存图像
+
+    BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
+
+    // 获取图像
+    Graphics g = image.getGraphics();
+
+    // 创建随机函数的实例
+
+    Random random = new Random();
+
+    //此处 设定图像背景色
+
+    g.setColor(getRandColor(random, 188, 235));
+
+    g.fillRect(0, 0, width, height);
+
+    //设置随机 备选的字体类型
+
+    String[] fontTypes = { "\u5b8b\u4f53" , "\u65b0\u5b8b\u4f53" ,
+
+            "\u9ed1\u4f53" , "\u6977\u4f53" , "\u96b6\u4e66" };
+
+    int fontTypesLength = fontTypes.length;
+
+    // 在图片背景上增加噪点,增加图片分析难度
+
+    g.setColor(getRandColor(random, 180, 199));
+
+    g.setFont( new Font( "Times New Roman" , Font.PLAIN, 14));
+
+    for ( int i = 0; i < 4; i++) {
+
+        g.drawString( "@*@*@*@*@*@*@*" ,
+
+                0, 5 * (i + 2));
+
+    }
+
+    // 取随机产生的验证码 (4 个汉字 )
+
+    // 保存生成的汉字字符串
+
+    String sRand = "" ;
+
+    for ( int i = 0; i < 4; i++) {
+
+        int start = random.nextInt(length);
+
+        String rand = base.substring(start, start + 1);
+
+        sRand += rand;
+
+        // 设置图片上字体的颜色
+
+        g.setColor(getRandColor(random, 10, 150));
+
+        // 设置字体格式
+
+        g.setFont( new Font(fontTypes[random.nextInt(fontTypesLength)],
+
+                Font.BOLD, 18 + random.nextInt(6)));
+
+        // 将此汉字画到验证图片上面
+
+        g.drawString(rand, 24 * i + 10 + random.nextInt(8), 24);
+
+    }
+
+    // 将验证码存入Session中
+
+    session.setAttribute( "rand" , sRand);
+
+    g.dispose();
+
+    //将 图象输出到JSP页面中
+
+    ImageIO.write(image, "JPEG" , response.getOutputStream());
+
+    //关闭流
+
+    out.clear();
+
+    out=pageContext.pushBody();
+
+%>

+ 16 - 0
SSODemo/SSOAuth/web/index.jsp

@@ -0,0 +1,16 @@
+<%--
+  Created by IntelliJ IDEA.
+  User: Administrator
+  Date: 2020/12/21
+  Time: 19:59
+  To change this template use File | Settings | File Templates.
+--%>
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+<html>
+  <head>
+    <title>$Title$</title>
+  </head>
+  <body>
+  SSOAuth
+  </body>
+</html>

Файловите разлики са ограничени, защото са твърде много
+ 1 - 0
SSODemo/SSOAuth/web/js/jquery/jquery-1.7.2.min.js


+ 140 - 0
SSODemo/SSOAuth/web/login.jsp

@@ -0,0 +1,140 @@
+<%@ page language="java" pageEncoding="UTF-8"%>
+
+<%
+    String path = request.getContextPath();
+    String url =request.getParameter("goto");
+%>
+
+<%
+    response.setHeader("Pragma","No-cache");
+    response.setHeader("Cache-Control","no-cache");
+    response.setDateHeader("Expires", 0);
+%>
+
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+<head>
+    <title>系统登录界面</title>
+    <script type="text/javascript" src="<%=path %>/js/jquery/jquery-1.7.2.min.js"></script>
+    <style type="text/css">
+        body {
+            font: normal 11px "Trebuchet MS", Verdana, Arial, Helvetica,sans-serif;
+            color: #4f6b72;/*background: #E6EAE9;*/
+        }
+        table {
+            margin-top: 10%;
+            margin-left: 30%;
+            border: 1px solid #CCCCFF;
+        }
+        table td {
+            border: 0px solid #CCCCFF;
+            font: bold 12px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
+            color: #000000;
+        }
+        table input {
+            width: 180px;
+        }
+        .leftTd {
+            text-align: right;
+            width: 35%;
+        }
+        .centerTd {
+            text-align: center;
+            font: bold 18px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
+            color: #000000;
+        }
+        .rightTd {
+            text-align: left;
+            width: 65%;
+        }
+        #btn_ok{
+            width: 50px;
+        }
+        #btn_clear{
+            width: 50px;
+        }
+        a{
+            margin:30px;
+        }
+    </style>
+
+    <script type="text/javascript">
+        $(function(){
+            $("#btn_reload").bind("click",function(){
+                btn_reload();
+            });
+            $("#btn_clear").bind("click",function(){
+                btn_clear();
+            });
+            $("#btn_ok").bind("click",function(){
+                btn_ok();
+            });
+        });
+
+        function btn_ok(){
+            console.log("点击登录1")
+            var result =validateform();
+            if(!result){
+                return ;
+            }
+            $("#form").attr("action","/SSOAuth/AuthServlet.do");
+            $("#form").submit();
+        }
+
+        function btn_reload(){
+            $("#image").removeAttr("src");
+            $("#image").attr("src", "<%=path%>/image.jsp?random()*1000");
+        }
+
+        function btn_clear(){
+            $(":input").not("input[type=button]").each(function(){
+                $(this).val("");
+            });
+        }
+
+        function validateform(){
+            var result =true;
+            $(":input").not("input[type=button]").each(function(){
+                if($(this).val() ==""){
+                    result=false;
+                }
+            });
+            return result ;
+        }
+    </script>
+</head>
+<body>
+<form id="form" action="login.jsp" method="post">
+    <table>
+        <tbody>
+        <tr>
+            <td colspan="99" class="centerTd">用户信息登录 </td>
+        </tr>
+        <tr>
+            <td class="leftTd"><label>用户名</label></td>
+            <td class="rightTd"><input type="text" name="username" /></td>
+        </tr>
+        <tr>
+            <td class="leftTd"><label>密码</label></td>
+            <td class="rightTd"><input type="password" name="userpassword" /></td>
+        </tr>
+        <tr>
+            <td class="leftTd"><label>验证码</label></td>
+            <td class="rightTd"><input type="text" name="checkcode" />
+                <img src="<%=path%>/image.jsp"id="image" />
+            </td>
+        </tr>
+        <tr >
+            <td class="leftTd"><input type="button" id="btn_ok" value="登录" /></td>
+            <td class="rightTd"><input type="button" id="btn_clear" value="重置" />
+                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+                <a href ="javascript:void(0);" id="btn_reload">看不清,换一张</a>
+            </td>
+        </tr>
+        </tbody>
+    </table>
+    <input name="goto" type="hidden" value=<%=url%>/>
+</form>
+</body>
+</html>
+

+ 23 - 0
SSODemo/SSODemo.iml

@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module type="JAVA_MODULE" version="4">
+  <component name="FacetManager">
+    <facet type="web" name="Web">
+      <configuration>
+        <descriptors>
+          <deploymentDescriptor name="web.xml" url="file://$MODULE_DIR$/web/WEB-INF/web.xml" />
+        </descriptors>
+        <webroots>
+          <root url="file://$MODULE_DIR$/web" relative="/" />
+        </webroots>
+      </configuration>
+    </facet>
+  </component>
+  <component name="NewModuleRootManager" inherit-compiler-output="true">
+    <exclude-output />
+    <content url="file://$MODULE_DIR$">
+      <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
+    </content>
+    <orderEntry type="inheritedJdk" />
+    <orderEntry type="sourceFolder" forTests="false" />
+  </component>
+</module>

+ 36 - 0
SSODemo/SSOWebDemo01/SSOWebDemo01.iml

@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module type="JAVA_MODULE" version="4">
+  <component name="FacetManager">
+    <facet type="web" name="Web">
+      <configuration>
+        <descriptors>
+          <deploymentDescriptor name="web.xml" url="file://$MODULE_DIR$/web/WEB-INF/web.xml" />
+        </descriptors>
+        <webroots>
+          <root url="file://$MODULE_DIR$/web" relative="/" />
+        </webroots>
+      </configuration>
+    </facet>
+  </component>
+  <component name="NewModuleRootManager">
+    <output url="file://$MODULE_DIR$/web/WEB-INF/classes" />
+    <output-test url="file://$MODULE_DIR$/web/WEB-INF/classes" />
+    <exclude-output />
+    <content url="file://$MODULE_DIR$">
+      <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
+    </content>
+    <orderEntry type="jdk" jdkName="1.8" jdkType="JavaSDK" />
+    <orderEntry type="sourceFolder" forTests="false" />
+    <orderEntry type="module-library">
+      <library>
+        <CLASSES>
+          <root url="file://$MODULE_DIR$/web/WEB-INF/lib" />
+        </CLASSES>
+        <JAVADOC />
+        <SOURCES />
+        <jarDirectory url="file://$MODULE_DIR$/web/WEB-INF/lib" recursive="false" />
+      </library>
+    </orderEntry>
+    <orderEntry type="library" scope="PROVIDED" name="tomcat9-8888" level="application_server_libraries" />
+  </component>
+</module>

+ 31 - 0
SSODemo/SSOWebDemo01/web/WEB-INF/web.xml

@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<web-app version="2.5"
+         xmlns="http://java.sun.com/xml/ns/javaee"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
+    http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
+    <!--
+        welcome-file-list是一个配置在web.xml中的一个欢迎页,
+        用于当用户在url中输入工程名称或者输入web容器url(如http://localhost:8080/)时直接跳转的页面.
+    -->
+    <welcome-file-list>
+        <welcome-file>index.jsp</welcome-file>
+    </welcome-file-list>
+
+    <!--    认证系统名称-->
+    <context-param>
+        <param-name>CookieName</param-name>
+        <param-value>
+            XiaohaibingDesktopSSOID
+        </param-value>
+    </context-param>
+
+    <!--    认证系统身份服务-->
+    <context-param>
+        <param-name>SSOLoginPage</param-name>
+        <param-value>
+            http://localhost:8888/SSOAuth/login.jsp
+        </param-value>
+    </context-param>
+
+</web-app>

+ 61 - 0
SSODemo/SSOWebDemo01/web/index.jsp

@@ -0,0 +1,61 @@
+<%@ page language="java" pageEncoding="UTF-8" %>
+
+<%
+    /**
+     *  获取认证系统身份服务
+     *     身份服务是用来保护其他应用服务的, 用户一般在访问一个受SSOAuth保护的Web应用的某个URL时,
+     *     当前这个应用会发现当前的用户还没有登录,便强制将页面转向SSOAuth的login.jsp,让用户登录
+     */
+    String SSOLoginPage = request.getSession().getServletContext().getInitParameter("SSOLoginPage");
+    /**
+     * 获取认证系统名称
+     */
+    String CookieName = request.getSession().getServletContext().getInitParameter("CookieName");
+    CookieName = CookieName.toLowerCase().trim();
+    /**
+     * 获取cookie:客户端的用户信息
+     */
+    Cookie[] cookies = request.getCookies();
+    /**
+     * 获取登录标记,期望的cookie值
+     */
+    Cookie loginCookie = null;
+    String cookname = "";
+    /**
+     * 如果获取到的cookie不为空,进行cookie的校验
+     */
+    if (cookies != null) {
+        for (Cookie cookie : cookies) {
+            cookname = cookie.getName().trim().toLowerCase();
+            if (CookieName.equals(cookname)) {
+                loginCookie = cookie;
+                break;
+            }
+        }
+    }
+    /**
+     * 如果cookie中没有用户登录信息,需要跳转到登录页面去登录
+     */
+    if (loginCookie == null) {
+        String url = request.getRequestURL().toString();
+        response.sendRedirect(SSOLoginPage + "?goto=" + url);
+    }
+%>
+
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+<head>
+    <title>ssowebdemo1</title>
+    <%--在此处,设置jsp无缓存    可以使你再次进入曾经访问过的页面时,浏览器必须从服务端下载最新的内容,达到刷新的效果--%>
+    <meta http-equiv="pragma" content="no-cache">
+    <meta http-equiv="cache-control" content="no-cache">
+    <meta http-equiv="expires" content="0">
+    <%--搜索关键字  就是用搜索引擎搜索的时候 会和这个关键字匹配 从而找到你的网站--%>
+    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
+    <%--用来告诉搜索引擎你的网站主要内容--%>
+    <meta http-equiv="description" content="This is my page">
+</head>
+<body>
+<h1 align="center">WELCOME SsoWebDemo1 !</h1>
+</body>
+</html>

Файловите разлики са ограничени, защото са твърде много
+ 1 - 0
SSODemo/SSOWebDemo01/web/js/jquery/jquery-1.7.2.min.js


+ 16 - 0
SSODemo/SSOWebDemo01/web/test.jsp

@@ -0,0 +1,16 @@
+<%--
+  Created by IntelliJ IDEA.
+  User: Administrator
+  Date: 2020/12/24
+  Time: 22:27
+  To change this template use File | Settings | File Templates.
+--%>
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+<html>
+<head>
+    <title>Title</title>
+</head>
+<body>
+TEST
+</body>
+</html>

+ 36 - 0
SSODemo/SSOWebDemo02/SSOWebDemo02.iml

@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module type="JAVA_MODULE" version="4">
+  <component name="FacetManager">
+    <facet type="web" name="Web">
+      <configuration>
+        <descriptors>
+          <deploymentDescriptor name="web.xml" url="file://$MODULE_DIR$/web/WEB-INF/web.xml" />
+        </descriptors>
+        <webroots>
+          <root url="file://$MODULE_DIR$/web" relative="/" />
+        </webroots>
+      </configuration>
+    </facet>
+  </component>
+  <component name="NewModuleRootManager">
+    <output url="file://$MODULE_DIR$/web/WEB-INF/classes" />
+    <output-test url="file://$MODULE_DIR$/web/WEB-INF/classes" />
+    <exclude-output />
+    <content url="file://$MODULE_DIR$">
+      <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
+    </content>
+    <orderEntry type="jdk" jdkName="1.8" jdkType="JavaSDK" />
+    <orderEntry type="sourceFolder" forTests="false" />
+    <orderEntry type="module-library">
+      <library>
+        <CLASSES>
+          <root url="file://$MODULE_DIR$/web/WEB-INF/lib" />
+        </CLASSES>
+        <JAVADOC />
+        <SOURCES />
+        <jarDirectory url="file://$MODULE_DIR$/web/WEB-INF/lib" recursive="false" />
+      </library>
+    </orderEntry>
+    <orderEntry type="library" scope="PROVIDED" name="tomcat9-8888" level="application_server_libraries" />
+  </component>
+</module>

+ 28 - 0
SSODemo/SSOWebDemo02/web/WEB-INF/web.xml

@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<web-app version="2.5"
+         xmlns="http://java.sun.com/xml/ns/javaee"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
+    http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
+    <!--
+        welcome-file-list是一个配置在web.xml中的一个欢迎页,
+        用于当用户在url中输入工程名称或者输入web容器url(如http://localhost:8080/)时直接跳转的页面.
+    -->
+    <welcome-file-list>
+        <welcome-file>index.jsp</welcome-file>
+    </welcome-file-list>
+    <!--    认证系统名称-->
+    <context-param>
+        <param-name>CookieName</param-name>
+        <param-value>
+            XiaohaibingDesktopSSOID
+        </param-value>
+    </context-param>
+    <!--    认证系统身份服务-->
+    <context-param>
+        <param-name>SSOLoginPage</param-name>
+        <param-value>
+            http://localhost:8888/SSOAuth/login.jsp
+        </param-value>
+    </context-param>
+</web-app>

+ 61 - 0
SSODemo/SSOWebDemo02/web/index.jsp

@@ -0,0 +1,61 @@
+<%@ page language="java"  pageEncoding="UTF-8"%>
+
+<%
+    /**
+     *  获取认证系统身份服务
+     *     身份服务是用来保护其他应用服务的, 用户一般在访问一个受SSOAuth保护的Web应用的某个URL时,
+     *     当前这个应用会发现当前的用户还没有登录,便强制将页面转向SSOAuth的login.jsp,让用户登录
+     */
+    String SSOLoginPage =request.getSession().getServletContext().getInitParameter("SSOLoginPage");
+    /**
+     * 获取认证系统名称
+     */
+    String CookieName =request.getSession().getServletContext().getInitParameter("CookieName");
+    CookieName =CookieName.toLowerCase().trim();
+    /**
+     * 获取cookie:客户端的用户信息
+     */
+    Cookie[] cookies=   request.getCookies();
+    /**
+     * 获取登录标记,期望的cookie值
+     */
+    Cookie loginCookie =null;
+    String cookname ="";
+    /**
+     * 如果获取到的cookie不为空,进行cookie的校验
+     */
+    if(cookies!=null){
+        for(Cookie cookie:cookies){
+            cookname =cookie.getName().trim().toLowerCase();
+            if(CookieName.equals(cookname)){
+                loginCookie =cookie;
+                break;
+            }
+        }
+    }
+    /**
+     * 如果cookie中没有用户登录信息,需要跳转到登录页面去登录
+     */
+    if(loginCookie==null){
+        String url =request.getRequestURL().toString();
+        response.sendRedirect(SSOLoginPage+"?goto="+url);
+    }
+%>
+
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+<head>
+    <title>ssowebdemo2</title>
+    <%--在此处,设置jsp无缓存    可以使你再次进入曾经访问过的页面时,浏览器必须从服务端下载最新的内容,达到刷新的效果--%>
+    <meta http-equiv="pragma" content="no-cache">
+    <meta http-equiv="cache-control" content="no-cache">
+    <meta http-equiv="expires" content="0">
+    <%--搜索关键字  就是用搜索引擎搜索的时候 会和这个关键字匹配 从而找到你的网站--%>
+    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
+    <%--用来告诉搜索引擎你的网站主要内容--%>
+    <meta http-equiv="description" content="This is my page">
+</head>
+<body>
+<h1 align="center">WELCOME SsoWebDemo2 !</h1><br>
+</body>
+</html>

Файловите разлики са ограничени, защото са твърде много
+ 1 - 0
SSODemo/SSOWebDemo02/web/js/jquery/jquery-1.7.2.min.js


BIN
SSODemo/out/artifacts/SSOAuth_war_exploded/WEB-INF/classes/com/hei/servlet/AuthServlet.class


BIN
SSODemo/out/artifacts/SSOAuth_war_exploded/WEB-INF/classes/org/servlet/AuthServlet.class


+ 33 - 0
SSODemo/out/artifacts/SSOAuth_war_exploded/WEB-INF/web.xml

@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
+         version="4.0">
+    <servlet>
+        <description>This is the description of my J2EE component</description>
+        <display-name>This is the display name of my J2EE component</display-name>
+        <servlet-name>AuthServlet</servlet-name>
+        <servlet-class>com.hei.servlet.AuthServlet</servlet-class>
+    </servlet>
+    <servlet-mapping>
+        <servlet-name>AuthServlet</servlet-name>
+        <url-pattern>/AuthServlet.do</url-pattern>
+    </servlet-mapping>
+    <!--    认证系统域名-->
+    <context-param>
+        <param-name>DomainName</param-name>
+        <param-value>localhost</param-value>
+    </context-param>
+    <!--    认证系统名称-->
+    <context-param>
+        <param-name>CookieName</param-name>
+        <param-value>XiaoHaibingDesktopSSOID</param-value>
+    </context-param>
+    <!--
+        welcome-file-list是一个配置在web.xml中的一个欢迎页,
+        用于当用户在url中输入工程名称或者输入web容器url(如http://localhost:8888/)时直接跳转的页面.
+    -->
+    <welcome-file-list>
+        <welcome-file>index.jsp</welcome-file>
+    </welcome-file-list>
+</web-app>

+ 134 - 0
SSODemo/out/artifacts/SSOAuth_war_exploded/image.jsp

@@ -0,0 +1,134 @@
+<%@ page  pageEncoding = "gb2312" contentType="image/jpeg" import = "javax.imageio.*,java.util.*,java.awt.image.*,java.awt.*" %>
+
+<%!
+
+    //在此处 获取并生成随机颜色
+
+    Color getRandColor(Random random, int ff, int cc) {
+
+        if (ff > 255)
+
+            ff = 255;
+
+        if (cc > 255)
+
+            cc = 255;
+
+        int r = ff + random.nextInt(cc - ff);
+
+        int g = ff + random.nextInt(cc - ff);
+
+        int b = ff + random.nextInt(cc - ff);
+
+        return new Color(r, g, b);
+
+    } %>
+
+<%
+
+    //在此处 设置JSP页面无缓存
+
+    response.setHeader( "Pragma" , "No-cache" );
+
+    response.setHeader( "Cache-Control" , "no-cache" );
+
+    response.setDateHeader( "Expires" , 0);
+
+    // 设置图片的长宽
+
+    int width = 130;
+    int height = 30;
+
+    //设定被随机选取的中文字,此处中文字内容过多,不一一列出,只是举例说明下。
+    String base = "\u9752\u534a\u706b\u6cd5\u9898\u5efa\u8d76\u4f4d\u5531\u6d77\u4e03\u5973\u4efb\u4ef6\u611f\u51c6\u97f3\u7b54\u54e5\u9645\u65e7\u795e\u5ea7\u7ae0\u538b\u6162\u53d4\u80cc\u7ec6" ;
+
+    //设置 备选随机汉字的个数
+
+    int length = base.length();
+
+    // 创建缓存图像
+
+    BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
+
+    // 获取图像
+    Graphics g = image.getGraphics();
+
+    // 创建随机函数的实例
+
+    Random random = new Random();
+
+    //此处 设定图像背景色
+
+    g.setColor(getRandColor(random, 188, 235));
+
+    g.fillRect(0, 0, width, height);
+
+    //设置随机 备选的字体类型
+
+    String[] fontTypes = { "\u5b8b\u4f53" , "\u65b0\u5b8b\u4f53" ,
+
+            "\u9ed1\u4f53" , "\u6977\u4f53" , "\u96b6\u4e66" };
+
+    int fontTypesLength = fontTypes.length;
+
+    // 在图片背景上增加噪点,增加图片分析难度
+
+    g.setColor(getRandColor(random, 180, 199));
+
+    g.setFont( new Font( "Times New Roman" , Font.PLAIN, 14));
+
+    for ( int i = 0; i < 4; i++) {
+
+        g.drawString( "@*@*@*@*@*@*@*" ,
+
+                0, 5 * (i + 2));
+
+    }
+
+    // 取随机产生的验证码 (4 个汉字 )
+
+    // 保存生成的汉字字符串
+
+    String sRand = "" ;
+
+    for ( int i = 0; i < 4; i++) {
+
+        int start = random.nextInt(length);
+
+        String rand = base.substring(start, start + 1);
+
+        sRand += rand;
+
+        // 设置图片上字体的颜色
+
+        g.setColor(getRandColor(random, 10, 150));
+
+        // 设置字体格式
+
+        g.setFont( new Font(fontTypes[random.nextInt(fontTypesLength)],
+
+                Font.BOLD, 18 + random.nextInt(6)));
+
+        // 将此汉字画到验证图片上面
+
+        g.drawString(rand, 24 * i + 10 + random.nextInt(8), 24);
+
+    }
+
+    // 将验证码存入Session中
+
+    session.setAttribute( "rand" , sRand);
+
+    g.dispose();
+
+    //将 图象输出到JSP页面中
+
+    ImageIO.write(image, "JPEG" , response.getOutputStream());
+
+    //关闭流
+
+    out.clear();
+
+    out=pageContext.pushBody();
+
+%>

+ 16 - 0
SSODemo/out/artifacts/SSOAuth_war_exploded/index.jsp

@@ -0,0 +1,16 @@
+<%--
+  Created by IntelliJ IDEA.
+  User: Administrator
+  Date: 2020/12/21
+  Time: 19:59
+  To change this template use File | Settings | File Templates.
+--%>
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+<html>
+  <head>
+    <title>$Title$</title>
+  </head>
+  <body>
+  SSOAuth
+  </body>
+</html>

Файловите разлики са ограничени, защото са твърде много
+ 1 - 0
SSODemo/out/artifacts/SSOAuth_war_exploded/js/jquery/jquery-1.7.2.min.js


Файловите разлики са ограничени, защото са твърде много
+ 1 - 0
SSODemo/out/artifacts/SSOAuth_war_exploded/js/jquery/jquery-3.2.1.min.js


+ 140 - 0
SSODemo/out/artifacts/SSOAuth_war_exploded/login.jsp

@@ -0,0 +1,140 @@
+<%@ page language="java" pageEncoding="UTF-8"%>
+
+<%
+    String path = request.getContextPath();
+    String url =request.getParameter("goto");
+%>
+
+<%
+    response.setHeader("Pragma","No-cache");
+    response.setHeader("Cache-Control","no-cache");
+    response.setDateHeader("Expires", 0);
+%>
+
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+<head>
+    <title>系统登录界面</title>
+    <script type="text/javascript" src="<%=path %>/js/jquery/jquery-1.7.2.min.js"></script>
+    <style type="text/css">
+        body {
+            font: normal 11px "Trebuchet MS", Verdana, Arial, Helvetica,sans-serif;
+            color: #4f6b72;/*background: #E6EAE9;*/
+        }
+        table {
+            margin-top: 10%;
+            margin-left: 30%;
+            border: 1px solid #CCCCFF;
+        }
+        table td {
+            border: 0px solid #CCCCFF;
+            font: bold 12px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
+            color: #000000;
+        }
+        table input {
+            width: 180px;
+        }
+        .leftTd {
+            text-align: right;
+            width: 35%;
+        }
+        .centerTd {
+            text-align: center;
+            font: bold 18px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
+            color: #000000;
+        }
+        .rightTd {
+            text-align: left;
+            width: 65%;
+        }
+        #btn_ok{
+            width: 50px;
+        }
+        #btn_clear{
+            width: 50px;
+        }
+        a{
+            margin:30px;
+        }
+    </style>
+
+    <script type="text/javascript">
+        $(function(){
+            $("#btn_reload").bind("click",function(){
+                btn_reload();
+            });
+            $("#btn_clear").bind("click",function(){
+                btn_clear();
+            });
+            $("#btn_ok").bind("click",function(){
+                btn_ok();
+            });
+        });
+
+        function btn_ok(){
+            console.log("点击登录1")
+            var result =validateform();
+            if(!result){
+                return ;
+            }
+            $("#form").attr("action","/SSOAuth/AuthServlet.do");
+            $("#form").submit();
+        }
+
+        function btn_reload(){
+            $("#image").removeAttr("src");
+            $("#image").attr("src", "<%=path%>/image.jsp?random()*1000");
+        }
+
+        function btn_clear(){
+            $(":input").not("input[type=button]").each(function(){
+                $(this).val("");
+            });
+        }
+
+        function validateform(){
+            var result =true;
+            $(":input").not("input[type=button]").each(function(){
+                if($(this).val() ==""){
+                    result=false;
+                }
+            });
+            return result ;
+        }
+    </script>
+</head>
+<body>
+<form id="form" action="login.jsp" method="post">
+    <table>
+        <tbody>
+        <tr>
+            <td colspan="99" class="centerTd">用户信息登录 </td>
+        </tr>
+        <tr>
+            <td class="leftTd"><label>用户名</label></td>
+            <td class="rightTd"><input type="text" name="username" /></td>
+        </tr>
+        <tr>
+            <td class="leftTd"><label>密码</label></td>
+            <td class="rightTd"><input type="password" name="userpassword" /></td>
+        </tr>
+        <tr>
+            <td class="leftTd"><label>验证码</label></td>
+            <td class="rightTd"><input type="text" name="checkcode" />
+                <img src="<%=path%>/image.jsp"id="image" />
+            </td>
+        </tr>
+        <tr >
+            <td class="leftTd"><input type="button" id="btn_ok" value="登录" /></td>
+            <td class="rightTd"><input type="button" id="btn_clear" value="重置" />
+                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+                <a href ="javascript:void(0);" id="btn_reload">看不清,换一张</a>
+            </td>
+        </tr>
+        </tbody>
+    </table>
+    <input name="goto" type="hidden" value=<%=url%>/>
+</form>
+</body>
+</html>
+

+ 31 - 0
SSODemo/out/artifacts/SSOWebDemo01_war_exploded/WEB-INF/web.xml

@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<web-app version="2.5"
+         xmlns="http://java.sun.com/xml/ns/javaee"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
+    http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
+    <!--
+        welcome-file-list是一个配置在web.xml中的一个欢迎页,
+        用于当用户在url中输入工程名称或者输入web容器url(如http://localhost:8080/)时直接跳转的页面.
+    -->
+    <welcome-file-list>
+        <welcome-file>index.jsp</welcome-file>
+    </welcome-file-list>
+
+    <!--    认证系统名称-->
+    <context-param>
+        <param-name>CookieName</param-name>
+        <param-value>
+            XiaohaibingDesktopSSOID
+        </param-value>
+    </context-param>
+
+    <!--    认证系统身份服务-->
+    <context-param>
+        <param-name>SSOLoginPage</param-name>
+        <param-value>
+            http://localhost:8888/SSOAuth/login.jsp
+        </param-value>
+    </context-param>
+
+</web-app>

+ 61 - 0
SSODemo/out/artifacts/SSOWebDemo01_war_exploded/index.jsp

@@ -0,0 +1,61 @@
+<%@ page language="java" pageEncoding="UTF-8" %>
+
+<%
+    /**
+     *  获取认证系统身份服务
+     *     身份服务是用来保护其他应用服务的, 用户一般在访问一个受SSOAuth保护的Web应用的某个URL时,
+     *     当前这个应用会发现当前的用户还没有登录,便强制将页面转向SSOAuth的login.jsp,让用户登录
+     */
+    String SSOLoginPage = request.getSession().getServletContext().getInitParameter("SSOLoginPage");
+    /**
+     * 获取认证系统名称
+     */
+    String CookieName = request.getSession().getServletContext().getInitParameter("CookieName");
+    CookieName = CookieName.toLowerCase().trim();
+    /**
+     * 获取cookie:客户端的用户信息
+     */
+    Cookie[] cookies = request.getCookies();
+    /**
+     * 获取登录标记,期望的cookie值
+     */
+    Cookie loginCookie = null;
+    String cookname = "";
+    /**
+     * 如果获取到的cookie不为空,进行cookie的校验
+     */
+    if (cookies != null) {
+        for (Cookie cookie : cookies) {
+            cookname = cookie.getName().trim().toLowerCase();
+            if (CookieName.equals(cookname)) {
+                loginCookie = cookie;
+                break;
+            }
+        }
+    }
+    /**
+     * 如果cookie中没有用户登录信息,需要跳转到登录页面去登录
+     */
+    if (loginCookie == null) {
+        String url = request.getRequestURL().toString();
+        response.sendRedirect(SSOLoginPage + "?goto=" + url);
+    }
+%>
+
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+<head>
+    <title>ssowebdemo1</title>
+    <%--在此处,设置jsp无缓存    可以使你再次进入曾经访问过的页面时,浏览器必须从服务端下载最新的内容,达到刷新的效果--%>
+    <meta http-equiv="pragma" content="no-cache">
+    <meta http-equiv="cache-control" content="no-cache">
+    <meta http-equiv="expires" content="0">
+    <%--搜索关键字  就是用搜索引擎搜索的时候 会和这个关键字匹配 从而找到你的网站--%>
+    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
+    <%--用来告诉搜索引擎你的网站主要内容--%>
+    <meta http-equiv="description" content="This is my page">
+</head>
+<body>
+<h1 align="center">WELCOME SsoWebDemo1 !</h1>
+</body>
+</html>

Файловите разлики са ограничени, защото са твърде много
+ 1 - 0
SSODemo/out/artifacts/SSOWebDemo01_war_exploded/js/jquery/jquery-1.7.2.min.js


+ 16 - 0
SSODemo/out/artifacts/SSOWebDemo01_war_exploded/test.jsp

@@ -0,0 +1,16 @@
+<%--
+  Created by IntelliJ IDEA.
+  User: Administrator
+  Date: 2020/12/24
+  Time: 22:27
+  To change this template use File | Settings | File Templates.
+--%>
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+<html>
+<head>
+    <title>Title</title>
+</head>
+<body>
+TEST
+</body>
+</html>

+ 28 - 0
SSODemo/out/artifacts/SSOWebDemo02_war_exploded/WEB-INF/web.xml

@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<web-app version="2.5"
+         xmlns="http://java.sun.com/xml/ns/javaee"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
+    http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
+    <!--
+        welcome-file-list是一个配置在web.xml中的一个欢迎页,
+        用于当用户在url中输入工程名称或者输入web容器url(如http://localhost:8080/)时直接跳转的页面.
+    -->
+    <welcome-file-list>
+        <welcome-file>index.jsp</welcome-file>
+    </welcome-file-list>
+    <!--    认证系统名称-->
+    <context-param>
+        <param-name>CookieName</param-name>
+        <param-value>
+            XiaohaibingDesktopSSOID
+        </param-value>
+    </context-param>
+    <!--    认证系统身份服务-->
+    <context-param>
+        <param-name>SSOLoginPage</param-name>
+        <param-value>
+            http://localhost:8888/SSOAuth/login.jsp
+        </param-value>
+    </context-param>
+</web-app>

+ 61 - 0
SSODemo/out/artifacts/SSOWebDemo02_war_exploded/index.jsp

@@ -0,0 +1,61 @@
+<%@ page language="java"  pageEncoding="UTF-8"%>
+
+<%
+    /**
+     *  获取认证系统身份服务
+     *     身份服务是用来保护其他应用服务的, 用户一般在访问一个受SSOAuth保护的Web应用的某个URL时,
+     *     当前这个应用会发现当前的用户还没有登录,便强制将页面转向SSOAuth的login.jsp,让用户登录
+     */
+    String SSOLoginPage =request.getSession().getServletContext().getInitParameter("SSOLoginPage");
+    /**
+     * 获取认证系统名称
+     */
+    String CookieName =request.getSession().getServletContext().getInitParameter("CookieName");
+    CookieName =CookieName.toLowerCase().trim();
+    /**
+     * 获取cookie:客户端的用户信息
+     */
+    Cookie[] cookies=   request.getCookies();
+    /**
+     * 获取登录标记,期望的cookie值
+     */
+    Cookie loginCookie =null;
+    String cookname ="";
+    /**
+     * 如果获取到的cookie不为空,进行cookie的校验
+     */
+    if(cookies!=null){
+        for(Cookie cookie:cookies){
+            cookname =cookie.getName().trim().toLowerCase();
+            if(CookieName.equals(cookname)){
+                loginCookie =cookie;
+                break;
+            }
+        }
+    }
+    /**
+     * 如果cookie中没有用户登录信息,需要跳转到登录页面去登录
+     */
+    if(loginCookie==null){
+        String url =request.getRequestURL().toString();
+        response.sendRedirect(SSOLoginPage+"?goto="+url);
+    }
+%>
+
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+<head>
+    <title>ssowebdemo2</title>
+    <%--在此处,设置jsp无缓存    可以使你再次进入曾经访问过的页面时,浏览器必须从服务端下载最新的内容,达到刷新的效果--%>
+    <meta http-equiv="pragma" content="no-cache">
+    <meta http-equiv="cache-control" content="no-cache">
+    <meta http-equiv="expires" content="0">
+    <%--搜索关键字  就是用搜索引擎搜索的时候 会和这个关键字匹配 从而找到你的网站--%>
+    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
+    <%--用来告诉搜索引擎你的网站主要内容--%>
+    <meta http-equiv="description" content="This is my page">
+</head>
+<body>
+<h1 align="center">WELCOME SsoWebDemo2 !</h1><br>
+</body>
+</html>

Файловите разлики са ограничени, защото са твърде много
+ 1 - 0
SSODemo/out/artifacts/SSOWebDemo02_war_exploded/js/jquery/jquery-1.7.2.min.js


+ 6 - 0
SSODemo/web/WEB-INF/web.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
+         version="4.0">
+</web-app>

+ 16 - 0
SSODemo/web/index.jsp

@@ -0,0 +1,16 @@
+<%--
+  Created by IntelliJ IDEA.
+  User: Administrator
+  Date: 2020/12/21
+  Time: 19:59
+  To change this template use File | Settings | File Templates.
+--%>
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+<html>
+  <head>
+    <title>$Title$</title>
+  </head>
+  <body>
+  $END$
+  </body>
+</html>

Някои файлове не бяха показани, защото твърде много файлове са промени