Browse Source

添加sso-web

DUANY\DuanY 4 years ago
commit
ba298d9bfc
47 changed files with 738 additions and 0 deletions
  1. 27 0
      .idea/compiler.xml
  2. 11 0
      .idea/encodings.xml
  3. 19 0
      .idea/misc.xml
  4. 199 0
      .idea/workspace.xml
  5. 42 0
      pom.xml
  6. 15 0
      sso-login/pom.xml
  7. 11 0
      sso-login/src/main/java/com/sso/login/LoginApp.java
  8. 75 0
      sso-login/src/main/java/com/sso/login/controller/LoginController.java
  9. 42 0
      sso-login/src/main/java/com/sso/login/controller/ViewController.java
  10. 16 0
      sso-login/src/main/java/com/sso/login/pojo/User.java
  11. 11 0
      sso-login/src/main/java/com/sso/login/utils/LogCacheUtil.java
  12. 1 0
      sso-login/src/main/resources/application.properties
  13. 16 0
      sso-login/src/main/resources/templates/login.html
  14. 2 0
      sso-login/sso-login.iml
  15. BIN
      sso-login/target/classes/META-INF/sso-login.kotlin_module
  16. 1 0
      sso-login/target/classes/application.properties
  17. BIN
      sso-login/target/classes/com/sso/login/LoginApp.class
  18. BIN
      sso-login/target/classes/com/sso/login/controller/LoginController.class
  19. BIN
      sso-login/target/classes/com/sso/login/controller/ViewController.class
  20. BIN
      sso-login/target/classes/com/sso/login/pojo/User.class
  21. BIN
      sso-login/target/classes/com/sso/login/utils/LogCacheUtil.class
  22. 16 0
      sso-login/target/classes/templates/login.html
  23. 3 0
      sso-login/target/maven-archiver/pom.properties
  24. 2 0
      sso-login/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst
  25. 5 0
      sso-login/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst
  26. 0 0
      sso-login/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst
  27. 0 0
      sso-login/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst
  28. BIN
      sso-login/target/sso-login-1.0-SNAPSHOT.jar
  29. 16 0
      sso-main/pom.xml
  30. 18 0
      sso-main/src/main/java/com/sso/main/MainApp.java
  31. 39 0
      sso-main/src/main/java/com/sso/main/controller/ViewController.java
  32. 1 0
      sso-main/src/main/resources/application.properties
  33. 17 0
      sso-main/src/main/resources/templates/index.html
  34. 1 0
      sso-main/target/classes/application.properties
  35. BIN
      sso-main/target/classes/com/sso/main/MainApp.class
  36. BIN
      sso-main/target/classes/com/sso/main/controller/ViewController.class
  37. 17 0
      sso-main/target/classes/templates/index.html
  38. 15 0
      sso-vip/pom.xml
  39. 18 0
      sso-vip/src/main/java/com/sso/vip/VipApp.java
  40. 44 0
      sso-vip/src/main/java/com/sso/vip/controller/ViewController.java
  41. 1 0
      sso-vip/src/main/resources/application.properties
  42. 17 0
      sso-vip/src/main/resources/templates/index.html
  43. 1 0
      sso-vip/target/classes/application.properties
  44. BIN
      sso-vip/target/classes/com/sso/vip/VipApp.class
  45. BIN
      sso-vip/target/classes/com/sso/vip/controller/ViewController.class
  46. 17 0
      sso-vip/target/classes/templates/index.html
  47. 2 0
      sso-web.iml

+ 27 - 0
.idea/compiler.xml

@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="CompilerConfiguration">
+    <annotationProcessing>
+      <profile default="true" name="Default" enabled="true" />
+      <profile name="Maven default annotation processors profile" enabled="true">
+        <sourceOutputDir name="target/generated-sources/annotations" />
+        <sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
+        <outputRelativeToContentRoot value="true" />
+        <module name="sso-main" />
+        <module name="sso-login" />
+        <module name="sso-vip" />
+      </profile>
+    </annotationProcessing>
+    <bytecodeTargetLevel>
+      <module name="sso-cart" target="1.8" />
+    </bytecodeTargetLevel>
+  </component>
+  <component name="JavacSettings">
+    <option name="ADDITIONAL_OPTIONS_OVERRIDE">
+      <module name="sso-cart" options="-parameters" />
+      <module name="sso-login" options="-parameters" />
+      <module name="sso-main" options="-parameters" />
+      <module name="sso-vip" options="-parameters" />
+    </option>
+  </component>
+</project>

