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] 10/11: Improved logging and error handling. Fixed path to identity.
Date Mon, 22 Jan 2018 15:20:26 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 1f9140be84723b4a208d27045493784305cb8bca
Author: myrle-krantz <mkrantz@mifos.org>
AuthorDate: Wed Jun 7 12:08:12 2017 +0200

    Improved logging and error handling.  Fixed path to identity.
---
 .../config/PermittedFeignClientConfiguration.java        |  2 +-
 .../security/ApplicationTokenedTargetInterceptor.java    |  5 ++++-
 .../service/ApplicationAccessTokenService.java           | 16 ++++++++++++++--
 3 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/library/src/main/java/io/mifos/permittedfeignclient/config/PermittedFeignClientConfiguration.java
b/library/src/main/java/io/mifos/permittedfeignclient/config/PermittedFeignClientConfiguration.java
index 41ff160..c004aae 100644
--- a/library/src/main/java/io/mifos/permittedfeignclient/config/PermittedFeignClientConfiguration.java
+++ b/library/src/main/java/io/mifos/permittedfeignclient/config/PermittedFeignClientConfiguration.java
@@ -57,6 +57,6 @@ public class PermittedFeignClientConfiguration {
             .requestInterceptor(new TokenedTargetInterceptor())
             .decoder(new GsonDecoder())
             .encoder(new GsonEncoder())
-            .target(IdentityManager.class, "http://identity-v1");
+            .target(IdentityManager.class, "http://identity-v1/identity/v1");
   }
 }
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 60a58ad..ecce505 100644
--- a/library/src/main/java/io/mifos/permittedfeignclient/security/ApplicationTokenedTargetInterceptor.java
+++ b/library/src/main/java/io/mifos/permittedfeignclient/security/ApplicationTokenedTargetInterceptor.java
@@ -48,8 +48,11 @@ public class ApplicationTokenedTargetInterceptor implements RequestInterceptor
{
   @Override
   public void apply(final RequestTemplate template) {
     UserContextHolder.getUserContext().ifPresent(userContext -> {
+      final String accessToken = applicationAccessTokenService.getAccessToken(userContext.getUser(),
+              TenantContextHolder.checkedGetIdentifier(), endpointSetIdentifier);
+
       template.header(ApiConstants.USER_HEADER, userContext.getUser());
-      template.header(ApiConstants.AUTHORIZATION_HEADER, applicationAccessTokenService.getAccessToken(userContext.getUser(),
TenantContextHolder.checkedGetIdentifier(), endpointSetIdentifier));
+      template.header(ApiConstants.AUTHORIZATION_HEADER, accessToken);
     });
   }
 }
\ 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 ca6e274..1cb4554 100644
--- a/library/src/main/java/io/mifos/permittedfeignclient/service/ApplicationAccessTokenService.java
+++ b/library/src/main/java/io/mifos/permittedfeignclient/service/ApplicationAccessTokenService.java
@@ -19,6 +19,8 @@ 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.context.AutoGuest;
+import io.mifos.core.api.util.NotFoundException;
 import io.mifos.core.lang.ApplicationName;
 import io.mifos.core.lang.AutoTenantContext;
 import io.mifos.core.lang.security.RsaKeyPairFactory;
@@ -97,8 +99,14 @@ public class ApplicationAccessTokenService {
   private Authentication createAccessToken(final TokenCacheKey tokenCacheKey) {
     final String refreshToken = refreshTokenCache.get(tokenCacheKey).getToken();
     try (final AutoTenantContext ignored = new AutoTenantContext(tokenCacheKey.getTenant()))
{
-      logger.debug("Getting access token for {}", tokenCacheKey);
-      return identityManager.refresh(refreshToken);
+      try (final AutoGuest ignored2 = new AutoGuest()) {
+        logger.debug("Getting access token for {}", tokenCacheKey);
+        return identityManager.refresh(refreshToken);
+      }
+      catch (final Exception e) {
+        logger.error("Couldn't get access token from identity for {}.", tokenCacheKey, e);
+        throw new NotFoundException("Couldn't get access token");
+      }
     }
   }
 
@@ -122,5 +130,9 @@ public class ApplicationAccessTokenService {
 
       return tenantRefreshTokenSerializer.build(specification);
     }
+    catch (final Exception e) {
+      logger.error("Couldn't create refresh token for {}.", tokenCacheKey, e);
+      throw new NotFoundException("Couldn't create refresh token.");
+    }
   }
 }

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

Mime
View raw message