|
1 | 1 | package com.datamate.gateway.infrastructure.client.impl; |
2 | 2 |
|
| 3 | +import com.alibaba.fastjson2.JSON; |
| 4 | +import com.alibaba.fastjson2.JSONException; |
| 5 | +import com.alibaba.fastjson2.JSONObject; |
3 | 6 | import com.datamate.gateway.common.config.SslIgnoreHttpClientFactory; |
4 | 7 | import com.datamate.gateway.infrastructure.client.OmsService; |
5 | 8 | import com.fasterxml.jackson.databind.ObjectMapper; |
6 | 9 |
|
7 | | -import lombok.Data; |
8 | 10 | 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; |
10 | 13 | import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; |
11 | 14 | import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; |
12 | 15 | import org.apache.hc.core5.http.ParseException; |
|
15 | 18 | import org.springframework.stereotype.Service; |
16 | 19 |
|
17 | 20 | import java.io.IOException; |
18 | | -import java.util.List; |
19 | 21 |
|
20 | 22 | /** |
21 | 23 | * OmsServiceImpl is a service that interacts with the OMS service. |
@@ -56,41 +58,27 @@ public OmsServiceImpl( |
56 | 58 | @Override |
57 | 59 | public String getUserNameFromOms(String authToken, String csrfToken, String realIp) { |
58 | 60 | 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); |
63 | 63 | httpPost.setHeader(AUTH_TOKEN_NEW_HEADER_KEY, authToken); |
64 | 64 | httpPost.setHeader(CSRF_TOKEN_NEW_HEADER_KEY, csrfToken); |
65 | 65 | httpPost.setHeader(REAL_IP_HEADER_KEY, realIp); |
66 | 66 |
|
67 | 67 | CloseableHttpResponse response = httpClient.execute(httpPost); |
68 | 68 | 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()); |
75 | 77 | return null; |
76 | 78 | } |
77 | | - |
78 | | - return resultVo.getData().get(0); |
79 | 79 | } catch (IOException | ParseException e) { |
80 | 80 | log.error("Failed to get user name from OMS service", e); |
81 | 81 | return null; |
82 | 82 | } |
83 | 83 | } |
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 | | - } |
96 | 84 | } |
0 commit comments