Skip to content

Commit 89ccaad

Browse files
committed
fix tests
1 parent 8859e84 commit 89ccaad

File tree

7 files changed

+143
-103
lines changed

7 files changed

+143
-103
lines changed

.local.env

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
SENTRIUS_VERSION=1.1.325
1+
SENTRIUS_VERSION=1.1.334
22
SENTRIUS_SSH_VERSION=1.1.41
33
SENTRIUS_KEYCLOAK_VERSION=1.1.53
44
SENTRIUS_AGENT_VERSION=1.1.42
55
SENTRIUS_AI_AGENT_VERSION=1.1.263
66
LLMPROXY_VERSION=1.0.78
77
LAUNCHER_VERSION=1.0.82
8-
AGENTPROXY_VERSION=1.0.75
8+
AGENTPROXY_VERSION=1.0.85

.local.env.bak

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
SENTRIUS_VERSION=1.1.325
1+
SENTRIUS_VERSION=1.1.334
22
SENTRIUS_SSH_VERSION=1.1.41
33
SENTRIUS_KEYCLOAK_VERSION=1.1.53
44
SENTRIUS_AGENT_VERSION=1.1.42
55
SENTRIUS_AI_AGENT_VERSION=1.1.263
66
LLMPROXY_VERSION=1.0.78
77
LAUNCHER_VERSION=1.0.82
8-
AGENTPROXY_VERSION=1.0.75
8+
AGENTPROXY_VERSION=1.0.85

