fineract-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From my...@apache.org
Subject [fineract-cn-permitted-feign-client] 02/11: Making getAccessToken more useful for rhythm by making user an explicit parameter rather than a thread local.
Date Mon, 22 Jan 2018 15:20:18 GMT
This is an automated email from the ASF dual-hosted git repository.

myrle pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/fineract-cn-permitted-feign-client.git

commit dbfd9257d6a7b4691cb0f7f128f0dce1ca2ab820
Author: myrle-krantz <mkrantz@mifos.org>
AuthorDate: Fri May 19 13:36:47 2017 +0200

    Making getAccessToken more useful for rhythm by making user an explicit parameter rather
than a thread local.
---
 .../security/ApplicationTokenedTargetInterceptor.java        |  9 ++++-----
 .../service/ApplicationAccessTokenService.java               |  5 ++---
 .../service/ApplicationAccessTokenServiceTest.java           | 12 ++++--------
 3 files changed, 10 insertions(+), 16 deletions(-)

diff --git a/library/src/main/java/io/mifos/permittedfeignclient/security/ApplicationTokenedTargetInterceptor.java
b/library/src/main/java/io/mifos/permittedfeignclient/security/ApplicationTokenedTargetInterceptor.java
index 2f3c7e7..4141d70 100644
--- a/library/src/main/java/io/mifos/permittedfeignclient/security/ApplicationTokenedTargetInterceptor.java
+++ b/library/src/main/java/io/mifos/permittedfeignclient/security/ApplicationTokenedTargetInterceptor.java
@@ -18,7 +18,6 @@ package io.mifos.permittedfeignclient.security;
 import feign.RequestInterceptor;
 import feign.RequestTemplate;
 import io.mifos.core.api.util.ApiConstants;
-import io.mifos.core.api.util.UserContext;
 import io.mifos.core.api.util.UserContextHolder;
 import io.mifos.permittedfeignclient.annotation.EndpointSet;
 import io.mifos.permittedfeignclient.service.ApplicationAccessTokenService;
@@ -47,9 +46,9 @@ public class ApplicationTokenedTargetInterceptor implements RequestInterceptor
{
 
   @Override
   public void apply(final RequestTemplate template) {
-    template.header(ApiConstants.AUTHORIZATION_HEADER, applicationAccessTokenService.getAccessToken(endpointSetIdentifier));
-    UserContextHolder.getUserContext()
-            .map(UserContext::getUser)
-            .ifPresent(user -> template.header(ApiConstants.USER_HEADER, user));
+    UserContextHolder.getUserContext().ifPresent(userContext -> {
+      template.header(ApiConstants.USER_HEADER, userContext.getUser());
+      template.header(ApiConstants.AUTHORIZATION_HEADER, applicationAccessTokenService.getAccessToken(userContext.getUser(),
endpointSetIdentifier));
+    });
   }
 }
\ No newline at end of file
diff --git a/library/src/main/java/io/mifos/permittedfeignclient/service/ApplicationAccessTokenService.java
b/library/src/main/java/io/mifos/permittedfeignclient/service/ApplicationAccessTokenService.java
index b97b4dd..082f5ec 100644
--- a/library/src/main/java/io/mifos/permittedfeignclient/service/ApplicationAccessTokenService.java
+++ b/library/src/main/java/io/mifos/permittedfeignclient/service/ApplicationAccessTokenService.java
@@ -19,7 +19,6 @@ import io.mifos.anubis.config.TenantSignatureRepository;
 import io.mifos.anubis.security.AmitAuthenticationException;
 import io.mifos.anubis.token.TenantRefreshTokenSerializer;
 import io.mifos.anubis.token.TokenSerializationResult;
-import io.mifos.core.api.util.UserContextHolder;
 import io.mifos.core.lang.ApplicationName;
 import io.mifos.core.lang.TenantContextHolder;
 import io.mifos.core.lang.security.RsaKeyPairFactory;
@@ -112,9 +111,9 @@ public class ApplicationAccessTokenService {
             .build();
   }
 
-  public String getAccessToken(final String endpointSetIdentifier) {
+  public String getAccessToken(final String user, final String endpointSetIdentifier) {
     final TokenCacheKey tokenCacheKey
-            = new TokenCacheKey(UserContextHolder.checkedGetUser(), TenantContextHolder.checkedGetIdentifier(),
endpointSetIdentifier);
+            = new TokenCacheKey(user, TenantContextHolder.checkedGetIdentifier(), endpointSetIdentifier);
     final Authentication authentication = accessTokenCache.get(tokenCacheKey);
     return authentication.getAccessToken();
   }
diff --git a/library/src/test/java/io/mifos/permittedfeignclient/service/ApplicationAccessTokenServiceTest.java
b/library/src/test/java/io/mifos/permittedfeignclient/service/ApplicationAccessTokenServiceTest.java
index c940668..51d3f63 100644
--- a/library/src/test/java/io/mifos/permittedfeignclient/service/ApplicationAccessTokenServiceTest.java
+++ b/library/src/test/java/io/mifos/permittedfeignclient/service/ApplicationAccessTokenServiceTest.java
@@ -3,7 +3,6 @@ package io.mifos.permittedfeignclient.service;
 import io.mifos.anubis.config.TenantSignatureRepository;
 import io.mifos.anubis.token.TenantRefreshTokenSerializer;
 import io.mifos.anubis.token.TokenSerializationResult;
-import io.mifos.core.api.context.AutoUserContext;
 import io.mifos.core.lang.ApplicationName;
 import io.mifos.core.lang.AutoTenantContext;
 import io.mifos.core.lang.security.RsaKeyPairFactory;
@@ -24,7 +23,6 @@ public class ApplicationAccessTokenServiceTest {
   private static final String BEARER_TOKEN_MOCK = "bearer token mock";
   private static final String USER_NAME = "user";
   private static final String TENANT_NAME = "tenant";
-  private static final String BEARER_INCOMING_ACCESS_TOKEN_MOCK = "bearer incoming access
token mock";
 
   @Test
   public void testHappyCase() {
@@ -50,13 +48,11 @@ public class ApplicationAccessTokenServiceTest {
             tenantRefreshTokenSerializerMock);
 
     try (final AutoTenantContext ignored1 = new AutoTenantContext(TENANT_NAME)) {
-      try (final AutoUserContext ignored2 = new AutoUserContext(USER_NAME, BEARER_INCOMING_ACCESS_TOKEN_MOCK))
{
-        final String accessToken = testSubject.getAccessToken("blah");
-        Assert.assertEquals(BEARER_TOKEN_MOCK, accessToken);
+      final String accessToken = testSubject.getAccessToken(USER_NAME, "blah");
+      Assert.assertEquals(BEARER_TOKEN_MOCK, accessToken);
 
-        final String accessTokenAgain = testSubject.getAccessToken("blah");
-        Assert.assertEquals(BEARER_TOKEN_MOCK, accessTokenAgain);
-      }
+      final String accessTokenAgain = testSubject.getAccessToken(USER_NAME, "blah");
+      Assert.assertEquals(BEARER_TOKEN_MOCK, accessTokenAgain);
     }
   }
 }
\ No newline at end of file

-- 
To stop receiving notification emails like this one, please contact
myrle@apache.org.

Mime
View raw message