From 281ac39f2af06baed17449ad17b884676e041f7c Mon Sep 17 00:00:00 2001 From: Youn <yct@kereval.com> Date: Tue, 1 Sep 2020 14:52:44 +0200 Subject: [PATCH] IUAINFRA-47 add new method for generate token with the path properties as parameter --- .../application/DummyAuthzServerSoapui.java | 54 +++++++++++++++++-- 1 file changed, 49 insertions(+), 5 deletions(-) diff --git a/access-token-provider-api/src/main/java/net/ihe/gazelle/app/accesstokenproviderapi/application/DummyAuthzServerSoapui.java b/access-token-provider-api/src/main/java/net/ihe/gazelle/app/accesstokenproviderapi/application/DummyAuthzServerSoapui.java index bc7aca5..862e5f2 100644 --- a/access-token-provider-api/src/main/java/net/ihe/gazelle/app/accesstokenproviderapi/application/DummyAuthzServerSoapui.java +++ b/access-token-provider-api/src/main/java/net/ihe/gazelle/app/accesstokenproviderapi/application/DummyAuthzServerSoapui.java @@ -12,8 +12,6 @@ import java.time.Duration; public class DummyAuthzServerSoapui implements DummyAuthzServer { private static final String ALGORITHM = "HS256"; - private static final String SUBJECT = "aamrein"; - private static final String AUDIENCE = "audience"; private static final String ISSUER = "https://ehealthsuisse.ihe-europe.net/access-token-provider"; private static final TokenType TOKEN_TYPE = TokenType.JWT; private static final Duration DURATION = Duration.ofHours(1); @@ -22,15 +20,59 @@ public class DummyAuthzServerSoapui implements DummyAuthzServer { @Override public byte[] getAccessToken(String userId, String audienceId, String purposeOfUse, String resourceId) { //todo purposeOfUse and resourceId are not yet implemented - AccessTokenRequest accessTokenRequest = new AccessTokenRequest(ISSUER, userId, audienceId, DURATION, TOKEN_TYPE); - accessTokenRequest.setSignature(new SymmetricSignature(ALGORITHM, "secret")); TokenGenerator tokenGenerator = new TokenGenerator(); tokenGenerator.setAudienceSecretRetriever(new AudienceSecretRetrieverForSoapui()); + return getTokenGenerator(userId, audienceId, tokenGenerator); + } + + /** + * getAccessToken + * + * @param userId + * @param audienceId + * @param purposeOfUse + * @param resourceId + * @param propertiesFilePath + * @return + */ + public byte[] getAccessToken(String userId, String audienceId, String purposeOfUse, String resourceId, String propertiesFilePath) { + //todo purposeOfUse and resourceId are not yet implemented + + TokenGenerator tokenGenerator = new TokenGenerator(); + tokenGenerator.setAudienceSecretRetriever(new AudienceSecretRetrieverForSoapui(propertiesFilePath)); + + return getTokenGenerator(userId, audienceId, tokenGenerator); + } + + + /** + * getAccessTokenRequest + * + * @param userId + * @param audienceId + * @return + */ + public AccessTokenRequest getAccessTokenRequest(String userId, String audienceId){ + AccessTokenRequest accessTokenRequest = new AccessTokenRequest(ISSUER, userId, audienceId, DURATION, TOKEN_TYPE); + accessTokenRequest.setSignature(new SymmetricSignature(ALGORITHM, "secret")); + return accessTokenRequest; + } + + + /** + * getTokenGenerator + * + * @param userId + * @param audienceId + * @param tokenGenerator + * @return + */ + public byte[] getTokenGenerator(String userId, String audienceId, TokenGenerator tokenGenerator){ byte[] token = null; try { - token = tokenGenerator.generateAccessToken(accessTokenRequest).getToken(); + token = tokenGenerator.generateAccessToken(getAccessTokenRequest(userId, audienceId)).getToken(); } catch (EncodingException e) { e.printStackTrace(); } catch (TokenRequestException e) { @@ -39,4 +81,6 @@ public class DummyAuthzServerSoapui implements DummyAuthzServer { return token; } } + + } -- GitLab