Skip to content

Commit

Permalink
Merge pull request #1559 from alphagov/bau-initialise-single-instance…
Browse files Browse the repository at this point in the history
…s-of-data-sources

BAU: Only initialise one Redis and KMS connection in token handler.
  • Loading branch information
mrwilson authored Mar 21, 2022
2 parents 666c7d8 + 7af1920 commit 996afc0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import uk.gov.di.authentication.shared.entity.RefreshTokenStore;
import uk.gov.di.authentication.shared.entity.UserProfile;
import uk.gov.di.authentication.shared.helpers.ClientSubjectHelper;
import uk.gov.di.authentication.shared.helpers.ObjectMapperFactory;
import uk.gov.di.authentication.shared.services.AuthorisationCodeService;
import uk.gov.di.authentication.shared.services.ClientService;
import uk.gov.di.authentication.shared.services.ClientSessionService;
Expand Down Expand Up @@ -88,24 +89,26 @@ public TokenHandler(
}

public TokenHandler(ConfigurationService configurationService) {
var kms = new KmsConnectionService(configurationService);

this.configurationService = configurationService;
this.redisConnectionService = new RedisConnectionService(configurationService);

this.clientService =
new DynamoClientService(
configurationService.getAwsRegion(),
configurationService.getEnvironment(),
configurationService.getDynamoEndpointUri());
this.tokenService =
new TokenService(
configurationService,
new RedisConnectionService(configurationService),
new KmsConnectionService(configurationService));
new TokenService(configurationService, this.redisConnectionService, kms);
this.dynamoService = new DynamoService(configurationService);
this.authorisationCodeService = new AuthorisationCodeService(configurationService);
this.authorisationCodeService =
new AuthorisationCodeService(
configurationService,
redisConnectionService,
ObjectMapperFactory.getInstance());
this.clientSessionService = new ClientSessionService(configurationService);
this.tokenValidationService =
new TokenValidationService(
configurationService, new KmsConnectionService(configurationService));
this.redisConnectionService = new RedisConnectionService(configurationService);
this.tokenValidationService = new TokenValidationService(configurationService, kms);
}

public TokenHandler() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ public class AuthorisationCodeService {
private final long authorisationCodeExpiry;
private final ObjectMapper objectMapper;

public AuthorisationCodeService(
ConfigurationService configurationService,
RedisConnectionService redisConnectionService,
ObjectMapper objectMapper) {
this.redisConnectionService = redisConnectionService;
this.authorisationCodeExpiry = configurationService.getAuthCodeExpiry();
this.objectMapper = objectMapper;
}

public AuthorisationCodeService(ConfigurationService configurationService) {
this.redisConnectionService =
new RedisConnectionService(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
import io.lettuce.core.TransactionResult;
import io.lettuce.core.api.StatefulRedisConnection;
import io.lettuce.core.api.sync.RedisCommands;
import io.lettuce.core.support.ConnectionPoolSupport;
import org.apache.commons.pool2.impl.GenericObjectPool;
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;

import java.util.Optional;

import static io.lettuce.core.support.ConnectionPoolSupport.createGenericObjectPool;

public class RedisConnectionService implements AutoCloseable {

private final RedisClient client;
Expand All @@ -23,9 +24,7 @@ public RedisConnectionService(
password.ifPresent(s -> builder.withPassword(s.toCharArray()));
RedisURI redisURI = builder.build();
this.client = RedisClient.create(redisURI);
this.pool =
ConnectionPoolSupport.createGenericObjectPool(
client::connect, new GenericObjectPoolConfig());
this.pool = createGenericObjectPool(client::connect, new GenericObjectPoolConfig<>());
warmUp();
}

Expand Down

0 comments on commit 996afc0

Please sign in to comment.