-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DTSCCI-242 CMC Claim Store functional test 429 errors (#2976)
* DTSCCI-242: Fix @Cacheable self invocation * DTSCCI-242: Fix contract test config * Re-enable pact tests on PR * DTSCCI-242: Fix @Cacheable self invocation * DTSCCI-242: Create cacheable beans for user authorisations * DTSCCI-242: Create cacheable beans for user authorisations * DTSCCI-242 Caching fix and Jcenter fix * DTSCCI-242 Checkstyle fix * DTSCCI-242 Code clean up * DTSCCI-242: Remove @Cacheable annotation from interface * DTSCCI-242: Enable cacheable tokens in preview and aat * DTSCCI-242: update hmcts java to resolve build error * Revert "DTSCCI-242: update hmcts java to resolve build error" This reverts commit ad9574a. * DTSCCI-242: Correct property name --------- Co-authored-by: Nigel Dunne <12184413+nigeldunne@users.noreply.github.com> Co-authored-by: AbuSalam22 <136581242+AbuSalam22@users.noreply.github.com> Co-authored-by: Ruban <ruban72@hotmail.com>
- Loading branch information
1 parent
b746c09
commit e4c1e31
Showing
18 changed files
with
412 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
...ava/uk/gov/hmcts/cmc/claimstore/services/user/CacheableUserAuthorisationTokenService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package uk.gov.hmcts.cmc.claimstore.services.user; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.cache.annotation.Cacheable; | ||
import org.springframework.stereotype.Component; | ||
import uk.gov.hmcts.cmc.claimstore.models.idam.Oauth2; | ||
import uk.gov.hmcts.cmc.claimstore.models.idam.TokenExchangeResponse; | ||
import uk.gov.hmcts.cmc.claimstore.requests.idam.IdamApi; | ||
import uk.gov.hmcts.cmc.claimstore.stereotypes.LogExecutionTime; | ||
|
||
@Component | ||
@ConditionalOnProperty(prefix = "idam.user.token.cache", name = "enabled", havingValue = "true") | ||
public class CacheableUserAuthorisationTokenService implements IUserAuthorisationTokenService { | ||
public static final String GRANT_TYPE_PASSWORD = "password"; | ||
public static final String DEFAULT_SCOPE = "openid profile roles"; | ||
public static final String BEARER = "Bearer "; | ||
|
||
private final IdamApi idamApi; | ||
private final Oauth2 oauth2; | ||
Logger logger = LoggerFactory.getLogger(this.getClass()); | ||
|
||
public CacheableUserAuthorisationTokenService(IdamApi idamApi, Oauth2 oauth2) { | ||
this.idamApi = idamApi; | ||
this.oauth2 = oauth2; | ||
} | ||
|
||
@Override | ||
@LogExecutionTime | ||
@Cacheable(value = "userOIDTokenCache") | ||
public String getAuthorisationToken(String username, String password) { | ||
logger.info("IDAM /o/token invoked."); | ||
TokenExchangeResponse tokenExchangeResponse = idamApi.exchangeToken( | ||
oauth2.getClientId(), | ||
oauth2.getClientSecret(), | ||
oauth2.getRedirectUrl(), | ||
GRANT_TYPE_PASSWORD, | ||
username, | ||
password, | ||
DEFAULT_SCOPE); | ||
return BEARER + tokenExchangeResponse.getAccessToken(); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/uk/gov/hmcts/cmc/claimstore/services/user/CacheableUserInfoService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package uk.gov.hmcts.cmc.claimstore.services.user; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.cache.annotation.Cacheable; | ||
import org.springframework.stereotype.Component; | ||
import uk.gov.hmcts.cmc.claimstore.models.idam.UserInfo; | ||
import uk.gov.hmcts.cmc.claimstore.requests.idam.IdamApi; | ||
import uk.gov.hmcts.cmc.claimstore.stereotypes.LogExecutionTime; | ||
|
||
@Component | ||
@ConditionalOnProperty(prefix = "idam.user.token.cache", name = "enabled", havingValue = "true") | ||
public class CacheableUserInfoService implements IUserInfoService { | ||
|
||
private final IdamApi idamApi; | ||
Logger logger = LoggerFactory.getLogger(this.getClass()); | ||
|
||
public CacheableUserInfoService(IdamApi idamApi) { | ||
this.idamApi = idamApi; | ||
} | ||
|
||
@Override | ||
@LogExecutionTime | ||
@Cacheable(value = "userInfoCache") | ||
public UserInfo getUserInfo(String bearerToken) { | ||
logger.info("IDAM /o/userinfo invoked"); | ||
return idamApi.retrieveUserInfo(bearerToken); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
src/main/java/uk/gov/hmcts/cmc/claimstore/services/user/IUserAuthorisationTokenService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package uk.gov.hmcts.cmc.claimstore.services.user; | ||
|
||
public interface IUserAuthorisationTokenService { | ||
String getAuthorisationToken(String username, String password); | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/uk/gov/hmcts/cmc/claimstore/services/user/IUserInfoService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package uk.gov.hmcts.cmc.claimstore.services.user; | ||
|
||
import uk.gov.hmcts.cmc.claimstore.models.idam.UserInfo; | ||
|
||
public interface IUserInfoService { | ||
UserInfo getUserInfo(String bearerToken); | ||
} |
42 changes: 42 additions & 0 deletions
42
src/main/java/uk/gov/hmcts/cmc/claimstore/services/user/UserAuthorisationTokenService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package uk.gov.hmcts.cmc.claimstore.services.user; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.stereotype.Component; | ||
import uk.gov.hmcts.cmc.claimstore.models.idam.Oauth2; | ||
import uk.gov.hmcts.cmc.claimstore.models.idam.TokenExchangeResponse; | ||
import uk.gov.hmcts.cmc.claimstore.requests.idam.IdamApi; | ||
import uk.gov.hmcts.cmc.claimstore.stereotypes.LogExecutionTime; | ||
|
||
@Component | ||
@ConditionalOnProperty(prefix = "idam.user.token.cache", name = "enabled", havingValue = "false", matchIfMissing = true) | ||
public class UserAuthorisationTokenService implements IUserAuthorisationTokenService { | ||
public static final String GRANT_TYPE_PASSWORD = "password"; | ||
public static final String DEFAULT_SCOPE = "openid profile roles"; | ||
public static final String BEARER = "Bearer "; | ||
|
||
private final IdamApi idamApi; | ||
private final Oauth2 oauth2; | ||
Logger logger = LoggerFactory.getLogger(this.getClass()); | ||
|
||
public UserAuthorisationTokenService(IdamApi idamApi, Oauth2 oauth2) { | ||
this.idamApi = idamApi; | ||
this.oauth2 = oauth2; | ||
} | ||
|
||
@Override | ||
@LogExecutionTime | ||
public String getAuthorisationToken(String username, String password) { | ||
logger.info("IDAM /o/token invoked."); | ||
TokenExchangeResponse tokenExchangeResponse = idamApi.exchangeToken( | ||
oauth2.getClientId(), | ||
oauth2.getClientSecret(), | ||
oauth2.getRedirectUrl(), | ||
GRANT_TYPE_PASSWORD, | ||
username, | ||
password, | ||
DEFAULT_SCOPE); | ||
return BEARER + tokenExchangeResponse.getAccessToken(); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/uk/gov/hmcts/cmc/claimstore/services/user/UserInfoService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package uk.gov.hmcts.cmc.claimstore.services.user; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.stereotype.Component; | ||
import uk.gov.hmcts.cmc.claimstore.models.idam.UserInfo; | ||
import uk.gov.hmcts.cmc.claimstore.requests.idam.IdamApi; | ||
import uk.gov.hmcts.cmc.claimstore.stereotypes.LogExecutionTime; | ||
|
||
@Component | ||
@ConditionalOnProperty(prefix = "idam.user.token.cache", name = "enabled", havingValue = "false", matchIfMissing = true) | ||
public class UserInfoService implements IUserInfoService { | ||
|
||
private final IdamApi idamApi; | ||
Logger logger = LoggerFactory.getLogger(this.getClass()); | ||
|
||
public UserInfoService(IdamApi idamApi) { | ||
this.idamApi = idamApi; | ||
} | ||
|
||
@Override | ||
@LogExecutionTime | ||
public UserInfo getUserInfo(String bearerToken) { | ||
logger.info("IDAM /o/userinfo invoked"); | ||
return idamApi.retrieveUserInfo(bearerToken); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.