CA Gateway 토큰 처리

1. 기존메모리에서 따로 관리하던것을 인터스끼리 공유 할수있도록 sessionManager에서 토큰을 관리.(CAToken 관리용
cache 추가 작업)

2. ApiAuthFilter.java 에 ca 방식 토큰 인증 로직 추가.

나머지는 CA토큰 발급(BearerTokenController)처리 및 BeareTokenInfo 는 어윤삼 부장 작업본 그대로
사용.
This commit is contained in:
cho
2026-01-08 11:06:35 +09:00
parent 8d21eba5e8
commit 48eee97caa
6 changed files with 202 additions and 3 deletions
@@ -0,0 +1,49 @@
package com.eactive.eai.authserver.service;
import java.util.Set;
import com.fasterxml.jackson.annotation.JsonProperty;
public class BearerTokenInfo {
@JsonProperty("client_id")
private String clientId;
private Long expiresIn;
private Long expiresAt;
private Set<String> scopeSet;
public String getClientId() {
return clientId;
}
public void setClientId(String clientId) {
this.clientId = clientId;
}
public Long getExpiresIn() {
return expiresIn;
}
public void setExpiresIn(Long expiresIn) {
this.expiresIn = expiresIn;
}
public Long getExpiresAt() {
return expiresAt;
}
public void setExpiresAt(Long expiresIn) {
this.expiresAt = System.currentTimeMillis() + (expiresIn * 1000);
}
public Set<String> getScopeSet() {
return scopeSet;
}
public void setScopeSet(Set<String> scopeSet) {
this.scopeSet = scopeSet;
}
public boolean isExpired() {
return System.currentTimeMillis() > expiresAt;
}
}
@@ -0,0 +1,73 @@
package com.eactive.eai.authserver.service;
import java.security.SecureRandom;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import javax.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.eactive.eai.common.session.SessionManager;
import com.eactive.eai.common.session.SessionManagerForIgnite;
@Service
public class BearerTokenService {
public String generateCAToken(String clientId, Long expiresIn, Set<String> scopeSet) {
String token = UUID.randomUUID().toString();
BearerTokenInfo CATokenInfo = new BearerTokenInfo();
CATokenInfo.setClientId(clientId);
CATokenInfo.setExpiresIn(expiresIn);
CATokenInfo.setExpiresAt(expiresIn);
CATokenInfo.setScopeSet(scopeSet);
//CATokenStore.put(token, CATokenInfo);
SessionManager.getInstance().putCAToken(token, CATokenInfo);
return token;
}
public boolean validateCA(String token) {
BearerTokenInfo CATokenInfo = SessionManager.getInstance().getCAToken(token);
if (CATokenInfo == null) return false;
if (CATokenInfo.isExpired()) {
SessionManager.getInstance().removeCAToken(token);
return false;
}else {
return true;
}
}
public String getClientIdFromCA(String token) {
BearerTokenInfo CATokenInfo = SessionManager.getInstance().getCAToken(token);
return CATokenInfo.getClientId();
}
// private static final String CHARACTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
// private static final SecureRandom secureRandom = new SecureRandom();
//
// public static String generateTokenString(int length) {
// // Java 8의 IntStream과 Collectors.joining을 사용한 효율적인 방법
// return IntStream.range(0, length)
// .map(i -> secureRandom.nextInt(CHARACTERS.length()))
// .mapToObj(CHARACTERS::charAt)
// .map(String::valueOf)
// .collect(Collectors.joining());
// }
}