(improvement)(auth) Support token key allocation based on the integration application. (#1119)

This commit is contained in:
lexluo09
2024-06-10 21:50:39 +08:00
committed by GitHub
parent 3f098a6364
commit 82a3e30472
9 changed files with 61 additions and 24 deletions

View File

@@ -6,6 +6,7 @@ import com.tencent.supersonic.auth.api.authentication.request.UserReq;
import java.util.List;
import java.util.Set;
import javax.servlet.http.HttpServletRequest;
/**
* UserAdaptor defines some interfaces for obtaining user and organization information
@@ -20,7 +21,7 @@ public interface UserAdaptor {
void register(UserReq userReq);
String login(UserReq userReq);
String login(UserReq userReq, HttpServletRequest request);
List<User> getUserByOrg(String key);

View File

@@ -1,6 +1,9 @@
package com.tencent.supersonic.auth.api.authentication.config;
import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;
import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
@@ -18,12 +21,18 @@ public class AuthenticationConfig {
@Value("${authentication.enable:false}")
private boolean enabled;
@Value("${authentication.token.secret:secret}")
private String tokenSecret;
@Value("${authentication.token.default.appKey:supersonic}")
private String tokenDefaultAppKey;
@Value("${authentication.token.appSecret:supersonic:secret}")
private String tokenAppSecret;
@Value("${authentication.token.http.header.key:Authorization}")
private String tokenHttpHeaderKey;
@Value("${authentication.token.http.app.key:App-Key}")
private String tokenHttpHeaderAppKey;
@Value("${authentication.app.appId:appId}")
private String appId;
@@ -35,4 +44,10 @@ public class AuthenticationConfig {
@Value("${authentication.token.timeout:7200000}")
private Long tokenTimeout;
public Map<String, String> getAppKeyToSecretMap() {
return Arrays.stream(this.tokenAppSecret.split(","))
.map(s -> s.split(":"))
.collect(Collectors.toMap(e -> e[0].trim(), e -> e[1].trim()));
}
}

View File

@@ -19,7 +19,7 @@ public interface UserService {
void register(UserReq userCmd);
String login(UserReq userCmd);
String login(UserReq userCmd, HttpServletRequest request);
Set<String> getUserAllOrgId(String userName);