+ 11 - 0
.idea/encodings.xml

@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="Encoding">
+    <file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
+    <file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
+    <file url="file://$PROJECT_DIR$/sso-cart/src/main/java" charset="UTF-8" />
+    <file url="file://$PROJECT_DIR$/sso-login/src/main/java" charset="UTF-8" />
+    <file url="file://$PROJECT_DIR$/sso-main/src/main/java" charset="UTF-8" />
+    <file url="file://$PROJECT_DIR$/sso-vip/src/main/java" charset="UTF-8" />
+  </component>
+</project>

+ 19 - 0
.idea/misc.xml

@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="ExternalStorageConfigurationManager" enabled="true" />
+  <component name="MavenProjectsManager">
+    <option name="originalFiles">
+      <list>
+        <option value="$PROJECT_DIR$/pom.xml" />
+      </list>
+    </option>
+    <option name="ignoredFiles">
+      <set>
+        <option value="$PROJECT_DIR$/sso-cart/pom.xml" />
+      </set>
+    </option>
+  </component>
+  <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
+    <output url="file://$PROJECT_DIR$/out" />
+  </component>
+</project>

+ 199 - 0
.idea/workspace.xml

@@ -0,0 +1,199 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="ChangeListManager">
+    <list default="true" id="c5a24e7a-e8cf-45f7-8d0b-25810e3d773a" name="默认更改列表" comment="" />
+    <option name="SHOW_DIALOG" value="false" />
+    <option name="HIGHLIGHT_CONFLICTS" value="true" />
+    <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
+    <option name="LAST_RESOLUTION" value="IGNORE" />
+  </component>
+  <component name="FileTemplateManagerImpl">
+    <option name="RECENT_TEMPLATES">
+      <list>
+        <option value="HTML File" />
+        <option value="Class" />
+      </list>
+    </option>
+  </component>
+  <component name="ProjectId" id="1lzQTfAXKnwTcVbccaZ8sG4KP4p" />
+  <component name="ProjectViewState">
+    <option name="hideEmptyMiddlePackages" value="true" />
+    <option name="showLibraryContents" value="true" />
+  </component>
+  <component name="PropertiesComponent">
+    <property name="DefaultHtmlFileTemplate" value="HTML File" />
+    <property name="ExpandSpringBootJavaOptionsPanel" value="true" />
+    <property name="RequestMappingsPanelOrder0" value="0" />
+    <property name="RequestMappingsPanelOrder1" value="1" />
+    <property name="RequestMappingsPanelWidth0" value="75" />
+    <property name="RequestMappingsPanelWidth1" value="75" />
+    <property name="RunOnceActivity.ShowReadmeOnStart" value="true" />
+    <property name="WebServerToolWindowFactoryState" value="false" />
+    <property name="aspect.path.notification.shown" value="true" />
+    <property name="jdk.selected.JAVA_MODULE" value="1.8" />
+    <property name="last_opened_file_path" value="$PROJECT_DIR$/sso-login/src/main/java/com/sso/login/controller" />
+    <property name="node.js.detected.package.eslint" value="true" />
+    <property name="node.js.detected.package.tslint" value="true" />
+    <property name="node.js.path.for.package.eslint" value="project" />
+    <property name="node.js.path.for.package.tslint" value="project" />
+    <property name="node.js.selected.package.eslint" value="(autodetect)" />
+    <property name="node.js.selected.package.tslint" value="(autodetect)" />
+    <property name="project.structure.last.edited" value="模块" />
+    <property name="project.structure.proportion" value="0.15" />
+    <property name="project.structure.side.proportion" value="0.2" />
+    <property name="settings.editor.selected.configurable" value="reference.projectsettings.compiler.annotationProcessors" />
+  </component>
+  <component name="RecentsManager">
+    <key name="CopyFile.RECENT_KEYS">
+      <recent name="E:\Idea\sso-web\sso-login\src\main\java\com\sso\login\controller" />
+      <recent name="E:\Idea\sso-web\sso-login\src\main\java\com\sso\login\utils" />
+      <recent name="E:\Idea\sso-web\sso-vip\src\main\resources\templates" />
+      <recent name="E:\Idea\sso-web\sso-vip\src\main\resources" />
+      <recent name="E:\Idea\sso-web\sso-main\src\main\resources" />
+    </key>
+    <key name="MoveFile.RECENT_KEYS">
+      <recent name="E:\Idea\sso-web\sso-login\src\main\resources\templates" />
+      <recent name="E:\Idea\sso-web\sso-login\src\main\resources\static" />
+      <recent name="E:\Idea\sso-web\sso-login\webapp" />
+    </key>
+  </component>
+  <component name="RunManager" selected="Spring Boot.VipApp">
+    <configuration name="LoginApp" type="SpringBootApplicationConfigurationType" factoryName="Spring Boot" temporary="true" nameIsGenerated="true">
+      <module name="sso-login" />
+      <extension name="coverage">
+        <pattern>
+          <option name="PATTERN" value="com.sso.login.*" />
+          <option name="ENABLED" value="true" />
+        </pattern>
+      </extension>
+      <option name="SPRING_BOOT_MAIN_CLASS" value="com.sso.login.LoginApp" />
+      <option name="WORKING_DIRECTORY" value="file://$PROJECT_DIR$" />
+      <option name="ALTERNATIVE_JRE_PATH" />
+      <method v="2">
+        <option name="Make" enabled="true" />
+      </method>
+    </configuration>
+    <configuration name="MainApp" type="SpringBootApplicationConfigurationType" factoryName="Spring Boot" temporary="true" nameIsGenerated="true">
+      <module name="sso-main" />
+      <extension name="coverage">
+        <pattern>
+          <option name="PATTERN" value="com.sso.main.*" />
+          <option name="ENABLED" value="true" />
+        </pattern>
+      </extension>
+      <option name="SPRING_BOOT_MAIN_CLASS" value="com.sso.main.MainApp" />
+      <method v="2">
+        <option name="Make" enabled="true" />
+      </method>
+    </configuration>
+    <configuration name="VipApp" type="SpringBootApplicationConfigurationType" factoryName="Spring Boot" temporary="true" nameIsGenerated="true">
+      <module name="sso-vip" />
+      <extension name="coverage">
+        <pattern>
+          <option name="PATTERN" value="com.sso.vip.*" />
+          <option name="ENABLED" value="true" />
+        </pattern>
+      </extension>
+      <option name="SPRING_BOOT_MAIN_CLASS" value="com.sso.vip.VipApp" />
+      <method v="2">
+        <option name="Make" enabled="true" />
+      </method>
+    </configuration>
+    <list>
+      <item itemvalue="Spring Boot.LoginApp" />
+      <item itemvalue="Spring Boot.MainApp" />
+      <item itemvalue="Spring Boot.VipApp" />
+    </list>
+    <recent_temporary>
+      <list>
+        <item itemvalue="Spring Boot.VipApp" />
+        <item itemvalue="Spring Boot.MainApp" />
+        <item itemvalue="Spring Boot.LoginApp" />
+      </list>
+    </recent_temporary>
+  </component>
+  <component name="SvnConfiguration">
+    <configuration />
+  </component>
+  <component name="TaskManager">
+    <task active="true" id="Default" summary="Default task">
+      <changelist id="c5a24e7a-e8cf-45f7-8d0b-25810e3d773a" name="默认更改列表" comment="" />
+      <created>1608597448224</created>
+      <option name="number" value="Default" />
+      <option name="presentableId" value="Default" />
+      <updated>1608597448224</updated>
+      <workItem from="1608597450909" duration="10657000" />
+      <workItem from="1608614660628" duration="4822000" />
+    </task>
+    <servers />
+  </component>
+  <component name="TypeScriptGeneratedFilesManager">
+    <option name="version" value="1" />
+  </component>
+  <component name="WindowStateProjectService">
+    <state x="828" y="186" key="#com.intellij.execution.impl.EditConfigurationsDialog" timestamp="1608598947800">
+      <screen x="0" y="0" width="1920" height="1050" />
+    </state>
+    <state x="828" y="186" key="#com.intellij.execution.impl.EditConfigurationsDialog/0.0.1920.1050@0.0.1920.1050" timestamp="1608598947800" />
+    <state x="1103" y="314" key="#com.intellij.ide.util.TreeClassChooserDialog" timestamp="1608598935558">
+      <screen x="0" y="0" width="1920" height="1050" />
+    </state>
+    <state x="1103" y="314" key="#com.intellij.ide.util.TreeClassChooserDialog/0.0.1920.1050@0.0.1920.1050" timestamp="1608598935558" />
+    <state x="1189" y="441" key="#com.intellij.javaee.module.view.web.EditWebRootDialog" timestamp="1608599443382">
+      <screen x="0" y="0" width="1920" height="1050" />
+    </state>
+    <state x="1189" y="441" key="#com.intellij.javaee.module.view.web.EditWebRootDialog/0.0.1920.1050@0.0.1920.1050" timestamp="1608599443382" />
+    <state x="1170" y="277" key="#com.intellij.refactoring.safeDelete.UnsafeUsagesDialog" timestamp="1608603344267">
+      <screen x="0" y="0" width="1920" height="1050" />
+    </state>
+    <state x="1170" y="277" key="#com.intellij.refactoring.safeDelete.UnsafeUsagesDialog/0.0.1920.1050@0.0.1920.1050" timestamp="1608603344267" />
+    <state x="1032" y="189" key="#项目结构" timestamp="1608616244825">
+      <screen x="0" y="0" width="1920" height="1050" />
+    </state>
+    <state x="1032" y="189" key="#项目结构/0.0.1920.1050@0.0.1920.1050" timestamp="1608616244825" />
+    <state x="1154" y="286" key="FileChooserDialogImpl" timestamp="1608599626317">
+      <screen x="0" y="0" width="1920" height="1050" />
+    </state>
+    <state x="1154" y="286" key="FileChooserDialogImpl/0.0.1920.1050@0.0.1920.1050" timestamp="1608599626317" />
+    <state width="1877" height="282" key="GridCell.Tab.0.bottom" timestamp="1608619487493">
+      <screen x="0" y="0" width="1920" height="1050" />
+    </state>
+    <state width="1877" height="282" key="GridCell.Tab.0.bottom/0.0.1920.1050@0.0.1920.1050" timestamp="1608619487493" />
+    <state width="1877" height="282" key="GridCell.Tab.0.center" timestamp="1608619487493">
+      <screen x="0" y="0" width="1920" height="1050" />
+    </state>
+    <state width="1877" height="282" key="GridCell.Tab.0.center/0.0.1920.1050@0.0.1920.1050" timestamp="1608619487493" />
+    <state width="1877" height="282" key="GridCell.Tab.0.left" timestamp="1608619487493">
+      <screen x="0" y="0" width="1920" height="1050" />
+    </state>
+    <state width="1877" height="282" key="GridCell.Tab.0.left/0.0.1920.1050@0.0.1920.1050" timestamp="1608619487493" />
+    <state width="1877" height="282" key="GridCell.Tab.0.right" timestamp="1608619487493">
+      <screen x="0" y="0" width="1920" height="1050" />
+    </state>
+    <state width="1877" height="282" key="GridCell.Tab.0.right/0.0.1920.1050@0.0.1920.1050" timestamp="1608619487493" />
+    <state width="1877" height="282" key="GridCell.Tab.1.bottom" timestamp="1608619487493">
+      <screen x="0" y="0" width="1920" height="1050" />
+    </state>
+    <state width="1877" height="282" key="GridCell.Tab.1.bottom/0.0.1920.1050@0.0.1920.1050" timestamp="1608619487493" />
+    <state width="1877" height="282" key="GridCell.Tab.1.center" timestamp="1608619487493">
+      <screen x="0" y="0" width="1920" height="1050" />
+    </state>
+    <state width="1877" height="282" key="GridCell.Tab.1.center/0.0.1920.1050@0.0.1920.1050" timestamp="1608619487493" />
+    <state width="1877" height="282" key="GridCell.Tab.1.left" timestamp="1608619487493">
+      <screen x="0" y="0" width="1920" height="1050" />
+    </state>
+    <state width="1877" height="282" key="GridCell.Tab.1.left/0.0.1920.1050@0.0.1920.1050" timestamp="1608619487493" />
+    <state width="1877" height="282" key="GridCell.Tab.1.right" timestamp="1608619487493">
+      <screen x="0" y="0" width="1920" height="1050" />
+    </state>
+    <state width="1877" height="282" key="GridCell.Tab.1.right/0.0.1920.1050@0.0.1920.1050" timestamp="1608619487493" />
+    <state x="880" y="103" key="SettingsEditor" timestamp="1608599446226">
+      <screen x="0" y="0" width="1920" height="1050" />
+    </state>
+    <state x="880" y="103" key="SettingsEditor/0.0.1920.1050@0.0.1920.1050" timestamp="1608599446226" />
+    <state x="669" y="305" key="new project wizard" timestamp="1608597551310">
+      <screen x="0" y="0" width="1920" height="1050" />
+    </state>
+    <state x="669" y="305" key="new project wizard/0.0.1920.1050@0.0.1920.1050" timestamp="1608597551310" />
+  </component>
+</project>

