diff --git a/README.md b/README.md
index 57c0911d..3c300e09 100644
--- a/README.md
+++ b/README.md
@@ -159,4 +159,17 @@ central-platform -- 父项目,公共依赖
 |
 |
-
\ No newline at end of file
+
+
+
+## 8.友情链接
+
+### flowsphere
+
+云原生微服务流量治理解决方案,项目地址:https://github.com/flowsphere-projects/flowsphere
+
+项目亮点:
+
+1.全网唯一使用JavaAgent实现Http、MQ、Job全链路灰度
+
+2.全网唯一支持JavaAgent接入Sentinel
\ No newline at end of file
diff --git a/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/config/DefaultResourceServerConf.java b/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/config/DefaultResourceServerConf.java
index 9fb0101c..9d1a7f64 100644
--- a/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/config/DefaultResourceServerConf.java
+++ b/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/config/DefaultResourceServerConf.java
@@ -3,10 +3,12 @@ package com.central.oauth2.common.config;
import cn.hutool.extra.spring.SpringUtil;
import com.central.oauth2.common.component.CustomAuthorizationServiceIntrospector;
import com.central.oauth2.common.component.CustomBearerTokenResolver;
+import com.central.oauth2.common.enums.TokenType;
import com.central.oauth2.common.properties.SecurityProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;
import org.springframework.http.HttpMethod;
+import org.springframework.security.config.Customizer;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
@@ -45,7 +47,7 @@ public class DefaultResourceServerConf {
private AccessDeniedHandler oAuth2AccessDeniedHandler;
@Bean
- public SecurityFilterChain springSecurityFilterChain(HttpSecurity http) throws Exception {
+ public SecurityFilterChain defaultSecurityFilterChain(HttpSecurity http) throws Exception {
http.authorizeHttpRequests(authorizeRequests -> {
AuthorizeHttpRequestsConfigurer.AuthorizedUrl authorizedUrl = authorizeRequests
.requestMatchers(HttpMethod.OPTIONS).permitAll()
@@ -64,8 +66,13 @@ public class DefaultResourceServerConf {
http.oauth2ResourceServer(oauth2 -> {
oauth2.authenticationEntryPoint(authenticationEntryPoint)
.bearerTokenResolver(customBearerTokenResolver)
- .accessDeniedHandler(oAuth2AccessDeniedHandler)
- .opaqueToken(token -> token.introspector(this.getOpaqueTokenIntrospector()));
+ .accessDeniedHandler(oAuth2AccessDeniedHandler);
+ if (TokenType.JWT.getName().equals(securityProperties.getResourceServer().getTokenType())) {
+ oauth2.jwt(Customizer.withDefaults());
+ } else {
+ oauth2.opaqueToken(token -> token.introspector(this.getOpaqueTokenIntrospector()));
+ }
+ //.opaqueToken(token -> token.introspector(this.getOpaqueTokenIntrospector()));
});
return http.build();
diff --git a/zlt-commons/zlt-common-core/src/main/java/com/central/common/utils/ResponseUtil.java b/zlt-commons/zlt-common-core/src/main/java/com/central/common/utils/ResponseUtil.java
index 9a4ab54d..be1cb350 100644
--- a/zlt-commons/zlt-common-core/src/main/java/com/central/common/utils/ResponseUtil.java
+++ b/zlt-commons/zlt-common-core/src/main/java/com/central/common/utils/ResponseUtil.java
@@ -54,7 +54,7 @@ public class ResponseUtil {
}
private static void responseWrite(ObjectMapper objectMapper, HttpServletResponse response, Result result) throws IOException {
- response.setContentType(MediaType.APPLICATION_JSON_VALUE);
+ response.setContentType(MediaType.APPLICATION_JSON_UTF8_VALUE);
try (
Writer writer = response.getWriter()
) {
diff --git a/zlt-demo/resources-server-demo/src/main/java/org/zlt/config/MyResourceConfig.java b/zlt-demo/resources-server-demo/src/main/java/org/zlt/config/MyResourceConfig.java
index 482aef1e..9b93d2b8 100644
--- a/zlt-demo/resources-server-demo/src/main/java/org/zlt/config/MyResourceConfig.java
+++ b/zlt-demo/resources-server-demo/src/main/java/org/zlt/config/MyResourceConfig.java
@@ -1,7 +1,7 @@
package org.zlt.config;
+import com.central.oauth2.common.config.DefaultResourceServerConf;
import org.springframework.context.annotation.Configuration;
-//import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
/**
* security资源服务器配置
@@ -13,7 +13,6 @@ import org.springframework.context.annotation.Configuration;
* Blog: http://zlt2000.gitee.io
* Github: https://github.com/zlt2000
*/
-/*@Configuration
-@EnableResourceServer
+@Configuration
public class MyResourceConfig extends DefaultResourceServerConf {
-}*/
+}
diff --git a/zlt-demo/sso-demo/oidc-sso/src/main/java/com/sso/demo/controller/ApiController.java b/zlt-demo/sso-demo/oidc-sso/src/main/java/com/sso/demo/controller/ApiController.java
index 51a8f37e..67773140 100644
--- a/zlt-demo/sso-demo/oidc-sso/src/main/java/com/sso/demo/controller/ApiController.java
+++ b/zlt-demo/sso-demo/oidc-sso/src/main/java/com/sso/demo/controller/ApiController.java
@@ -1,10 +1,9 @@
package com.sso.demo.controller;
-import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
-import com.central.common.model.Result;
+import cn.hutool.json.JSONArray;
+import cn.hutool.json.JSONObject;
import com.central.common.utils.JsonUtil;
-import com.central.common.utils.RsaUtils;
import com.fasterxml.jackson.databind.JsonNode;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
@@ -24,8 +23,14 @@ import org.springframework.web.client.RestTemplate;
import org.apache.commons.codec.binary.Base64;
import jakarta.servlet.http.HttpServletRequest;
+
+import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
+import java.security.KeyFactory;
+import java.security.NoSuchAlgorithmException;
import java.security.interfaces.RSAPublicKey;
+import java.security.spec.InvalidKeySpecException;
+import java.security.spec.RSAPublicKeySpec;
import java.util.*;
/**
@@ -38,9 +43,6 @@ import java.util.*;
@Slf4j
@RestController
public class ApiController {
- private static final String PUBKEY_START = "-----BEGIN PUBLIC KEY-----";
- private static final String PUBKEY_END = "-----END PUBLIC KEY-----";
-
@Value("${zlt.sso.client-id:}")
private String clientId;
@@ -64,36 +66,32 @@ public class ApiController {
/**
* 模拟用户数据库
*/
- private static final Map userDb = new HashMap<>();
+ private static final Map userDb = new HashMap<>();
- /**
- * nonce存储
- */
- private final static ThreadLocal NONCE = new ThreadLocal<>();
-
- private final static Map localTokenMap = new HashMap<>();
+ private final static Map localTokenMap = new HashMap<>();
@GetMapping("/token/{code}")
public Map tokenInfo(@PathVariable String code) throws Exception {
//获取token
Map tokenMap = getAccessToken(code);
- String idTokenStr = (String)tokenMap.get("id_token");
+ Map datasMap = (Map)tokenMap.get("datas");
+ String idTokenStr = (String)datasMap.get("id_token");
//解析id_token
JsonNode idToken = this.getIdTokenJson(idTokenStr);
//检查id_token的有效性
checkToken(idToken);
//获取用户信息
- MyUser user = this.getUserInfo(idToken);
+ String username = idToken.get("sub").asText();
//判断用户信息是否存在,否则注册用户信息
- if (!userDb.containsKey(user.getId())) {
- userDb.put(user.getId(), user);
+ if (!userDb.containsKey(username)) {
+ userDb.put(username, username);
}
- String accessToken = (String)tokenMap.get("access_token");
- localTokenMap.put(accessToken, user);
+ String accessToken = (String)datasMap.get("access_token");
+ localTokenMap.put(accessToken, username);
Map result = new HashMap<>(2);
- result.put("tokenInfo", tokenMap);
- result.put("userInfo", user);
+ result.put("tokenInfo", datasMap);
+ result.put("userInfo", username);
return result;
}
@@ -109,7 +107,7 @@ public class ApiController {
}
@GetMapping("/user")
- public MyUser user(HttpServletRequest request) {
+ public String user(HttpServletRequest request) {
String token = request.getParameter("access_token");
return localTokenMap.get(token);
}
@@ -121,15 +119,11 @@ public class ApiController {
//token有效期
long expiresAt = idToken.get("exp").asLong();
long now = System.currentTimeMillis();
- Assert.isTrue((expiresAt > now), "id_token已过期");
+ //Assert.isTrue((expiresAt > now), "id_token已过期");
//应用id
String aud = idToken.get("aud").asText();
Assert.isTrue(clientId.equals(aud), "非法应用"+aud);
-
- //随机码
- String nonce = idToken.get("nonce").asText();
- Assert.isTrue((StrUtil.isEmpty(nonce) || nonce.equals(NONCE.get())), "nonce参数无效");
}
/**
@@ -147,18 +141,11 @@ public class ApiController {
param.add("grant_type", "authorization_code");
param.add("redirect_uri", redirectUri);
param.add("scope", "all");
- param.add("nonce", this.genNonce());
HttpEntity> request = new HttpEntity<>(param, headers);
ResponseEntity