Skip to content

Commit 32acc54

Browse files
committed
feat: use session url
1 parent 481e887 commit 32acc54

2 files changed

Lines changed: 16 additions & 29 deletions

File tree

backend/api-gateway/src/main/java/com/datamate/gateway/common/filter/OmsAuthFilter.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,9 @@ public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
8181
log.error("Authentication failed: Token is null or invalid.");
8282
return exchange.getResponse().setComplete();
8383
}
84-
String userGroupId = this.omsExtensionService.getUserGroupId(userName);
84+
log.info("Current oms username is: {}", userName);
8585
ServerHttpRequest newRequest = request.mutate()
8686
.header(USER_NAME_HEADER, userName)
87-
.header(USER_GROUP_ID_HEADER, userGroupId)
8887
.build();
8988

9089
return chain.filter(exchange.mutate().request(newRequest).build());

backend/api-gateway/src/main/java/com/datamate/gateway/infrastructure/client/impl/OmsServiceImpl.java

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
package com.datamate.gateway.infrastructure.client.impl;
22

3+
import com.alibaba.fastjson2.JSON;
4+
import com.alibaba.fastjson2.JSONException;
5+
import com.alibaba.fastjson2.JSONObject;
36
import com.datamate.gateway.common.config.SslIgnoreHttpClientFactory;
47
import com.datamate.gateway.infrastructure.client.OmsService;
58
import com.fasterxml.jackson.databind.ObjectMapper;
69

7-
import lombok.Data;
810
import lombok.extern.slf4j.Slf4j;
9-
import org.apache.hc.client5.http.classic.methods.HttpPost;
11+
12+
import org.apache.hc.client5.http.classic.methods.HttpGet;
1013
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
1114
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
1215
import org.apache.hc.core5.http.ParseException;
@@ -15,7 +18,6 @@
1518
import org.springframework.stereotype.Service;
1619

1720
import java.io.IOException;
18-
import java.util.List;
1921

2022
/**
2123
* OmsServiceImpl is a service that interacts with the OMS service.
@@ -56,41 +58,27 @@ public OmsServiceImpl(
5658
@Override
5759
public String getUserNameFromOms(String authToken, String csrfToken, String realIp) {
5860
try {
59-
String fullPath = this.omsServiceUrl + "/framework/v1/iam/roles/query-by-token";
60-
61-
HttpPost httpPost = new HttpPost(fullPath);
62-
61+
String fullPath = this.omsServiceUrl + "/framework/v1/sessions/current";
62+
HttpGet httpPost = new HttpGet(fullPath);
6363
httpPost.setHeader(AUTH_TOKEN_NEW_HEADER_KEY, authToken);
6464
httpPost.setHeader(CSRF_TOKEN_NEW_HEADER_KEY, csrfToken);
6565
httpPost.setHeader(REAL_IP_HEADER_KEY, realIp);
6666

6767
CloseableHttpResponse response = httpClient.execute(httpPost);
6868
String responseBody = EntityUtils.toString(response.getEntity());
69-
log.info("response code: {}, response body: {}", response.getCode(), responseBody);
70-
71-
ResultVo<List<String>> resultVo = objectMapper.readValue(responseBody,
72-
objectMapper.getTypeFactory().constructParametricType(ResultVo.class, List.class));
73-
74-
if (resultVo.getData() == null || resultVo.getData().isEmpty()) {
69+
log.info("response code: {}", response.getCode());
70+
71+
try {
72+
JSONObject jsonObject = JSON.parseObject(responseBody);
73+
JSONObject data = jsonObject.getJSONObject("data");
74+
return data.getString("userName");
75+
} catch (JSONException e) {
76+
log.error("Failed to parse response body: {}", e.getMessage());
7577
return null;
7678
}
77-
78-
return resultVo.getData().get(0);
7979
} catch (IOException | ParseException e) {
8080
log.error("Failed to get user name from OMS service", e);
8181
return null;
8282
}
8383
}
84-
85-
/**
86-
* ResultVo is a generic result wrapper.
87-
*
88-
* @param <T> the type of data
89-
*/
90-
@Data
91-
public static class ResultVo<T> {
92-
private Integer code;
93-
private String msg;
94-
private T data;
95-
}
9684
}

0 commit comments

Comments
 (0)