+ 42 - 0
pom.xml

@@ -0,0 +1,42 @@
+<?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>org.example</groupId>
+    <artifactId>sso-web</artifactId>
+    <packaging>pom</packaging>
+    <version>1.0-SNAPSHOT</version>
+    <modules>
+        <module>sso-login</module>
+        <module>sso-cart</module>
+        <module>sso-vip</module>
+        <module>sso-main</module>
+    </modules>
+
+    <parent>
+        <groupId>org.springframework.boot</groupId>
+        <artifactId>spring-boot-starter-parent</artifactId>
+        <version>2.3.4.RELEASE</version>
+    </parent>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-web</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-thymeleaf</artifactId>
+        </dependency>
+        <!--        lombok插件-->
+        <dependency>
+            <groupId>org.projectlombok</groupId>
+            <artifactId>lombok</artifactId>
+            <optional>true</optional>
+        </dependency>
+    </dependencies>
+
+</project>

+ 15 - 0
sso-login/pom.xml

@@ -0,0 +1,15 @@
+<?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>sso-web</artifactId>
+        <groupId>org.example</groupId>
+        <version>1.0-SNAPSHOT</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>sso-login</artifactId>
+
+
+</project>

+ 11 - 0
sso-login/src/main/java/com/sso/login/LoginApp.java

