Skip to content
Permalink
Browse files
Adding logging.
  • Loading branch information
mifosio-04-04-2018 committed May 31, 2017
1 parent 8e02dee commit b2ee0d327ac184af67f550658c6b4228f00cc4a4
Showing 2 changed files with 16 additions and 2 deletions.
@@ -24,9 +24,12 @@
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 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 String getAccessToken(final String user, final String tenant, final @Null
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();

@@ -27,6 +27,7 @@
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 void testHappyCase() {
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());

0 comments on commit b2ee0d3

Please sign in to comment.