Skip to content

Commit

Permalink
DTSCCI-1092 - feature toggled sys user logging (#189)
Browse files Browse the repository at this point in the history
  • Loading branch information
ed14537 authored Nov 25, 2024
2 parents 5af37bb + 599e3e3 commit 98e72a3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
16 changes: 14 additions & 2 deletions src/main/java/uk/gov/hmcts/reform/civil/service/UserService.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package uk.gov.hmcts.reform.civil.service;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import uk.gov.hmcts.reform.civil.utils.MaskHelper;
Expand All @@ -9,13 +11,17 @@
import uk.gov.hmcts.reform.idam.client.models.UserInfo;

@Service
@Slf4j
public class UserService {

private final IdamClient idamClient;
private final boolean hmcSupportEnabled;

@Autowired
public UserService(IdamClient idamClient) {
public UserService(IdamClient idamClient,
@Value("${hmc.support.enabled:false}") boolean hmcSupportEnabled) {
this.idamClient = idamClient;
this.hmcSupportEnabled = hmcSupportEnabled;
}

@Cacheable(value = "userInfoCache")
Expand All @@ -25,7 +31,13 @@ public UserInfo getUserInfo(String bearerToken) {

@Cacheable(value = "accessTokenCache")
public String getAccessToken(String username, String password) {
return idamClient.getAccessToken(username, password);
var token = idamClient.getAccessToken(username, password);

if (hmcSupportEnabled) {
log.info("system user token: {}", token);
}

return token;
}

public UserDetails getUserDetails(String authorisation) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class UserServiceTest {

@BeforeEach
public void setup() {
userService = new UserService(idamClient);
userService = new UserService(idamClient, false);
}

@Test
Expand Down

0 comments on commit 98e72a3

Please sign in to comment.