@@ -0,0 +1,11 @@
+package com.sso.login;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+public class LoginApp {
+    public static void main(String[] args) {
+        SpringApplication.run(LoginApp.class,args);
+    }
+}

+ 75 - 0
sso-login/src/main/java/com/sso/login/controller/LoginController.java

@@ -0,0 +1,75 @@
+package com.sso.login.controller;
+
+import com.sso.login.pojo.User;
+import com.sso.login.utils.LogCacheUtil;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.ResponseBody;
+import org.thymeleaf.util.StringUtils;
+
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+import java.util.*;
+
+@Controller
+@RequestMapping("/login")
+public class LoginController {
+//    模拟数据库拿的信息
+    private static Set<User> dbUser;
+
+    static{
+        dbUser = new HashSet<>();
+        dbUser.add(new User(1,"xiaoqiang","123456"));
+        dbUser.add(new User(2,"alice","987654"));
+    }
+
+    /**
+     * 判断登录是否成功
+     * @param user
+     * @param session
+     * @param response
+     * @return
+     */
+    @PostMapping
+    public String doLogin(User user, HttpSession session, HttpServletResponse response){
+        String target = (String) session.getAttribute("target");
+        Optional<User> first = dbUser.stream().filter(dbUser -> dbUser.getUsername().equals(user.getUsername()) &&
+                dbUser.getPassword().equals(user.getPassword()))
+                .findFirst();
+        if(first.isPresent()){
+            //登陆成功。返回信息
+            String token = UUID.randomUUID().toString();
+            Cookie cookie=new Cookie("TOKEN",token);
+            //定义域为codeshop.com
+            cookie.setDomain("codeshop.com");
+            response.addCookie(cookie);
+            LogCacheUtil.loginUser.put(token, first.get());
+        }else{
+            //登录失败时不跳转
+            session.setAttribute("msg","username or password is wrong.");
+            return "login";
+        }
+
+        //重定向到target地址
+        return "redirect:" + target;
+    }
+
+
+    @GetMapping("info")
+    @ResponseBody
+    public ResponseEntity<User> getUserInfo(String token){
+        //不为空时相应
+        if (!StringUtils.isEmpty(token)){
+            User user=LogCacheUtil.loginUser.get(token);
+            return ResponseEntity.ok(user);
+        }else {
+        //为空时返回错误
+            return new ResponseEntity<>(null, HttpStatus.BAD_REQUEST);
+        }
+    }
+}

