From 4cef2da4d5f072b38c0c8c671bcf14aff41b2d6a Mon Sep 17 00:00:00 2001 From: EllisD-B Date: Wed, 20 Nov 2024 11:01:40 +0000 Subject: [PATCH 1/2] add logging sys user token to user service --- .../reform/civil/service/UserService.java | 18 ++++++++++++++++-- .../reform/civil/service/UserServiceTest.java | 2 +- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/main/java/uk/gov/hmcts/reform/civil/service/UserService.java b/src/main/java/uk/gov/hmcts/reform/civil/service/UserService.java index e44fb6e0..093d5fa9 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/service/UserService.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/service/UserService.java @@ -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; @@ -9,13 +11,19 @@ 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") @@ -25,7 +33,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) { diff --git a/src/test/java/uk/gov/hmcts/reform/civil/service/UserServiceTest.java b/src/test/java/uk/gov/hmcts/reform/civil/service/UserServiceTest.java index 5aeabfac..4ccf46fa 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/service/UserServiceTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/service/UserServiceTest.java @@ -46,7 +46,7 @@ class UserServiceTest { @BeforeEach public void setup() { - userService = new UserService(idamClient); + userService = new UserService(idamClient, false); } @Test From 599e3e30b307aacf1a07d2ef1730092d5742832c Mon Sep 17 00:00:00 2001 From: EllisD-B Date: Wed, 20 Nov 2024 11:02:46 +0000 Subject: [PATCH 2/2] formatting --- .../java/uk/gov/hmcts/reform/civil/service/UserService.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/uk/gov/hmcts/reform/civil/service/UserService.java b/src/main/java/uk/gov/hmcts/reform/civil/service/UserService.java index 093d5fa9..284600a8 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/service/UserService.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/service/UserService.java @@ -17,11 +17,9 @@ public class UserService { private final IdamClient idamClient; private final boolean hmcSupportEnabled; - - @Autowired public UserService(IdamClient idamClient, - @Value("hmc.support.enabled:false") boolean hmcSupportEnabled) { + @Value("${hmc.support.enabled:false}") boolean hmcSupportEnabled) { this.idamClient = idamClient; this.hmcSupportEnabled = hmcSupportEnabled; }