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] 08/11: Adding logging.
Date Mon, 22 Jan 2018 15:20:24 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 b2ee0d327ac184af67f550658c6b4228f00cc4a4
Author: myrle-krantz <mkrantz@mifos.org>
AuthorDate: Wed May 31 17:12:43 2017 +0200

    Adding logging.
---
 .../service/ApplicationAccessTokenService.java               | 12 +++++++++++-
 .../service/ApplicationAccessTokenServiceTest.java           |  6 +++++-
 2 files changed, 16 insertions(+), 2 deletions(-)

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 c21752b..ca6e274 100644
--- a/library/src/main/java/io/mifos/permittedfeignclient/service/ApplicationAccessTokenService.java
+++ b/library/src/main/java/io/mifos/permittedfeignclient/service/ApplicationAccessTokenService.java
@@ -24,9 +24,12 @@ import io.mifos.core.lang.AutoTenantContext;
 import io.mifos.core.lang.security.RsaKeyPairFactory;
 import io.mifos.identity.api.v1.client.IdentityManager;
 import io.mifos.identity.api.v1.domain.Authentication;
+import io.mifos.permittedfeignclient.LibraryConstants;
 import net.jodah.expiringmap.ExpirationPolicy;
 import net.jodah.expiringmap.ExpiringMap;
+import org.slf4j.Logger;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
 import org.springframework.stereotype.Component;
 
 import javax.annotation.Nonnull;
@@ -46,6 +49,7 @@ public class ApplicationAccessTokenService {
   private final TenantSignatureRepository tenantSignatureRepository;
   private final IdentityManager identityManager;
   private final TenantRefreshTokenSerializer tenantRefreshTokenSerializer;
+  private final Logger logger;
 
   private final Map<TokenCacheKey, TokenSerializationResult> refreshTokenCache;
   private final Map<TokenCacheKey, Authentication> accessTokenCache;
@@ -55,12 +59,15 @@ public class ApplicationAccessTokenService {
           final @Nonnull ApplicationName applicationName,
           final @Nonnull TenantSignatureRepository tenantSignatureRepository,
           final @Nonnull IdentityManager identityManager,
-          final @Nonnull TenantRefreshTokenSerializer tenantRefreshTokenSerializer) {
+          final @Nonnull TenantRefreshTokenSerializer tenantRefreshTokenSerializer,
+          @Qualifier(LibraryConstants.LOGGER_NAME) final @Nonnull Logger logger
+  ) {
 
     this.applicationName = applicationName.toString();
     this.tenantSignatureRepository = tenantSignatureRepository;
     this.identityManager = identityManager;
     this.tenantRefreshTokenSerializer = tenantRefreshTokenSerializer;
+    this.logger = logger;
 
     this.refreshTokenCache = ExpiringMap.builder()
             .maxSize(300)
@@ -90,12 +97,15 @@ 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);
     }
   }
 
   private TokenSerializationResult createRefreshToken(final TokenCacheKey tokenCacheKey)
{
     try (final AutoTenantContext ignored = new AutoTenantContext(tokenCacheKey.getTenant()))
{
+      logger.debug("Creating refresh token for {}", tokenCacheKey);
+
       final Optional<RsaKeyPairFactory.KeyPairHolder> optionalSigningKeyPair
               = tenantSignatureRepository.getLatestApplicationSigningKeyPair();
 
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 29017b6..6b366d3 100644
--- a/library/src/test/java/io/mifos/permittedfeignclient/service/ApplicationAccessTokenServiceTest.java
+++ b/library/src/test/java/io/mifos/permittedfeignclient/service/ApplicationAccessTokenServiceTest.java
@@ -27,6 +27,7 @@ import io.mifos.identity.api.v1.domain.Authentication;
 import org.junit.Assert;
 import org.junit.Test;
 import org.mockito.Mockito;
+import org.slf4j.Logger;
 
 import java.time.LocalDateTime;
 import java.util.Optional;
@@ -57,11 +58,14 @@ public class ApplicationAccessTokenServiceTest {
     Mockito.when(tenantRefreshTokenSerializerMock.build(Mockito.anyObject()))
             .thenReturn(new TokenSerializationResult(BEARER_TOKEN_MOCK, LocalDateTime.now()));
 
+    final Logger loggerMock = Mockito.mock(Logger.class);
+
     final ApplicationAccessTokenService testSubject = new ApplicationAccessTokenService(
             applicationNameMock,
             tenantSignatureRepositoryMock,
             identityManagerMock,
-            tenantRefreshTokenSerializerMock);
+            tenantRefreshTokenSerializerMock,
+            loggerMock);
 
     try (final AutoTenantContext ignored1 = new AutoTenantContext(TENANT_NAME)) {
       final String accessTokenWithoutCallEndpointSet = testSubject.getAccessToken(USER_NAME,
TenantContextHolder.checkedGetIdentifier());

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

Mime
View raw message