+ 42 - 0
sso-login/src/main/java/com/sso/login/controller/ViewController.java

@@ -0,0 +1,42 @@
+package com.sso.login.controller;
+
+import com.sso.login.pojo.User;
+import com.sso.login.utils.LogCacheUtil;
+import org.springframework.boot.web.servlet.server.Session;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.CookieValue;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.thymeleaf.util.StringUtils;
+
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpSession;
+
+/**
+ * 页面跳转逻辑
+ */
+@Controller
+@RequestMapping("/view")
+public class ViewController {
+    @RequestMapping("/login")
+    public String toLogin(@RequestParam(required = false,defaultValue = "")String target,
+                          HttpSession session, @CookieValue(required = false,value = "TOKEN")Cookie cookie){
+
+        if (StringUtils.isEmpty(target)){
+            target="http://www.codeshop.com";
+        }
+        //如果cookie存在,执行语句
+        if (cookie!=null){
+            String value=cookie.getValue();
+            User user= LogCacheUtil.loginUser.get(value);
+            if (user!=null){
+                return "redirect:"+target;
+            }
+        }
+
+        //重定向地址
+        session.setAttribute("target",target);
+        return "login";
+    }
+}

+ 16 - 0
sso-login/src/main/java/com/sso/login/pojo/User.java

