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 0e4fc1f..0000000 Binary files a/gateway/target/classes/com/tuoheng/gateway/GatewayApplication.class and /dev/null differ diff --git a/gateway/target/classes/com/tuoheng/gateway/config/SecurityConfig.class b/gateway/target/classes/com/tuoheng/gateway/config/SecurityConfig.class deleted file mode 100644 index 1ce7696..0000000 Binary files a/gateway/target/classes/com/tuoheng/gateway/config/SecurityConfig.class and /dev/null differ diff --git a/oidc/src/main/java/com/tuoheng/oauth/oidc/config/SecurityConfig.java b/oidc/src/main/java/com/tuoheng/oauth/oidc/config/SecurityConfig.java index bee28d9..42be227 100644 --- a/oidc/src/main/java/com/tuoheng/oauth/oidc/config/SecurityConfig.java +++ b/oidc/src/main/java/com/tuoheng/oauth/oidc/config/SecurityConfig.java @@ -84,7 +84,13 @@ public class SecurityConfig { .anyRequest().authenticated() ) .oauth2ResourceServer(oauth2 -> 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 f5ffdcf..0000000 Binary files a/resourceservice/target/classes/com/tuoheng/resourceservice/HelloController.class and /dev/null differ 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 c558287..0000000 Binary files a/resourceservice/target/classes/com/tuoheng/resourceservice/ResourceServiceApplication.class and /dev/null differ 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 59c413a..0000000 Binary files a/resourceserviceb/target/classes/com/tuoheng/resourceservice/HelloController.class and /dev/null differ diff --git a/resourceserviceb/target/classes/com/tuoheng/resourceservice/ResourceServiceApplication.class b/resourceserviceb/target/classes/com/tuoheng/resourceservice/ResourceServiceApplication.class deleted file mode 100644 index 022f4b0..0000000 Binary files a/resourceserviceb/target/classes/com/tuoheng/resourceservice/ResourceServiceApplication.class and /dev/null differ