From d053df88d13879fe1d0ea3cc7ddda0be11b966ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E5=B0=8F=E4=BA=91?= Date: Sat, 19 Jul 2025 09:06:49 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=BB=98=E8=AE=A4=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gateway/.idea/workspace.xml | 6 +- gateway/target/classes/application.properties | 15 -- .../tuoheng/gateway/GatewayApplication.class | Bin 748 -> 0 bytes .../gateway/config/SecurityConfig.class | Bin 3453 -> 0 bytes .../oauth/oidc/config/SecurityConfig.java | 8 +- .../oidc/controller/LoginController.java | 32 +++ oidc/src/main/resources/static/login.html | 235 ++++++++++++++++++ .../target/classes/application.properties | 1 - .../resourceservice/HelloController.class | Bin 1223 -> 0 bytes .../ResourceServiceApplication.class | Bin 788 -> 0 bytes .../target/classes/application.properties | 1 - .../resourceservice/HelloController.class | Bin 1223 -> 0 bytes .../ResourceServiceApplication.class | Bin 788 -> 0 bytes 13 files changed, 279 insertions(+), 19 deletions(-) delete mode 100644 gateway/target/classes/application.properties delete mode 100644 gateway/target/classes/com/tuoheng/gateway/GatewayApplication.class delete mode 100644 gateway/target/classes/com/tuoheng/gateway/config/SecurityConfig.class create mode 100644 oidc/src/main/java/com/tuoheng/oauth/oidc/controller/LoginController.java create mode 100644 oidc/src/main/resources/static/login.html delete mode 100644 resourceservice/target/classes/application.properties delete mode 100644 resourceservice/target/classes/com/tuoheng/resourceservice/HelloController.class delete mode 100644 resourceservice/target/classes/com/tuoheng/resourceservice/ResourceServiceApplication.class delete mode 100644 resourceserviceb/target/classes/application.properties delete mode 100644 resourceserviceb/target/classes/com/tuoheng/resourceservice/HelloController.class delete mode 100644 resourceserviceb/target/classes/com/tuoheng/resourceservice/ResourceServiceApplication.class diff --git a/gateway/.idea/workspace.xml b/gateway/.idea/workspace.xml index c7b02d0..353192a 100644 --- a/gateway/.idea/workspace.xml +++ b/gateway/.idea/workspace.xml @@ -5,7 +5,10 @@ - + + + + diff --git a/gateway/target/classes/application.properties b/gateway/target/classes/application.properties deleted file mode 100644 index 83f1639..0000000 --- a/gateway/target/classes/application.properties +++ /dev/null @@ -1,15 +0,0 @@ -server.port=8080 - -spring.cloud.gateway.routes[0].id=resource-server-a -spring.cloud.gateway.routes[0].uri=http://localhost:8081 -spring.cloud.gateway.routes[0].predicates[0]=Path=/a/** -spring.cloud.gateway.routes[0].filters[0]=RewritePath=/a/(?.*), /api/${segment} -spring.cloud.gateway.routes[0].filters[1]=TokenRelay - -spring.cloud.gateway.routes[1].id=resource-server-b -spring.cloud.gateway.routes[1].uri=http://localhost:8082 -spring.cloud.gateway.routes[1].predicates[0]=Path=/b/** -spring.cloud.gateway.routes[1].filters[0]=RewritePath=/b/(?.*), /api/${segment} -spring.cloud.gateway.routes[1].filters[1]=TokenRelay - -spring.security.oauth2.resourceserver.jwt.jwk-set-uri=http://localhost:9000/oauth2/jwks \ No newline at end of file diff --git a/gateway/target/classes/com/tuoheng/gateway/GatewayApplication.class b/gateway/target/classes/com/tuoheng/gateway/GatewayApplication.class deleted file mode 100644 index 0e4fc1f970846a280ba821c5de9cb097ce7c3213..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 748 zcma)4O;6iE5PcgG986juP$;wurE1g%*aIm&<&SrE7$;SrvJlQ|45c;|>|*Q9a3KSenK*O9;&=a# zeo4>iIePr;@i%#VCNnV!4J`_M$lN9Geed&b&wKy;`^E17KEjVl^axB?Ud7ZkudLiv zb5&}!DYs3_b64zDv#6|^Z|m)RW0^!kAiX9xr0GZsFO=4lr3H>$w_RI*F3_8qSQJR) zy=9d`F9rl5TdGK^rk} z0w)CqtXiPGiv1IvIh}b8%s80&<`F-e!fA{qaYi7wZzmae18)ip$(k;EJ`v4rS!JdN zk=6DVgEnA$v!uiCF9mHF0wbY?XAQg)LObDw*rxBRz^nO|isBp!oHKA9?+NskYPPd1 zF#9@Bc3iwmz!PO=kU+j`Z2w#OvD)Spy}Eo)h6&8%X43RKvQk=>V^;*8?9IO&sCT++ zEVnam#j3Kh6N^bqc2s*&hn3Wii}aT%&B@6WF5^lProhs^lc+li16MIEU{s|p&r5BU z8xFXTd0c3bPy~yW+S-bEDVxLx0#6SK+E~uAR1l;vgKGx4^kaczVU{TtyG0UZHa&h_ zHpO-Mf5Ov`Ps1>j;xJq{@EJ(JN2R;nD!Y=PD)v zChWugS3>vnAiFk;;i|y1gD8fDuo`wSMO+Ul+{Eo9ZV5cve@^XokAXY*nvHaAlYMpN zK;pOCRbzKHb;C3^@Q5HuC|t_Zrc#OPGb zZ}d{?E_OY*lW*I4YFKu@l9skNlsV^y50NFlA)MM)6BxCoXFX2`+LzUch*|ItKx+I} z;Czd4Y%oLO>RO|WM2A1$0tCG~++!FXJ(?(VC$w>Jv=`K4e7%O<*daasm z6N^c%ZKvblgYBwn7vKAz(Uq@0+fJ>q=Dc*AqODbS@Cb?mC)-Vm*>_?wjYlcA;_nSy zK!$=((#XVnB?Dh!j(akVITHMB*X6^_kwKt>Bvu8+Uvh3Y7bRf}oPD(@vpe!9VRmhG z6o|N7;LL8hn}jD&I=r%P)}lZ%u1cJv>w5X(0}`C^9nEi&E0d$(*f;qc{l9Y3gA~8v z-{9;hzeXg$@fcSE$1zA%=~!xrW2k6}Cwn-ao_Ya3E$cY-0&j)m+e=e*y!#9Pic}91 z0jMfeG=LEbpJ-fjDmortLq!;?2AAgr=~%S(w1=ywb^ oauth2.jwt()) // 新增,支持JWT - .formLogin(Customizer.withDefaults()) + .formLogin(form -> form + .loginPage("/login") + .loginProcessingUrl("/login") + .defaultSuccessUrl("/") + .failureUrl("/login?error=bad_credentials") + .permitAll() + ) .cors(cors -> cors.configurationSource(corsConfigurationSource())) // 添加CORS支持 .csrf(csrf -> csrf.ignoringRequestMatchers("/logout")) // 禁用logout端点的CSRF保护 .logout(logout -> logout diff --git a/oidc/src/main/java/com/tuoheng/oauth/oidc/controller/LoginController.java b/oidc/src/main/java/com/tuoheng/oauth/oidc/controller/LoginController.java new file mode 100644 index 0000000..0f92908 --- /dev/null +++ b/oidc/src/main/java/com/tuoheng/oauth/oidc/controller/LoginController.java @@ -0,0 +1,32 @@ +package com.tuoheng.oauth.oidc.controller; + +import org.springframework.security.web.csrf.CsrfToken; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; + +import jakarta.servlet.http.HttpServletRequest; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; + +@RestController +public class LoginController { + + @GetMapping("/login") + @ResponseBody + public String login(HttpServletRequest request) throws IOException { + // 读取静态HTML文件 + String htmlContent = new String(Files.readAllBytes(Paths.get("src/main/resources/static/login.html"))); + + // 获取CSRF token + CsrfToken csrfToken = (CsrfToken) request.getAttribute(CsrfToken.class.getName()); + if (csrfToken != null) { + // 替换CSRF token占位符 + htmlContent = htmlContent.replace("id=\"csrf-parameter\" name=\"\" value=\"\"", + "id=\"csrf-parameter\" name=\"" + csrfToken.getParameterName() + "\" value=\"" + csrfToken.getToken() + "\""); + } + + return htmlContent; + } +} \ No newline at end of file diff --git a/oidc/src/main/resources/static/login.html b/oidc/src/main/resources/static/login.html new file mode 100644 index 0000000..73cc932 --- /dev/null +++ b/oidc/src/main/resources/static/login.html @@ -0,0 +1,235 @@ + + + + + + OIDC 登录 + + + + + + + + \ No newline at end of file diff --git a/resourceservice/target/classes/application.properties b/resourceservice/target/classes/application.properties deleted file mode 100644 index bafddce..0000000 --- a/resourceservice/target/classes/application.properties +++ /dev/null @@ -1 +0,0 @@ -server.port=8081 \ No newline at end of file diff --git a/resourceservice/target/classes/com/tuoheng/resourceservice/HelloController.class b/resourceservice/target/classes/com/tuoheng/resourceservice/HelloController.class deleted file mode 100644 index f5ffdcf30f8a079c5d90e338de7c091abba1275a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1223 zcmb7D?M@Rx6g|@xc3a99&%$+;;o^$WHzyJLB1z;Jg22u=_hVNQB@>{}dT1td|q#7a= z>PR+(wILkGU-vz&e8&;WK!#!DkRNf&;pDzuKNJnk(7!4@sn;0N<=H)k%(}lXa!4ba zM<4nbhHdGI_mNu{YM0j?!BDXM26y(jlJU7?%;=U38RqT(fK+AZYsDxTM$5Byf-Tb0 zv9@?XciEb3dR#|}axP!KUv0Z5RBBpDuUYM}w8>T1D9Xf6>u-O^5{ZKYbfZ&L%fhmwK&41?Wx6f2J@ zOjDbJh`P2?zRLEhrBl!lb&me=HIT&s{qt=HS_kPw^~NxT8lim(qbSfi zMAk9-#y^3DxRC_@f(+eLf}bdUJjE@$QkW>*`Hs73e5e#2oZ-cu7X0U{p1YkLNL7hu1D`ZLG71>gFodAt#Re`_W Ch&Y%4 diff --git a/resourceservice/target/classes/com/tuoheng/resourceservice/ResourceServiceApplication.class b/resourceservice/target/classes/com/tuoheng/resourceservice/ResourceServiceApplication.class deleted file mode 100644 index c558287df0153a799a7d02790457f71c97c70ff6..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 788 zcmbVKO;6iE5PcgG986juv`{D&;udn~-T)~TQX7erp@^XLz-etZ&Qg0fTCZvU7N=G{ z^au1uRh>1F@F84!@Qml{&CHwq^Y_K%?5nnQCdLo8vXgBF$< z)*_|lMVZIaUW+)B4Bf~iA{z^S^p>2zdY546!EzM!Wu>! aTi7Q58~R%G7)Uj+Q^{StCGFep0sjE6K-3-p diff --git a/resourceserviceb/target/classes/application.properties b/resourceserviceb/target/classes/application.properties deleted file mode 100644 index 8d51d0c..0000000 --- a/resourceserviceb/target/classes/application.properties +++ /dev/null @@ -1 +0,0 @@ -server.port=8082 \ No newline at end of file diff --git a/resourceserviceb/target/classes/com/tuoheng/resourceservice/HelloController.class b/resourceserviceb/target/classes/com/tuoheng/resourceservice/HelloController.class deleted file mode 100644 index 59c413afafee72fb47bfc1155472e569d315d3d5..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1223 zcmb7D?M@Rx6g@*rcUwwji?;0J{Y>jwy0LSjgikRk~s7~`*L8QQ_^?q+rt!UOm| z`U}*=2k@bccc(?5{J|!j*?aHIJ?EZ#=l7ofUn>@(CLc+!XgVh#c$eY5(Aj8DEa9zK+ zul#m#TZDe38lqSe>QFYsAEsB6>ns47xygO&!UJ)hTJ)w zs_!+a;6v_4Vr!paw6t-NNF1)%ctA(OPRTYN5p=H*7N!}>4ZrQ^$ZrW!UUjAFUUQ6! zYrdzI@47-UB-i{s!7x;no_HU%>q71Dx=WsX)o*Zjmn#|DU1w6a;$r5i|AA3q=x@c% zBVkJ2s!YSFHx#ppV&HqBA#tg36f9gOaU7fxS?sjwEYHe?uGO@XB-aH`XZ$LwlrUYB zO^@qH5!_NQn`>to-;TU^9(H9YNt`#H=WDJdRl%@O^;OdegP6p=;%#x{tIy7ns5^D( z?K%A4S?8V5Bta09C5cS$88QwJq|?ln(>*?KmEEbLRwee_L^m*$mn8agx zvGK1DL;xvTOJq5;Gur!SPr$yJ@C>bS7)WE5)@^4agmCGeq~A3H_i6ccCWRQ_T2^DCuEAciRrlNf+rJw}nk6us>^3>(-&Cv_Lr v#x!w#O7PFj4Voq6c}|`e_J6VmVsE#*;!*o7?W9aIWJqLI3qmWrUT=*lygiRp|Tc|5>xbp>L< z2k=o9*F&Ua5jI%zy}EDvocsL$@d>~ob{eQ)ET#uDw49P-i%ZO~zeehLX~(%uQiqnM-@4V#&|OcK_8r8I4jE3#W{3pn(qonoTTX ziJ@a`!t;?;I=QkUlefnH<&iOt_elW{BG1JQK;1BT+a*kd{!&F=O9}yeUY#*h4_;