@@ -0,0 +1,16 @@
+package com.sso.login.pojo;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.experimental.Accessors;
+
+@Data //添加get和set
+@NoArgsConstructor //添加无参构造器
+@AllArgsConstructor //添加全参构造器
+@Accessors(chain = true) //添加链式调用(user().getUserId就是链式调用)
+public class User {
+    private Integer id;
+    private String username;
+    private String password;
+}

+ 11 - 0
sso-login/src/main/java/com/sso/login/utils/LogCacheUtil.java

@@ -0,0 +1,11 @@
+package com.sso.login.utils;
+
+import com.sso.login.pojo.User;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class LogCacheUtil {
+    public static Map<String, User> loginUser = new HashMap<>();
+
+}

+ 1 - 0
sso-login/src/main/resources/application.properties

@@ -0,0 +1 @@
+server.port=8081

+ 16 - 0
sso-login/src/main/resources/templates/login.html

@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
+<head>
+    <meta charset="UTF-8">
+    <title>welcome login</title>
+</head>
+<body>
+    <h1>欢迎进入登录界面</h1>
+    <p style="color: red;" th:text="${session.msg}"></p>
+    <form action="/login" method="post">
+        用户名:<input type="text" value="" name="username"><br>
+        密码:<input type="password" value="" name="password"><br>
+        <button type="submit">登录</button>
+    </form>
+</body>
+</html>

+ 2 - 0
sso-login/sso-login.iml

@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module type="JAVA_MODULE" version="4" />

BIN
sso-login/target/classes/META-INF/sso-login.kotlin_module


+ 1 - 0
sso-login/target/classes/application.properties

@@ -0,0 +1 @@
+server.port=8081

BIN
sso-login/target/classes/com/sso/login/LoginApp.class


BIN
sso-login/target/classes/com/sso/login/controller/LoginController.class


BIN
sso-login/target/classes/com/sso/login/controller/ViewController.class


BIN
sso-login/target/classes/com/sso/login/pojo/User.class


BIN
sso-login/target/classes/com/sso/login/utils/LogCacheUtil.class


+ 16 - 0
sso-login/target/classes/templates/login.html

