From 8dfd76084d0ff0dedaa097d6fb95ef703d9db5fb Mon Sep 17 00:00:00 2001
From: barney <15270405776@163.com>
Date: Sun, 12 Mar 2023 22:11:47 +0800
Subject: [PATCH] v1.0
---
.idea/.gitignore | 8 ++
.idea/compiler.xml | 26 ++++
.idea/encodings.xml | 11 ++
.idea/inspectionProfiles/Project_Default.xml | 8 ++
.idea/jarRepositories.xml | 20 +++
.idea/misc.xml | 14 ++
.idea/uiDesigner.xml | 124 ++++++++++++++++++
README.md | 41 ++++++
pom.xml | 57 ++++++++
sso-cart/pom.xml | 20 +++
.../main/java/cc/bnblogs/CartApplication.java | 23 ++++
.../cc/bnblogs/controller/ViewController.java | 43 ++++++
sso-cart/src/main/resources/application.yml | 2 +
.../src/main/resources/templates/index.html | 18 +++
sso-cart/target/classes/application.yml | 2 +
.../classes/cc/bnblogs/CartApplication.class | Bin 0 -> 964 bytes
.../bnblogs/controller/ViewController.class | Bin 0 -> 2039 bytes
sso-cart/target/classes/templates/index.html | 18 +++
sso-login/pom.xml | 20 +++
.../java/cc/bnblogs/LoginApplication.java | 23 ++++
.../bnblogs/controller/LoginController.java | 83 ++++++++++++
.../cc/bnblogs/controller/ViewController.java | 59 +++++++++
.../src/main/java/cc/bnblogs/pojo/User.java | 23 ++++
.../cc/bnblogs/utils/LoginCacheUtils.java | 15 +++
sso-login/src/main/resources/application.yml | 2 +
.../src/main/resources/templates/login.html | 23 ++++
sso-login/target/classes/application.yml | 2 +
.../classes/cc/bnblogs/LoginApplication.class | Bin 0 -> 967 bytes
.../bnblogs/controller/LoginController.class | Bin 0 -> 5030 bytes
.../bnblogs/controller/ViewController.class | Bin 0 -> 2512 bytes
.../target/classes/cc/bnblogs/pojo/User.class | Bin 0 -> 2635 bytes
.../cc/bnblogs/utils/LoginCacheUtils.class | Bin 0 -> 520 bytes
sso-login/target/classes/templates/login.html | 23 ++++
sso-main/pom.xml | 20 +++
.../main/java/cc/bnblogs/MainApplication.java | 28 ++++
.../cc/bnblogs/controller/ViewController.java | 48 +++++++
sso-main/src/main/resources/application.yml | 2 +
.../src/main/resources/templates/index.html | 23 ++++
sso-main/target/classes/application.yml | 2 +
.../classes/cc/bnblogs/MainApplication.class | Bin 0 -> 964 bytes
.../bnblogs/controller/ViewController.class | Bin 0 -> 2039 bytes
sso-main/target/classes/templates/index.html | 23 ++++
sso-vip/pom.xml | 20 +++
.../main/java/cc/bnblogs/VipApplication.java | 22 ++++
.../cc/bnblogs/controller/ViewController.java | 40 ++++++
sso-vip/src/main/resources/application.yml | 2 +
.../src/main/resources/templates/index.html | 18 +++
sso-vip/target/classes/application.yml | 2 +
.../classes/cc/bnblogs/VipApplication.class | Bin 0 -> 961 bytes
.../bnblogs/controller/ViewController.class | Bin 0 -> 2039 bytes
sso-vip/target/classes/templates/index.html | 18 +++
51 files changed, 976 insertions(+)
create mode 100644 .idea/.gitignore
create mode 100644 .idea/compiler.xml
create mode 100644 .idea/encodings.xml
create mode 100644 .idea/inspectionProfiles/Project_Default.xml
create mode 100644 .idea/jarRepositories.xml
create mode 100644 .idea/misc.xml
create mode 100644 .idea/uiDesigner.xml
create mode 100644 README.md
create mode 100644 pom.xml
create mode 100644 sso-cart/pom.xml
create mode 100644 sso-cart/src/main/java/cc/bnblogs/CartApplication.java
create mode 100644 sso-cart/src/main/java/cc/bnblogs/controller/ViewController.java
create mode 100644 sso-cart/src/main/resources/application.yml
create mode 100644 sso-cart/src/main/resources/templates/index.html
create mode 100644 sso-cart/target/classes/application.yml
create mode 100644 sso-cart/target/classes/cc/bnblogs/CartApplication.class
create mode 100644 sso-cart/target/classes/cc/bnblogs/controller/ViewController.class
create mode 100644 sso-cart/target/classes/templates/index.html
create mode 100644 sso-login/pom.xml
create mode 100644 sso-login/src/main/java/cc/bnblogs/LoginApplication.java
create mode 100644 sso-login/src/main/java/cc/bnblogs/controller/LoginController.java
create mode 100644 sso-login/src/main/java/cc/bnblogs/controller/ViewController.java
create mode 100644 sso-login/src/main/java/cc/bnblogs/pojo/User.java
create mode 100644 sso-login/src/main/java/cc/bnblogs/utils/LoginCacheUtils.java
create mode 100644 sso-login/src/main/resources/application.yml
create mode 100644 sso-login/src/main/resources/templates/login.html
create mode 100644 sso-login/target/classes/application.yml
create mode 100644 sso-login/target/classes/cc/bnblogs/LoginApplication.class
create mode 100644 sso-login/target/classes/cc/bnblogs/controller/LoginController.class
create mode 100644 sso-login/target/classes/cc/bnblogs/controller/ViewController.class
create mode 100644 sso-login/target/classes/cc/bnblogs/pojo/User.class
create mode 100644 sso-login/target/classes/cc/bnblogs/utils/LoginCacheUtils.class
create mode 100644 sso-login/target/classes/templates/login.html
create mode 100644 sso-main/pom.xml
create mode 100644 sso-main/src/main/java/cc/bnblogs/MainApplication.java
create mode 100644 sso-main/src/main/java/cc/bnblogs/controller/ViewController.java
create mode 100644 sso-main/src/main/resources/application.yml
create mode 100644 sso-main/src/main/resources/templates/index.html
create mode 100644 sso-main/target/classes/application.yml
create mode 100644 sso-main/target/classes/cc/bnblogs/MainApplication.class
create mode 100644 sso-main/target/classes/cc/bnblogs/controller/ViewController.class
create mode 100644 sso-main/target/classes/templates/index.html
create mode 100644 sso-vip/pom.xml
create mode 100644 sso-vip/src/main/java/cc/bnblogs/VipApplication.java
create mode 100644 sso-vip/src/main/java/cc/bnblogs/controller/ViewController.java
create mode 100644 sso-vip/src/main/resources/application.yml
create mode 100644 sso-vip/src/main/resources/templates/index.html
create mode 100644 sso-vip/target/classes/application.yml
create mode 100644 sso-vip/target/classes/cc/bnblogs/VipApplication.class
create mode 100644 sso-vip/target/classes/cc/bnblogs/controller/ViewController.class
create mode 100644 sso-vip/target/classes/templates/index.html
diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 0000000..35410ca
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,8 @@
+# 默认忽略的文件
+/shelf/
+/workspace.xml
+# 基于编辑器的 HTTP 客户端请求
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
new file mode 100644
index 0000000..ef06c80
--- /dev/null
+++ b/.idea/compiler.xml
@@ -0,0 +1,26 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/encodings.xml b/.idea/encodings.xml
new file mode 100644
index 0000000..7482feb
--- /dev/null
+++ b/.idea/encodings.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml
new file mode 100644
index 0000000..fe66321
--- /dev/null
+++ b/.idea/inspectionProfiles/Project_Default.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml
new file mode 100644
index 0000000..abb532a
--- /dev/null
+++ b/.idea/jarRepositories.xml
@@ -0,0 +1,20 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..ae9c995
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml
new file mode 100644
index 0000000..2b63946
--- /dev/null
+++ b/.idea/uiDesigner.xml
@@ -0,0 +1,124 @@
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+
\ No newline at end of file
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..381e630
--- /dev/null
+++ b/README.md
@@ -0,0 +1,41 @@
+### 基于SpringBoot+Thymeleaf+maven实现基于Cookie的单点登录
+
+#### 使用依赖
+
+```xml
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+
+ org.projectlombok
+ lombok
+
+
+
+ org.springframework.boot
+ spring-boot-starter-thymeleaf
+
+```
+
+#### 四个模块
+
+- `sso-main`: 首页
+- `sso-login`: 登录
+- `sso-cart`: 购物车
+- `sso-vip`: `vip`系统
+
+#### 接口
+
+| 接口类型 | 接口地址 |
+| --------- | -------------------------------------------- |
+| 首页 | `http://www.codeshop.com:8082/view/index` |
+| 登录 | `http://login.codeshop.com:8081/view/login` |
+| 登出 | `http://login.codeshop.com:8081/view/logout` |
+| 购物车 | `http://cart.codeshop.com:8080/view/index` |
+| `vip`系统 | `http://vip.codeshop.com:8083/view/index` |
+
+#### 单点登录
+
+三个服务: 首页、购物车、`vip`系统,有一个成功登录,则所有服务均成功登录,一个退出登录,所有的服务均需重新登录
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..6a71508
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,57 @@
+
+
+ 4.0.0
+
+ cc.bnblogs
+ use-cookie-sso
+ 1.0-SNAPSHOT
+ pom
+
+ sso-main
+ sso-cart
+ sso-vip
+ sso-login
+
+
+
+ org.springframework.boot
+ spring-boot-starter-parent
+
+ 2.7.9
+
+
+
+ 8
+ 8
+ UTF-8
+
+
+
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+
+ org.springframework.boot
+ spring-boot-devtools
+ runtime
+ true
+
+
+
+ org.projectlombok
+ lombok
+
+
+
+ org.springframework.boot
+ spring-boot-starter-thymeleaf
+
+
+
+
+
\ No newline at end of file
diff --git a/sso-cart/pom.xml b/sso-cart/pom.xml
new file mode 100644
index 0000000..d7ce83b
--- /dev/null
+++ b/sso-cart/pom.xml
@@ -0,0 +1,20 @@
+
+
+ 4.0.0
+
+ cc.bnblogs
+ use-cookie-sso
+ 1.0-SNAPSHOT
+
+
+ sso-cart
+
+
+ 8
+ 8
+ UTF-8
+
+
+
\ No newline at end of file
diff --git a/sso-cart/src/main/java/cc/bnblogs/CartApplication.java b/sso-cart/src/main/java/cc/bnblogs/CartApplication.java
new file mode 100644
index 0000000..924d852
--- /dev/null
+++ b/sso-cart/src/main/java/cc/bnblogs/CartApplication.java
@@ -0,0 +1,23 @@
+package cc.bnblogs;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.context.annotation.Bean;
+import org.springframework.web.client.RestTemplate;
+
+/**
+ * @description: 购物车子模块
+ * @author: zfp@bnblogs.cc
+ * @date: 2023/3/12 15:37
+ */
+@SpringBootApplication
+public class CartApplication {
+ public static void main(String[] args) {
+ SpringApplication.run(CartApplication.class,args);
+ }
+
+ @Bean
+ public RestTemplate restTemplate() {
+ return new RestTemplate();
+ }
+}
diff --git a/sso-cart/src/main/java/cc/bnblogs/controller/ViewController.java b/sso-cart/src/main/java/cc/bnblogs/controller/ViewController.java
new file mode 100644
index 0000000..56253a9
--- /dev/null
+++ b/sso-cart/src/main/java/cc/bnblogs/controller/ViewController.java
@@ -0,0 +1,43 @@
+package cc.bnblogs.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.GetMapping;
+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;
+
+/**
+ * @description: 购物车页面
+ * @author: zfp@bnblogs.cc
+ * @date: 2023/3/12 16:16
+ */
+@Controller
+@RequestMapping("/view")
+public class ViewController {
+ @Autowired
+ private RestTemplate restTemplate;
+
+ private final String LOGIN_INFO_ADDR = "http://login.codeshop.com:8081/login/info?token=";
+
+ @GetMapping("/index")
+ public String toIndex(@CookieValue(required = false,value = "TOKEN")Cookie cookie,
+ HttpSession httpSession) {
+ if (cookie!=null) {
+ String token = cookie.getValue();
+ if(!StringUtils.isEmpty(token)) {
+ // 访问/login/info接口时带上token请求登录用户信息
+ Map result = restTemplate.getForObject(LOGIN_INFO_ADDR + token, Map.class);
+ // 打印已登录用户信息
+// System.out.println(result);
+ httpSession.setAttribute("loginUser",result);
+ }
+ }
+ return "index";
+ }
+}
diff --git a/sso-cart/src/main/resources/application.yml b/sso-cart/src/main/resources/application.yml
new file mode 100644
index 0000000..47fbb02
--- /dev/null
+++ b/sso-cart/src/main/resources/application.yml
@@ -0,0 +1,2 @@
+server:
+ port: 8080
\ No newline at end of file
diff --git a/sso-cart/src/main/resources/templates/index.html b/sso-cart/src/main/resources/templates/index.html
new file mode 100644
index 0000000..f0f76b4
--- /dev/null
+++ b/sso-cart/src/main/resources/templates/index.html
@@ -0,0 +1,18 @@
+
+
+
+
+ 购物车
+
+
+ 这里是购物车
+
+ 已登录
+
+
+
+ 登录
+ 退出
+
+
+
\ No newline at end of file
diff --git a/sso-cart/target/classes/application.yml b/sso-cart/target/classes/application.yml
new file mode 100644
index 0000000..47fbb02
--- /dev/null
+++ b/sso-cart/target/classes/application.yml
@@ -0,0 +1,2 @@
+server:
+ port: 8080
\ No newline at end of file
diff --git a/sso-cart/target/classes/cc/bnblogs/CartApplication.class b/sso-cart/target/classes/cc/bnblogs/CartApplication.class
new file mode 100644
index 0000000000000000000000000000000000000000..50d46101cbf488cc1fd025f7982ae12cc026b5c5
GIT binary patch
literal 964
zcmb7C+invv5IxSlOXwxEg_d%ENrS)=Lc9c3Y9sL!E^4ZviYM>Z-MVb-$m^wi7CaS!
z#0T(Ei19X|3tApnX+56t%<-8s{_*qccK}cEAV33~P23EygL8S*GmQaiq1C?G-``Qp;rcwQ@tQpAVzP-W;EEa
zTbS!05oy{l8D;s9=E4qU8u-UmxPro7_dYdOp(pIWDwx-U)&=r7Sw^V6-T*Lh%m$byANE
rJzK2K;GWFkzM*z_j`}A$FVb221L}g#8s&Jh>v`_=e7%8rbOZPWDZBPl
literal 0
HcmV?d00001
diff --git a/sso-cart/target/classes/cc/bnblogs/controller/ViewController.class b/sso-cart/target/classes/cc/bnblogs/controller/ViewController.class
new file mode 100644
index 0000000000000000000000000000000000000000..c79b3c5e45f56b0fef9d4720189543a60c84f47a
GIT binary patch
literal 2039
zcmb7FZBrXn6n<_JSO`nO&{}B~wbqvRr4=fL7KHFp+K^OUqAedfo8$spHoI~62FhRY
zSJ)Y)T1UrEe(*;*K6jI1qB~9TS&9#*jn8^9T
zffd#Q$2-^$?5aHRgCpximaMYtNKaW?E$Z_EgIje^IaOJ7LZ{@)CC~GftsLJA1!iO4
zDoNW5t$n+!{NU8G&kd}ly7Et)Kvwu{U#_sek$<+4Un@LYT3Oi=$mE{e$F}9#-hs8P
zw0l(R%@Ro2o+{dIo!)oeb38{a2qcF`iUO&uU!k-w=Xf$-ua;!6W7A3fm|wQtq8&K;
z+!UtNp+m24G~%H@u2`Ay62OoO@w~GB|dn
zvJRE1Sy|sda^!s6)dSvd%P?e~=11ZJ>tt2xuF}3oVb_)8TAOx_upP=jk{)9%NAC+<
zjYDXH3-oATnpgrK#p$+s!<=p_yL?2fW?K3;r8@L0k8RBcB?G2tI<~NyBqhhIwAOT8
zD!x=}RIB5-StW~FI&at7$#V|T#-f?G25ZC|QGt2t3gkC+O{XL~2F%+|;n8YdAieF^
zgR)$6G!X{ct2(KZEie`f88Ue3tJ9ifXcVEiG?SFyfFd*g$8_XuWms!|(8!X&!x-Ea*sN=Z;rw2Uq+!@L
zA(|qAp_p{GG%~?Msg@KcWvQ+Q`_2Cbe*;y-$NU%4%Z^F#k5ppkT;!>f>m{xk%{lJh
zYicC8Cwuw5O37W?2(CS&uOLPEaA!7DF@z6!;%p*xDthK6
z*AB{-$9~7c*cnp!i67DNEpCr~kItWAJb8t#OyUgb3I5K|lQEOOp!Wp+$SLxG0IJMg7@GJqLf{r<`{qDdk`TeFiH7<&W}aIsi(Mw@esEu
VOyINVI~|#2c%I?;&bjI5e*r`>E=vFa
literal 0
HcmV?d00001
diff --git a/sso-cart/target/classes/templates/index.html b/sso-cart/target/classes/templates/index.html
new file mode 100644
index 0000000..f0f76b4
--- /dev/null
+++ b/sso-cart/target/classes/templates/index.html
@@ -0,0 +1,18 @@
+
+
+
+
+ 购物车
+
+
+ 这里是购物车
+
+ 已登录
+
+
+
+ 登录
+ 退出
+
+
+
\ No newline at end of file
diff --git a/sso-login/pom.xml b/sso-login/pom.xml
new file mode 100644
index 0000000..43e778f
--- /dev/null
+++ b/sso-login/pom.xml
@@ -0,0 +1,20 @@
+
+
+ 4.0.0
+
+ cc.bnblogs
+ use-cookie-sso
+ 1.0-SNAPSHOT
+
+
+ sso-login
+
+
+ 8
+ 8
+ UTF-8
+
+
+
\ No newline at end of file
diff --git a/sso-login/src/main/java/cc/bnblogs/LoginApplication.java b/sso-login/src/main/java/cc/bnblogs/LoginApplication.java
new file mode 100644
index 0000000..bd6b7ad
--- /dev/null
+++ b/sso-login/src/main/java/cc/bnblogs/LoginApplication.java
@@ -0,0 +1,23 @@
+package cc.bnblogs;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.context.annotation.Bean;
+import org.springframework.web.client.RestTemplate;
+
+/**
+ * @description: 登录子模块
+ * @author: zfp@bnblogs.cc
+ * @date: 2023/3/12 15:38
+ */
+@SpringBootApplication
+public class LoginApplication {
+ public static void main(String[] args) {
+ SpringApplication.run(LoginApplication.class,args);
+ }
+
+ @Bean
+ public RestTemplate restTemplate() {
+ return new RestTemplate();
+ }
+}
diff --git a/sso-login/src/main/java/cc/bnblogs/controller/LoginController.java b/sso-login/src/main/java/cc/bnblogs/controller/LoginController.java
new file mode 100644
index 0000000..5a4cf33
--- /dev/null
+++ b/sso-login/src/main/java/cc/bnblogs/controller/LoginController.java
@@ -0,0 +1,83 @@
+package cc.bnblogs.controller;
+
+import cc.bnblogs.pojo.User;
+import cc.bnblogs.utils.LoginCacheUtils;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.*;
+import org.thymeleaf.util.StringUtils;
+
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+import java.util.*;
+
+/**
+ * @description: 用户登录逻辑
+ * @author: zfp@bnblogs.cc
+ * @date: 2023/3/12 15:53
+ */
+@Controller
+@RequestMapping("/login")
+public class LoginController {
+
+ // 模拟用户数据
+ private static Set dbUsers;
+
+ static {
+ dbUsers = new HashSet<>();
+ dbUsers.add(new User(1,"user1","123456"));
+ dbUsers.add(new User(2,"user2","123456"));
+ dbUsers.add(new User(3,"user3","123456"));
+ dbUsers.add(new User(4,"user4","123456"));
+ dbUsers.add(new User(5,"user5","123456"));
+ dbUsers.add(new User(6,"user6","123456"));
+ }
+ @PostMapping
+ public String doLogin(User user, HttpSession httpSession, HttpServletResponse httpServletResponse) {
+ String target = (String) httpSession.getAttribute("target");
+
+ // 模拟数据库根据用户名和密码查询该用户是否存在
+ Optional first = dbUsers.stream().filter(dbUser -> dbUser.getUsername().equals(user.getUsername()) &&
+ dbUser.getPassword().equals(user.getPassword())).findFirst();
+
+ // 如果该用户存在
+ if (first.isPresent()) {
+ // 保存用户登录信息
+ // 生成一个token作为key
+ String token = UUID.randomUUID().toString();
+ // 将token存入cookie
+ Cookie cookie = new Cookie("TOKEN",token);
+ // 设置相同的域
+ cookie.setDomain("codeshop.com");
+ // 将cookie通过响应返回
+ httpServletResponse.addCookie(cookie);
+
+ LoginCacheUtils.loginUser.put(token,first.get());
+ }
+ else {
+ // 返回登录失败界面,可选择重新登录
+ httpSession.setAttribute("msg","用户名或密码错误");
+ return "login";
+ }
+ // 重定向到登录前的地址
+ return "redirect:" + target;
+ }
+
+ /**
+ * 根据请求中的token决定是否返回用户数据
+ * @param token 请求方提供访问数据的token
+ * @return 返回响应结果
+ */
+ @GetMapping("info")
+ @ResponseBody
+ public ResponseEntity getUserInfo(String token) {
+ if (!StringUtils.isEmpty(token)) {
+ User user = LoginCacheUtils.loginUser.get(token);
+ return ResponseEntity.ok(user);
+ } else {
+ return new ResponseEntity<>(null, HttpStatus.BAD_REQUEST);
+ }
+ }
+}
diff --git a/sso-login/src/main/java/cc/bnblogs/controller/ViewController.java b/sso-login/src/main/java/cc/bnblogs/controller/ViewController.java
new file mode 100644
index 0000000..ebf5ddb
--- /dev/null
+++ b/sso-login/src/main/java/cc/bnblogs/controller/ViewController.java
@@ -0,0 +1,59 @@
+package cc.bnblogs.controller;
+
+import cc.bnblogs.pojo.User;
+import cc.bnblogs.utils.LoginCacheUtils;
+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.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+
+/**
+ * @description: 页面跳转逻辑
+ * @author: zfp@bnblogs.cc
+ * @date: 2023/3/12 15:55
+ */
+@Controller
+@RequestMapping("/view")
+
+public class ViewController {
+ @GetMapping("/login")
+ public String toLogin(@RequestParam(required = false,defaultValue = "") String target,
+ HttpSession httpSession,
+ @CookieValue(required = false, value = "TOKEN") Cookie cookie) {
+ if (StringUtils.isEmpty(target)) {
+ target = "http://www.codeshop.com:8082/view/index/";
+ }
+
+ // 如果用户已经成功登录,则不需要重复登录,直接重定向到页面
+ // 从token中获取到用户信息
+ if (cookie!=null) {
+ String token = cookie.getValue();
+ User user = LoginCacheUtils.loginUser.get(token);
+ if (user != null) {
+ return "redirect:" + target;
+ }
+ }
+
+ // todo: 注意这里没有做地址校验
+ httpSession.setAttribute("target",target);
+ return "login";
+ }
+
+ /**
+ *退出账户,将cookie设置为已过期
+ *删除已登录的用户
+ */
+ @GetMapping("/logout")
+ public String loginOut(@CookieValue(value = "TOKEN") Cookie cookie, HttpServletResponse response, String target) {
+ cookie.setMaxAge(0);
+ LoginCacheUtils.loginUser.remove(cookie.getValue());
+ response.addCookie(cookie);
+ return "redirect:" + target;
+ }
+}
diff --git a/sso-login/src/main/java/cc/bnblogs/pojo/User.java b/sso-login/src/main/java/cc/bnblogs/pojo/User.java
new file mode 100644
index 0000000..c2fcbfc
--- /dev/null
+++ b/sso-login/src/main/java/cc/bnblogs/pojo/User.java
@@ -0,0 +1,23 @@
+package cc.bnblogs.pojo;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.experimental.Accessors;
+
+/**
+ * @description: 用户实体
+ * @author: zfp@bnblogs.cc
+ * @date: 2023/3/12 15:51
+ */
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+// 使用链式调用
+@Accessors(chain = true)
+public class User {
+ private Integer id;
+ private String username;
+ private String password;
+
+}
diff --git a/sso-login/src/main/java/cc/bnblogs/utils/LoginCacheUtils.java b/sso-login/src/main/java/cc/bnblogs/utils/LoginCacheUtils.java
new file mode 100644
index 0000000..ed6c6cb
--- /dev/null
+++ b/sso-login/src/main/java/cc/bnblogs/utils/LoginCacheUtils.java
@@ -0,0 +1,15 @@
+package cc.bnblogs.utils;
+
+import cc.bnblogs.pojo.User;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @description:
+ * @author: zfp@bnblogs.cc
+ * @date: 2023/3/12 17:42
+ */
+public class LoginCacheUtils {
+ public static Map loginUser = new HashMap<>();
+}
diff --git a/sso-login/src/main/resources/application.yml b/sso-login/src/main/resources/application.yml
new file mode 100644
index 0000000..54b155f
--- /dev/null
+++ b/sso-login/src/main/resources/application.yml
@@ -0,0 +1,2 @@
+server:
+ port: 8081
\ No newline at end of file
diff --git a/sso-login/src/main/resources/templates/login.html b/sso-login/src/main/resources/templates/login.html
new file mode 100644
index 0000000..09276e3
--- /dev/null
+++ b/sso-login/src/main/resources/templates/login.html
@@ -0,0 +1,23 @@
+
+
+
+
+ 登录页
+
+
+
+
+ 欢迎来到登录页面
+
+
+
+
+
\ No newline at end of file
diff --git a/sso-login/target/classes/application.yml b/sso-login/target/classes/application.yml
new file mode 100644
index 0000000..54b155f
--- /dev/null
+++ b/sso-login/target/classes/application.yml
@@ -0,0 +1,2 @@
+server:
+ port: 8081
\ No newline at end of file
diff --git a/sso-login/target/classes/cc/bnblogs/LoginApplication.class b/sso-login/target/classes/cc/bnblogs/LoginApplication.class
new file mode 100644
index 0000000000000000000000000000000000000000..4fc738011d3468bda6a4fe616b7ff3a0b381115f
GIT binary patch
literal 967
zcmb7C+invv5It_LT|zH`6iO-Amox}0A;e2ir8W{z%SBBUgn069-L1>Uj=T=#v*4)+
zBtC$TLX0;FUC;`NmDb}K&m5mQ;~zi2eh2Ub_XE^%qk*jeH?iHotpHW;-)5*kQ(C!Q
zhDvv5#84fWBgwEDDlK15$C0#$B1$RJ4oxi5k+919^I+ATsElDdjAI_@C^bpOLz5`I
zH<_d=7ET%6C(yA_nqi~+E<6<<1W$!d_|RFUlYV}wunECjDLH0Xdm-J4IeIOu7)vKD
zCAO^0+@Ty#QsIai@9u=gCOn&X#ABa#X6$=@CL`sg31x;-_SNakIVD`+~}wi~4|0fHk^ky@1iA$U4Q_^w&r|
sGW2k9bq@D<0rw5nx96yRqVpo1&L2=SIvvXKWH<8MYx#N|i|8is3!e!0qW}N^
literal 0
HcmV?d00001
diff --git a/sso-login/target/classes/cc/bnblogs/controller/LoginController.class b/sso-login/target/classes/cc/bnblogs/controller/LoginController.class
new file mode 100644
index 0000000000000000000000000000000000000000..17613eb4e7329ca556c8f4cfd3b5e189cf2d6ecd
GIT binary patch
literal 5030
zcmbtYdw3LA75~ldCbQWLkZyT2t%W4K5)zp5N@+rCA%qe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OPGSi?`cKnXIpmL#T1)JQDz0+z>LsN-U
zug61xuEwTQ(=|P@icheIx2*bQIGflIeDCMZ=GWl2|I~9Bzi`oq1AON+@c>4-wqgc+
zh=bf2_y~uP)xv*MS&p>1(hKzcj9f8ODZj$G@;0(l*+P`b`VT9Df_?UhjBkc&`_A9>Z$0~pGX
z6=VXBfeAjlD0qrb=`oCmhRf<)h4Bpa*pF})=OUaZ(ZGe*lv2chHoOFIDT&ojJjs%$
zT*_=?n86`_hUbGmJUC7K#XfWghauF#p+KCFq87eHSeH@6Btc%$;7`R$cYu~PC(o64Nt+k%tyg|8{QQSZ&<;*z(?aCBNa{Q_q3KNa(|Wk&lHOe%e8+2{{WZ7
literal 0
HcmV?d00001
diff --git a/sso-login/target/classes/cc/bnblogs/pojo/User.class b/sso-login/target/classes/cc/bnblogs/pojo/User.class
new file mode 100644
index 0000000000000000000000000000000000000000..466fd69fa940ffb86e8150e1c2431c9e2246b7af
GIT binary patch
literal 2635
zcma)7ZF3V<6n<{9o87eA5=v4UtO`=KNt#BnDx|b3m13oZN@*3W=r-MHgCVJ#RQwbC
z0e^se;e*adnb8?Xzu=6&NyO*e-DJ}cW|+y`d+xdC<+;x}d-BhJzx@GV245#(;1gMv
zWck#>CRESl#
z6^6cE5K^HMhP~TB^6a9nYUtu=ksuUw7|#3L{+xYc0Q8-;w)0x7obg@EO3|@mfpV
zGn2V4%P5qw(AZ{}Bg@sgcV++1mgir0w`w|YqvF;!T)!&kP-(Pwt4)Q`>?4T2))d*lS09cspgD>~IM5z_8wcFTUb$znX@_d3C
zWS}T_zB^o)`nl1>HA0l|zT0E;NV~Lu)O!^6iSdr>ntk(|uxB-1`D_MC%Fd?m{*w#(GXHUV?`)TV$Zm2+?brxj9B
z;GoDP#ogQU>MU)sn~qM0MGl9M5ac2Ib~imkR)~BSr#Lk-95Zpmgd<8Zp-Jy#in{|P
zlyH5SrxJI?-OT?A^|Lm6g=<19kKt9y;y?qOWN=U>i(Gr1W4+GlzRqO7k8`}&In&qq
zb-cmnNak7YG458r@DM8B>prC2M+1`(IE^(U3UA7DIF67alu6|J#f-ghOkuYZb4(!?$&vZmN19%JM_hO%Zh(Pfk@TQo|R?W`q6c4%Z}
z?Y5EefPmtNS|_N$W&pHPfqN)onlH=X2X@{mK4bz_yhU9cc~tN=B?FhRh%=N-tl&eu
zLn(n8t!F4%@Y%iZQnK+La~9xO_P-dm@ct8wS~$y}t)5^k5R=_vyYNL4YRGH|3xAG?
zq?t@%QXUd}<{?2VwZ8%R8cKxFDN#w6h(m=cwx^nAhy(+zr)JL^bGi`Yso7nY!A=$K
z!zvzN;2Y7~WkW8qMtEaOae}L4+0<98i*~ZJroI~QPxX9|Fr+$;YdDWN!ZERmc}g)1
z;4(fS>Nr2aGbC21p67`8h?1$vyoVW1`5wY#X#~jKiwXEYW2a
zS@vpaOqiUT0e84XsEXXp{EopJkKl|99bi}}Jiw8WR3NkOhDVMDa#G|GE(bW)e+~o#
zY$l{e$#f5MMbqyQ(!canez@-pTEImDlo_a(!Qx6f#7atQ#iQU^
zsser`7JbT&l^=>UizUPP@9f~q4MgbkaT=@8?>nBy-Owds!WYpz;u_l@62}~>yP-kfWY<($`8EsyNg)+n5+CKjdWN78Rxd=Dz
zTzV8(qt04=o1meKic
bKBQ`WYOgTvmMA=
+
+
+
+ 登录页
+
+
+
+
+ 欢迎来到登录页面
+
+
+
+
+
\ No newline at end of file
diff --git a/sso-main/pom.xml b/sso-main/pom.xml
new file mode 100644
index 0000000..9cc0835
--- /dev/null
+++ b/sso-main/pom.xml
@@ -0,0 +1,20 @@
+
+
+ 4.0.0
+
+ cc.bnblogs
+ use-cookie-sso
+ 1.0-SNAPSHOT
+
+
+ sso-main
+
+
+ 8
+ 8
+ UTF-8
+
+
+
\ No newline at end of file
diff --git a/sso-main/src/main/java/cc/bnblogs/MainApplication.java b/sso-main/src/main/java/cc/bnblogs/MainApplication.java
new file mode 100644
index 0000000..5a172b4
--- /dev/null
+++ b/sso-main/src/main/java/cc/bnblogs/MainApplication.java
@@ -0,0 +1,28 @@
+package cc.bnblogs;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.context.annotation.Bean;
+import org.springframework.web.client.RestTemplate;
+
+/**
+ * @description: 网站首页
+ * @author: zfp@bnblogs.cc
+ * @date: 2023/3/12 15:40
+ */
+@SpringBootApplication
+public class MainApplication {
+ public static void main(String[] args) {
+ SpringApplication.run(MainApplication.class,args);
+ }
+
+ /**
+ * RestTemplate是由Spring框架提供的一个可用于应用中调用rest服务的类它简化了与http服务的通信方式
+ * 需要手动将RestTemplate注入到Bean容器中
+ * @return
+ */
+ @Bean
+ public RestTemplate restTemplate() {
+ return new RestTemplate();
+ }
+}
diff --git a/sso-main/src/main/java/cc/bnblogs/controller/ViewController.java b/sso-main/src/main/java/cc/bnblogs/controller/ViewController.java
new file mode 100644
index 0000000..ec1e13c
--- /dev/null
+++ b/sso-main/src/main/java/cc/bnblogs/controller/ViewController.java
@@ -0,0 +1,48 @@
+package cc.bnblogs.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.GetMapping;
+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;
+
+
+/**
+ * @description: 网站主页
+ * @author: zfp@bnblogs.cc
+ * @date: 2023/3/12 16:12
+ */
+@Controller
+@RequestMapping("/view")
+public class ViewController {
+
+ @Autowired
+ private RestTemplate restTemplate;
+
+ private final String LOGIN_INFO_ADDR = "http://login.codeshop.com:8081/login/info?token=";
+ @GetMapping("/index")
+ /**
+ * 跳转到index.html
+ * 没有登录的时候没有cookie值,所以required要设为false
+ */
+ public String toIndex(@CookieValue(required = false,value = "TOKEN")Cookie cookie,
+ HttpSession httpSession) {
+ if (cookie != null) {
+ String token = cookie.getValue();
+ if (!StringUtils.isEmpty(token)) {
+ // 访问/login/info接口时带上token请求登录用户信息
+ Map result = restTemplate.getForObject(LOGIN_INFO_ADDR + token,
+ Map.class);
+ // 保存登录用户
+ httpSession.setAttribute("loginUser",result);
+ }
+ }
+ return "index";
+ }
+}
diff --git a/sso-main/src/main/resources/application.yml b/sso-main/src/main/resources/application.yml
new file mode 100644
index 0000000..0884131
--- /dev/null
+++ b/sso-main/src/main/resources/application.yml
@@ -0,0 +1,2 @@
+server:
+ port: 8082
\ No newline at end of file
diff --git a/sso-main/src/main/resources/templates/index.html b/sso-main/src/main/resources/templates/index.html
new file mode 100644
index 0000000..ea9ef08
--- /dev/null
+++ b/sso-main/src/main/resources/templates/index.html
@@ -0,0 +1,23 @@
+
+
+
+
+ 首页
+
+
+ 欢迎来到codeshop首页
+
+ 已登录
+
+
+
+ 登录
+ 退出
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/sso-main/target/classes/application.yml b/sso-main/target/classes/application.yml
new file mode 100644
index 0000000..0884131
--- /dev/null
+++ b/sso-main/target/classes/application.yml
@@ -0,0 +1,2 @@
+server:
+ port: 8082
\ No newline at end of file
diff --git a/sso-main/target/classes/cc/bnblogs/MainApplication.class b/sso-main/target/classes/cc/bnblogs/MainApplication.class
new file mode 100644
index 0000000000000000000000000000000000000000..c26536760088ca82a149e79bcfa2c3b0cfa0aa68
GIT binary patch
literal 964
zcmb7C+invv5IxSlOXww(LPNQ~q(NW_Azp$iwUKyA0X0=n#gljIZe2EZZM3!aKV
z;sf|7#CVg?1%(GzT90QubA0BEfBgLV9l$d@3{XS6j#~k?aJ!B>0V>|V%TRlvv~oKP
z<<9nqq0%?Ul3`__w0xC~Lun61m{6oOFp)?`!Yc32f)#hFQiiQT6!B1piHTFbFO=S$
zOcE6dr;P3q=9oeZ8=ZH9Gx0(2MCh0gomD#S<#!4j6Uwy(#|*3c(w&;)H^Pdsbkb5{
z)5_Ex%JC!-j+pVz_Q2SfrxTBO;`7dpeb3Kj$fHC_?f5~VfCz0KWZJ2*9H~@MGrL+F
zmy;#%#|yC{qn-TdxcHsQ_oVR61w)hBNWN5Fr1ig=f8zUP*jb1f8bg4YGX#F3;>=1u
z%v;!_gQ9{>)X`vQ|6Alb?lo~A4;UW(hY}?27um)MuQ@26mQXACH2VA
qv&H%h?&%!v8!AT^sD7gJBAxahP*XbBDaVuD$a8Px>rKp~o4_vxdG<*F
literal 0
HcmV?d00001
diff --git a/sso-main/target/classes/cc/bnblogs/controller/ViewController.class b/sso-main/target/classes/cc/bnblogs/controller/ViewController.class
new file mode 100644
index 0000000000000000000000000000000000000000..e01f8cc62e91636b797c1e11269f2f39a76b79ed
GIT binary patch
literal 2039
zcmb7FYgZdp6x}xo83;qc(2CfKTKnKVv_hrO7I~L8B$Y?Bl#7
zb}gkomM%Z}!5`&v-${yz&T`e2HTQYW+2@|K&&eNu{`4z=Y3yatgV|2p?LrskGMLA`
z4DREB-YyvUJOcx>1{U?aq=#h#D+X3GSi^cJ9(H2`k2>*Kzzk%lc4W2Y+DZycw0O@p*y4t-7b2sw_I8Q*z~^=lRN3j_-v6v$3{H
z()L1Y-!3aZIJN9^1#7Xc{1YdT6`JkM71lTM&o}aGh3AVaD_a8D+zb2Iwp`mgu(p+U
zk77N`1X8xAind#)_vw3%=coq)$>EWrKx)~q@U%DQcrstFmSnJF(@Aa2FWYX>4jjF2
z9;VcxL$7b-%4MtMm0bTIw93Ax0^fCIU=kH>d>z|u{9f%3>c#6*u-j*lpL?pn$vZu
zXsOo7R>yHOOBSVc+^)8h=NzJqMKf;=)_8M71;(i}kYCp|osz5=Fm5}A$E$gP%(h<-
z%5u%oMCfnN>ZA^~z*sC~$j3`xoz^5%+roo*n#Vmzxm(bZ=j0!n13NXte6CUq!KIVB6n%dmpErN=eT~a
zDUsls?B#fwCwHkMICqb}h8WEzzDM#^BzT2mhL@mn3Rmy}S7t*LL->$8_9jB7A~UZz
zckpa!>~}mEJ3}fz@dG-(!R^uSkp3CQ)7R+CCeDzV;CF`ZteN};J!iP^8_c=Xc(!*i
z^&|R{$iDL}tt5#Dx|rs8jh3(Tfj7{HVa#9*3z&?&nI_^4eY}cKDAR>IlpUZhy=Z!<
zSJ$bjAGm~@)K6f9>m2N7a|I6%LSk443)XSjv&5Vv`l
Uz^BnT9jRrxpW*(_x$0+s0bA`ZYybcN
literal 0
HcmV?d00001
diff --git a/sso-main/target/classes/templates/index.html b/sso-main/target/classes/templates/index.html
new file mode 100644
index 0000000..ea9ef08
--- /dev/null
+++ b/sso-main/target/classes/templates/index.html
@@ -0,0 +1,23 @@
+
+
+
+
+ 首页
+
+
+ 欢迎来到codeshop首页
+
+ 已登录
+
+
+
+ 登录
+ 退出
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/sso-vip/pom.xml b/sso-vip/pom.xml
new file mode 100644
index 0000000..387c7d3
--- /dev/null
+++ b/sso-vip/pom.xml
@@ -0,0 +1,20 @@
+
+
+ 4.0.0
+
+ cc.bnblogs
+ use-cookie-sso
+ 1.0-SNAPSHOT
+
+
+ sso-vip
+
+
+ 8
+ 8
+ UTF-8
+
+
+
\ No newline at end of file
diff --git a/sso-vip/src/main/java/cc/bnblogs/VipApplication.java b/sso-vip/src/main/java/cc/bnblogs/VipApplication.java
new file mode 100644
index 0000000..3823da7
--- /dev/null
+++ b/sso-vip/src/main/java/cc/bnblogs/VipApplication.java
@@ -0,0 +1,22 @@
+package cc.bnblogs;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.context.annotation.Bean;
+import org.springframework.web.client.RestTemplate;
+
+/**
+ * @description:
+ * @author: zfp@bnblogs.cc
+ * @date: 2023/3/12 15:42
+ */
+@SpringBootApplication
+public class VipApplication {
+ public static void main(String[] args) {
+ SpringApplication.run(VipApplication.class,args);
+ }
+ @Bean
+ public RestTemplate restTemplate() {
+ return new RestTemplate();
+ }
+}
diff --git a/sso-vip/src/main/java/cc/bnblogs/controller/ViewController.java b/sso-vip/src/main/java/cc/bnblogs/controller/ViewController.java
new file mode 100644
index 0000000..aec7dd6
--- /dev/null
+++ b/sso-vip/src/main/java/cc/bnblogs/controller/ViewController.java
@@ -0,0 +1,40 @@
+package cc.bnblogs.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.GetMapping;
+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;
+
+/**
+ * @description:
+ * @author: zfp@bnblogs.cc
+ * @date: 2023/3/12 16:17
+ */
+@Controller
+@RequestMapping("/view")
+public class ViewController {
+ @Autowired
+ private RestTemplate restTemplate;
+
+ private final String LOGIN_INFO_ADDR = "http://login.codeshop.com:8081/login/info?token=";
+
+ @GetMapping("/index")
+ public String toIndex(@CookieValue(required = false,value = "TOKEN")Cookie cookie,
+ HttpSession httpSession) {
+ if (cookie != null) {
+ String token = cookie.getValue();
+ if (!StringUtils.isEmpty(token)) {
+ Map result = restTemplate.getForObject(LOGIN_INFO_ADDR + token, Map.class);
+ httpSession.setAttribute("loginUser",result);
+ }
+ }
+ return "index";
+ }
+}
diff --git a/sso-vip/src/main/resources/application.yml b/sso-vip/src/main/resources/application.yml
new file mode 100644
index 0000000..9899989
--- /dev/null
+++ b/sso-vip/src/main/resources/application.yml
@@ -0,0 +1,2 @@
+server:
+ port: 8083
\ No newline at end of file
diff --git a/sso-vip/src/main/resources/templates/index.html b/sso-vip/src/main/resources/templates/index.html
new file mode 100644
index 0000000..bfdea56
--- /dev/null
+++ b/sso-vip/src/main/resources/templates/index.html
@@ -0,0 +1,18 @@
+
+
+
+
+ vip系统
+
+
+ 这里是Vip系统
+
+ 已登录
+
+
+
+ 登录
+ 退出
+
+
+
\ No newline at end of file
diff --git a/sso-vip/target/classes/application.yml b/sso-vip/target/classes/application.yml
new file mode 100644
index 0000000..9899989
--- /dev/null
+++ b/sso-vip/target/classes/application.yml
@@ -0,0 +1,2 @@
+server:
+ port: 8083
\ No newline at end of file
diff --git a/sso-vip/target/classes/cc/bnblogs/VipApplication.class b/sso-vip/target/classes/cc/bnblogs/VipApplication.class
new file mode 100644
index 0000000000000000000000000000000000000000..bc7e9ff7331219e2e51ecade888b93f4168027e1
GIT binary patch
literal 961
zcmb7C%We}f6g|$nL+B$dg;L&Z(jc&e5SyS%Z6sFVp{5E#tUOb9>N2q-kB9PEuqpzH
z58$H^*OP=!rD4HH<7?l?@ww;v*YEE?0X)OQ01e!1VmrVs+-~AdfSNzwWoW!mTDe_@
zYIkSMP#c&d$*?k1TE5OEp|po0Ovuw2nn)yLVU<76oi%r&Qikne6!B1piHTD_R@1%d
zG*OXo%IH2pPK447o81q?Q}IdgMCh20oK-sR=T{0F6Ucf=m|^vmbSLKMt*~MuowStL
zwlZ~xaxzVXBVxR}Gc-2l>C_`0`@Az_Kk_pf@+eVKJAP0oAVOOQnRaR-$0}9S%bwQ8
zU}Q2I$(PD&w0^nwC%#>V-BQTV7{be(A?#xnXIAo2
z-oZWviUPLLM2krOQ{pD>wQ(O07#{tH4kYcxG~R@#GI9*PGJu@vj9Y;hJs6wOSi^2%
zs)IzNX}@HU>{U7~VHqow<%^$_^~J4DrS}chcNg^mMSxYhXsv+JBF`H6JM`B{Ju)H0VX@yFm1-X|tB$Z3F@09j8ua&*eSuInR4}-ZyXleDynkDeR@ujhPPI=|m@H)0o5E
zH11(uZx;-Fm4<;C1B-fI(!;WW6$7hjtYN(a_q(ux2OW4QUS;Q`T0K`kX-jR?SmRMHZaUDY|me^L%A1$M-^knb^0A
z()L1Y-!3UXIJNBa3)W&y`6o^w%Y3#cn_u6^J>AHy<)1FDtZWHnvd`>e+j4F1z}i;Y
zJgRjs6G+*fD%fs~*0B8;*0Vomr{5O4}Z}T~m&0ZQ51BwkiKedi1pvy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