agent-proxy/src/main/java/io/sentrius/sso/config/SecurityConfig.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ private ReactiveJwtAuthenticationConverter grantedAuthoritiesExtractor() {
6565
@Bean
6666
public CorsConfigurationSource corsConfigurationSource() {
6767
CorsConfiguration config = new CorsConfiguration();
68+
log.info("Configuring CORS for agent API URL: {}", agentApiUrl);
6869
config.setAllowedOrigins(List.of(agentApiUrl));
6970
config.setAllowedMethods(List.of("GET", "POST", "OPTIONS"));
7071
config.setAllowedHeaders(List.of("*"));

agent-proxy/src/main/java/io/sentrius/sso/service/ActiveWebSocketSessionManager.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@
1111
import java.util.concurrent.ConcurrentHashMap;
1212
import java.util.stream.Collectors;
1313
import io.sentrius.sso.core.dto.TerminalLogDTO;
14+
import lombok.extern.slf4j.Slf4j;
1415
import org.springframework.stereotype.Component;
1516
import org.springframework.web.reactive.socket.WebSocketSession;
1617

18+
@Slf4j
1719
@Component
1820
public class ActiveWebSocketSessionManager {
1921
private final Map<String, WebSocketSession> sessions = new ConcurrentHashMap<>();
@@ -72,6 +74,7 @@ public List<TerminalLogDTO> getActiveSessions() {
7274
*/
7375
public List<Map<String, Object>> getAgentSessionDurations() {
7476
synchronized (completedAgentSessions) {
77+
log.info("Returning {} completed agent sessions", completedAgentSessions.size());
7578
return new ArrayList<>(completedAgentSessions);
7679
}
7780
}
@@ -103,7 +106,7 @@ public List<Map<String, Object>> getActiveAgentSessionDurations() {
103106
activeDurations.add(activeSession);
104107
}
105108
}
106-
109+
log.info("Returning {} active agent session durations", activeDurations.size());
107110
return activeDurations;
108111
}
109112
}

api/src/main/java/io/sentrius/sso/controllers/api/UserApiController.java

Lines changed: 122 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.lang.reflect.Field;
44
import java.security.GeneralSecurityException;
5+
import java.util.ArrayList;
56
import java.util.HashMap;
67
import java.util.List;
78
import java.util.Map;
@@ -14,6 +15,7 @@
1415
import io.sentrius.sso.core.annotations.LimitAccess;
1516
import io.sentrius.sso.core.config.SystemOptions;
1617
import io.sentrius.sso.core.controllers.BaseController;
18+
import io.sentrius.sso.core.exceptions.ZtatException;
1719
import io.sentrius.sso.core.model.security.UserType;
1820
import io.sentrius.sso.core.model.security.enums.UserAccessEnum;
1921
import io.sentrius.sso.core.model.users.User;
@@ -27,6 +29,7 @@
2729
import io.sentrius.sso.core.services.UserCustomizationService;
2830
import io.sentrius.sso.core.services.UserService;
2931
import io.sentrius.sso.core.services.agents.AgentService;
32+
import io.sentrius.sso.core.services.agents.ZeroTrustClientService;
3033
import io.sentrius.sso.core.services.security.CryptoService;
3134
import io.sentrius.sso.core.services.security.ZeroTrustAccessTokenService;
3235
import io.sentrius.sso.core.services.security.ZeroTrustRequestService;
@@ -35,6 +38,9 @@
3538
import jakarta.servlet.http.HttpServletRequest;
3639
import jakarta.servlet.http.HttpServletResponse;
3740
import lombok.extern.slf4j.Slf4j;
41+
import org.springframework.beans.factory.annotation.Value;
42+
import org.springframework.core.ParameterizedTypeReference;
43+
import org.springframework.http.HttpMethod;
3844
import org.springframework.http.HttpStatus;
3945
import org.springframework.http.ResponseEntity;
4046
import org.springframework.stereotype.Controller;
@@ -60,6 +66,11 @@ public class UserApiController extends BaseController {
6066
final ZeroTrustRequestService ztatRequestService;
6167
final ZeroTrustAccessTokenService ztatService;
6268
final AgentService agentService;
69+
final ZeroTrustClientService zeroTrustClientService;
70+
71+
72+
@Value("${agentproxy.externalUrl:}")
73+
private String agentProxyExternalUrl;
6374

6475
static Map<String, Field> fields = new HashMap<>();
6576
static {
@@ -78,7 +89,8 @@ protected UserApiController(
7889
UserCustomizationService userThemeService,
7990
SessionService sessionService,
8091
ZeroTrustRequestService ztatRequestService,
81-
ZeroTrustAccessTokenService ztatService, AgentService agentService
92+
ZeroTrustAccessTokenService ztatService, AgentService agentService,
93+
ZeroTrustClientService zeroTrustClientService
8294
) {
8395
super(userService, systemOptions, errorOutputService);
8496
this.hostGroupService = hostGroupService;
@@ -89,6 +101,7 @@ protected UserApiController(
89101
this.ztatRequestService = ztatRequestService;
90102
this.ztatService = ztatService;
91103
this.agentService = agentService;
104+
this.zeroTrustClientService = zeroTrustClientService;
92105
}
93106

94107
@GetMapping("list")
@@ -303,10 +316,117 @@ public String deleteType(@RequestParam("id") String dtoId) throws GeneralSecurit
303316
public ResponseEntity<Map<String, Integer>> getGraphData(HttpServletRequest request,
304317
HttpServletResponse response) {
305318
var username = userService.getOperatingUser(request,response, null).getUsername();
306-
var ret= sessionService.getGraphData(username);
319+
var ret= getGraphData(username);
307320

308321
return ResponseEntity.ok(ret);
309322
}
310323

324+
325+
public Map<String, Integer> getGraphData(String username) {
326+
List<Map<String, Object>> sessionDurations = sessionService.getGraphList(username);
327+
328+
// Add agent session durations
329+
List<Map<String, Object>> agentSessionDurations = getAgentSessionDurations();
330+
log.info("Fetched {} agent session durations", agentSessionDurations.size());
331+
log.info("Fetched {} agent session durations", agentSessionDurations.size());
332+
sessionDurations.addAll(agentSessionDurations);
333+
334+
Map<String, Integer> graphData = new HashMap<>();
335+
graphData.put("0-5 min", 0);
336+
graphData.put("5-15 min", 0);
337+
graphData.put("15-30 min", 0);
338+
graphData.put("30+ min", 0);
339+
340+
for (Map<String, Object> session : sessionDurations) {
341+
long durationMinutes = Long.valueOf ( session.get("durationMinutes").toString() );
342+
343+
if (durationMinutes <= 5) {
344+
graphData.put("0-5 min", graphData.get("0-5 min") + 1);
345+
} else if (durationMinutes <= 15) {
346+
graphData.put("5-15 min", graphData.get("5-15 min") + 1);
347+
} else if (durationMinutes <= 30) {
348+
graphData.put("15-30 min", graphData.get("15-30 min") + 1);
349+
} else {
350+
graphData.put("30+ min", graphData.get("30+ min") + 1);
351+
}
352+
}
353+
354+
return graphData;
355+
}
356+
357+
/**
358+
* Fetch agent session duration data from agent proxy service
359+
* @return List of agent session duration data
360+
*/
361+
private List<Map<String, Object>> getAgentSessionDurations() {
362+
List<Map<String, Object>> agentSessions = new ArrayList<>();
363+
364+
if (agentProxyExternalUrl == null || agentProxyExternalUrl.trim().isEmpty()) {
365+
log.warn("Agent proxy URL not configured, skipping agent session data");
366+
return agentSessions;
367+
}
368+
369+
try {
370+
371+
var resp = zeroTrustClientService.callAuthenticatedGetOnApi(agentProxyExternalUrl,"/api/v1/sessions/agent" +
372+
"/durations"
373+
, null);
374+
log.info("Fetched active agent session duration data: {}", resp);
375+
if (null != resp){
376+
var completedNode = JsonUtil.MAPPER.readTree(resp);
377+
Map<String, Object> completedMap = new HashMap<>();
378+
for(var node : completedNode) {
379+
node.fields().forEachRemaining(
380+
entry -> {
381+
completedMap.put(entry.getKey(), entry.getValue());
382+
log.info(
383+
"Processing agent session duration entry: {} = {}", entry.getKey(), entry.getValue());
384+
}
385+
386+
);
387+
}
388+
if (completedMap.size() > 0) {
389+
log.info("Adding completed agent session duration data: {}", completedMap);
390+
agentSessions.add(completedMap);
391+
}
392+
393+
}
394+
395+
396+
resp = zeroTrustClientService.callAuthenticatedGetOnApi(agentProxyExternalUrl,"/api/v1/sessions/agent/active-durations"
397+
, null);
398+
399+
log.info("Fetched active agent session duration data: {}", resp);
400+
if (null != resp){
401+
var completedNode = JsonUtil.MAPPER.readTree(resp);
402+
Map<String, Object> completedMap = new HashMap<>();
403+
for(var node : completedNode) {
404+
node.fields().forEachRemaining(
405+
entry -> {
406+
completedMap.put(entry.getKey(), entry.getValue());
407+
log.info(
408+
"Processing agent session duration entry: {} = {}", entry.getKey(), entry.getValue());
409+
}
410+
411+
);
412+
}
413+
if (completedMap.size() > 0) {
414+
log.info("Adding completed agent session duration data: {}", completedMap);
415+
agentSessions.add(completedMap);
416+
}
417+
418+
}
419+
420+
log.info("Fetched {} agent session duration records", agentSessions.size());
421+
422+
} catch (Exception e) {
423+
log.warn("Failed to fetch agent session data from {}: {}", agentProxyExternalUrl, e.getMessage());
424+
} catch (ZtatException e) {
425+
log.warn("Failed to fetch agent session data from {}: {}", agentProxyExternalUrl, e.getMessage());
426+
}
427+
428+
return agentSessions;
429+
}
430+
311431
}
312432

dataplane/src/main/java/io/sentrius/sso/core/services/SessionService.java

Lines changed: 9 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,8 @@
1010
import lombok.extern.slf4j.Slf4j;
1111
import org.springframework.beans.factory.annotation.Autowired;
1212
import org.springframework.beans.factory.annotation.Value;
13-
import org.springframework.core.ParameterizedTypeReference;
14-
import org.springframework.http.HttpMethod;
1513
import org.springframework.stereotype.Service;
1614
import org.springframework.transaction.annotation.Transactional;
17-
import org.springframework.web.client.RestTemplate;
1815

1916
import java.sql.Timestamp;
2017
import java.time.LocalDateTime;
@@ -36,11 +33,10 @@ public class SessionService {
3633
@Autowired
3734
private TerminalLogRepository terminalLogRepository;
3835

36+
3937
@Value("${agentproxy.externalUrl:}")
4038
private String agentProxyExternalUrl;
4139

42-
private final RestTemplate restTemplate = new RestTemplate();
43-
4440
private final Map<Long, SessionLog> activeSessions = new ConcurrentHashMap<>();
4541
private final Map<Long, TerminalLogs> activeTerminals = new ConcurrentHashMap<>();
4642

@@ -144,11 +140,8 @@ public List<Map<String, Object>> getSessionDurationData(String username) {
144140

145141
public Map<String, Integer> getGraphData(String username) {
146142
List<Map<String, Object>> sessionDurations = getSessionDurationData(username);
147-
148-
// Add agent session durations
149-
List<Map<String, Object>> agentSessionDurations = getAgentSessionDurations();
150-
sessionDurations.addAll(agentSessionDurations);
151143

144+
// Add agent session durations
152145
Map<String, Integer> graphData = new HashMap<>();
153146
graphData.put("0-5 min", 0);
154147
graphData.put("5-15 min", 0);
@@ -172,52 +165,13 @@ public Map<String, Integer> getGraphData(String username) {
172165
return graphData;
173166
}
174167

175-
/**
176-
* Fetch agent session duration data from agent proxy service
177-
* @return List of agent session duration data
178-
*/
179-
private List<Map<String, Object>> getAgentSessionDurations() {
180-
List<Map<String, Object>> agentSessions = new ArrayList<>();
181-
182-
if (agentProxyExternalUrl == null || agentProxyExternalUrl.trim().isEmpty()) {
183-
log.warn("Agent proxy URL not configured, skipping agent session data");
184-
return agentSessions;
185-
}
186-
187-
try {
188-
// Fetch completed agent sessions
189-
String completedUrl = agentProxyExternalUrl + "/api/v1/sessions/agent/durations";
190-
var completedResponse = restTemplate.exchange(
191-
completedUrl,
192-
HttpMethod.GET,
193-
null,
194-
new ParameterizedTypeReference<List<Map<String, Object>>>() {}
195-
);
196-
197-
if (completedResponse.getBody() != null) {
198-
agentSessions.addAll(completedResponse.getBody());
199-
}
200-
201-
// Fetch active agent sessions
202-
String activeUrl = agentProxyExternalUrl + "/api/v1/sessions/agent/active-durations";
203-
var activeResponse = restTemplate.exchange(
204-
activeUrl,
205-
HttpMethod.GET,
206-
null,
207-
new ParameterizedTypeReference<List<Map<String, Object>>>() {}
208-
);
209-
210-
if (activeResponse.getBody() != null) {
211-
agentSessions.addAll(activeResponse.getBody());
212-
}
213-
214-
log.info("Fetched {} agent session duration records", agentSessions.size());
215-
216-
} catch (Exception e) {
217-
log.warn("Failed to fetch agent session data from {}: {}", agentProxyExternalUrl, e.getMessage());
218-
}
219-
220-
return agentSessions;
168+
public List<Map<String, Object>> getGraphList(String username) {
169+
List<Map<String, Object>> sessionDurations = getSessionDurationData(username);
170+
171+
return sessionDurations;
221172
}
222173

174+
175+
176+
223177
}

0 commit comments

Comments
 (0)