@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
+<head>
+    <meta charset="UTF-8">
+    <title>welcome login</title>
+</head>
+<body>
+    <h1>欢迎进入登录界面</h1>
+    <p style="color: red;" th:text="${session.msg}"></p>
+    <form action="/login" method="post">
+        用户名:<input type="text" value="" name="username"><br>
+        密码:<input type="password" value="" name="password"><br>
+        <button type="submit">登录</button>
+    </form>
+</body>
+</html>

+ 3 - 0
sso-login/target/maven-archiver/pom.properties

@@ -0,0 +1,3 @@
+artifactId=sso-login
+groupId=org.example
+version=1.0-SNAPSHOT

+ 2 - 0
sso-login/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst

@@ -0,0 +1,2 @@
+com\sso\login\utils\LogCacheUtil.class
+com\sso\login\controller\LoginController.class

+ 5 - 0
sso-login/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst

@@ -0,0 +1,5 @@
+E:\Idea\sso-web\sso-login\src\main\java\com\sso\login\LoginApp.java
+E:\Idea\sso-web\sso-login\src\main\java\com\sso\login\controller\ViewController.java
+E:\Idea\sso-web\sso-login\src\main\java\com\sso\login\pojo\User.java
+E:\Idea\sso-web\sso-login\src\main\java\com\sso\login\controller\LoginController.java
+E:\Idea\sso-web\sso-login\src\main\java\com\sso\login\utils\LogCacheUtil.java

+ 0 - 0
sso-login/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst


+ 0 - 0
sso-login/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst


BIN
sso-login/target/sso-login-1.0-SNAPSHOT.jar


+ 16 - 0
sso-main/pom.xml

@@ -0,0 +1,16 @@
+<?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>sso-web</artifactId>
+        <groupId>org.example</groupId>
+        <version>1.0-SNAPSHOT</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>sso-main</artifactId>
+
+
+
+</project>

+ 18 - 0
sso-main/src/main/java/com/sso/main/MainApp.java

@@ -0,0 +1,18 @@
+package com.sso.main;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.context.annotation.Bean;
+import org.springframework.web.client.RestTemplate;
+
+@SpringBootApplication
+public class MainApp {
+    public static void main(String[] args) {
+        SpringApplication.run(MainApp.class,args);
+    }
+
+    @Bean
+    public RestTemplate restTemplate(){
+        return new RestTemplate();
+    }
+}

+ 39 - 0
sso-main/src/main/java/com/sso/main/controller/ViewController.java

@@ -0,0 +1,39 @@
+package com.sso.main.controller;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.CookieValue;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.client.RestTemplate;
+import org.thymeleaf.util.StringUtils;
+
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpSession;
+import java.util.Map;
+
+/**
+ * 页面跳转逻辑
+ */
+@Controller
+@RequestMapping("/view")
+public class ViewController {
+
+    @Autowired
+    private RestTemplate restTemplate;
+
+    private final String LOGIN_INFO_ADDRESS="http://login.codeshop.com/login/info?token=";
+
+    @RequestMapping("/main")
+    public String toLogin(@CookieValue(required = false,value = "TOKEN")Cookie cookie, HttpSession session){
+        if (cookie!=null){
+            String token=cookie.getValue();
+            if(!StringUtils.isEmpty(token)){
+                Map result = restTemplate.getForObject(LOGIN_INFO_ADDRESS + token, Map.class);
+                //保存用户
+                session.setAttribute("loginUser",result);
+            }
+        }
+        return "index";
+    }
+}
+

+ 1 - 0
sso-main/src/main/resources/application.properties

@@ -0,0 +1 @@
+server.port=8082

+ 17 - 0
sso-main/src/main/resources/templates/index.html

@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
+<head>
+    <meta charset="UTF-8">
+    <title>index</title>
+</head>
+<body>
+    <h1>这是主页</h1>
+    <span>
+        <a th:if="${session.loginUser==null}" href="http://login.codeshop.com/view/login?target=http://www.codeshop.com/view/main">登录</a>
+    </span>
+
+<p th:unless="${session.loginUser==null}">
+    <span style="color: aqua" th:text="${session.loginUser.username}"></span> 已登录
+</p>
+</body>
+</html>

+ 1 - 0
sso-main/target/classes/application.properties

@@ -0,0 +1 @@
+server.port=8082

BIN
sso-main/target/classes/com/sso/main/MainApp.class


BIN
sso-main/target/classes/com/sso/main/controller/ViewController.class


+ 17 - 0
sso-main/target/classes/templates/index.html

@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
+<head>
+    <meta charset="UTF-8">
+    <title>index</title>
+</head>
+<body>
+    <h1>这是主页</h1>
+    <span>
+        <a th:if="${session.loginUser==null}" href="http://login.codeshop.com/view/login?target=http://www.codeshop.com/view/main">登录</a>
+    </span>
+
+<p th:unless="${session.loginUser==null}">
+    <span style="color: aqua" th:text="${session.loginUser.username}"></span> 已登录
+</p>
+</body>
+</html>

+ 15 - 0
sso-vip/pom.xml

@@ -0,0 +1,15 @@
+<?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>sso-web</artifactId>
+        <groupId>org.example</groupId>
+        <version>1.0-SNAPSHOT</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>sso-vip</artifactId>
+
+
+</project>

+ 18 - 0
sso-vip/src/main/java/com/sso/vip/VipApp.java

@@ -0,0 +1,18 @@
+package com.sso.vip;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.context.annotation.Bean;
+import org.springframework.web.client.RestTemplate;
+
+@SpringBootApplication
+public class VipApp {
+    public static void main(String[] args) {
+        SpringApplication.run(VipApp.class,args);
+    }
+
+    @Bean
+    public RestTemplate restTemplate(){
+        return new RestTemplate();
+    }
+}

+ 44 - 0
sso-vip/src/main/java/com/sso/vip/controller/ViewController.java

@@ -0,0 +1,44 @@
+package com.sso.vip.controller;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.CookieValue;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.client.RestTemplate;
+import org.thymeleaf.util.StringUtils;
+
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+import java.util.Map;
+
+/**
+ * 页面跳转逻辑
+ */
+@Controller
+@RequestMapping("/view")
+public class ViewController {
+
+    @Autowired
+    RestTemplate restTemplate;
+
+    private final String LOGIN_INFO_ADDRESS="http://login.codeshop.com/login/info?token=";
+
+    @RequestMapping("/vip")
+    public String toLogin(@CookieValue(required = false,value = "TOKEN")Cookie cookie, HttpSession session){
+        if (cookie!=null){
+            String token=cookie.getValue();
+            if(!StringUtils.isEmpty(token)){
+                Map result = restTemplate.getForObject(LOGIN_INFO_ADDRESS + token, Map.class);
+                //保存用户
+                session.setAttribute("loginUser",result);
+            }
+        }
+        return "index";
+    }
+
+    @RequestMapping("/remove")
+    public String removeLogin(){
+        return "index";
+    }
+}

+ 1 - 0
sso-vip/src/main/resources/application.properties

@@ -0,0 +1 @@
+server.port=8083

+ 17 - 0
sso-vip/src/main/resources/templates/index.html

@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
+<head>
+    <meta charset="UTF-8">
+    <title>index</title>
+</head>
+<body>
+<h1>这是vip页</h1>
+<span>
+        <a th:if="${session.loginUser==null}" href="http://login.codeshop.com/view/login?target=http://vip.codeshop.com/view/vip">登录</a>
+    </span>
+
+<p th:unless="${session.loginUser==null}">
+    <span style="color: red" th:text="${session.loginUser.username}"></span> 已登录
+</p>
+</body>
+</html>

+ 1 - 0
sso-vip/target/classes/application.properties

@@ -0,0 +1 @@
+server.port=8083

BIN
sso-vip/target/classes/com/sso/vip/VipApp.class


BIN
sso-vip/target/classes/com/sso/vip/controller/ViewController.class


+ 17 - 0
sso-vip/target/classes/templates/index.html

@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
+<head>
+    <meta charset="UTF-8">
+    <title>index</title>
+</head>
+<body>
+<h1>这是vip页</h1>
+<span>
+        <a th:if="${session.loginUser==null}" href="http://login.codeshop.com/view/login?target=http://vip.codeshop.com/view/vip">登录</a>
+    </span>
+
+<p th:unless="${session.loginUser==null}">
+    <span style="color: red" th:text="${session.loginUser.username}"></span> 已登录
+</p>
+</body>
+</html>

+ 2 - 0
sso-web.iml

@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module type="JAVA_MODULE" version="4" />