Skip to content

Commit

Permalink
Renamed ReconfigurableAuthenticator to ConfigurableAuthenticator
Browse files Browse the repository at this point in the history
  • Loading branch information
robtimus committed Aug 8, 2023
1 parent 1c127a5 commit 6909e2d
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 38 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* ReconfigurableAuthenticator.java
* ConfigurableAuthenticator.java
* Copyright 2023 Rob Spoor
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -32,18 +32,18 @@
* @author Rob Spoor
* @since 3.8
*/
public class ReconfigurableAuthenticator implements Authenticator {
public class ConfigurableAuthenticator implements Authenticator {

private final AtomicReference<Authenticator> delegate;

/**
* Creates a new reconfigurable authenticator.
* Creates a new configurable authenticator.
*
* @param authorizationType The initial authorization type.
* @param apiKeyId The initial API key id.
* @param secretApiKey The initial secret API key.
*/
public ReconfigurableAuthenticator(AuthorizationType authorizationType, String apiKeyId, String secretApiKey) {
public ConfigurableAuthenticator(AuthorizationType authorizationType, String apiKeyId, String secretApiKey) {
delegate = new AtomicReference<>(new DefaultAuthenticator(authorizationType, apiKeyId, secretApiKey));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
import org.springframework.boot.actuate.endpoint.annotation.WriteOperation;
import org.springframework.lang.Nullable;
import com.github.robtimus.connect.sdk.java.springboot.ReconfigurableAuthenticator;
import com.github.robtimus.connect.sdk.java.springboot.ConfigurableAuthenticator;
import com.ingenico.connect.gateway.sdk.java.defaultimpl.AuthorizationType;

/**
Expand All @@ -33,9 +33,9 @@
@SuppressWarnings("javadoc")
public class ApiKeyEndpoint {

private final ReconfigurableAuthenticator authenticator;
private final ConfigurableAuthenticator authenticator;

public ApiKeyEndpoint(ReconfigurableAuthenticator authenticator) {
public ApiKeyEndpoint(ConfigurableAuthenticator authenticator) {
this.authenticator = authenticator;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.github.robtimus.connect.sdk.java.springboot.ReconfigurableAuthenticator;
import com.github.robtimus.connect.sdk.java.springboot.ConfigurableAuthenticator;
import com.github.robtimus.connect.sdk.java.springboot.actuator.ApiKeyEndpoint;
import com.ingenico.connect.gateway.sdk.java.Authenticator;
import com.ingenico.connect.gateway.sdk.java.defaultimpl.AuthorizationType;
Expand All @@ -54,17 +54,17 @@ public ConnectSdkAuthenticatorAutoConfiguration(ConnectSdkProperties properties)
}

@Bean
public ReconfigurableAuthenticator connectSdkAuthenticator() {
public ConfigurableAuthenticator connectSdkAuthenticator() {
AuthorizationType authorizationType = properties.getAuthorizationType();
String apiKeyId = properties.getApiKeyId();
String secretApiKey = properties.getSecretApiKey();
return new ReconfigurableAuthenticator(authorizationType, apiKeyId, secretApiKey);
return new ConfigurableAuthenticator(authorizationType, apiKeyId, secretApiKey);
}

@Bean
@ConditionalOnClass(Endpoint.class)
@ConditionalOnAvailableEndpoint(endpoint = ApiKeyEndpoint.class)
public ApiKeyEndpoint connectSdkApiKeyEndpoint(ReconfigurableAuthenticator authenticator) {
public ApiKeyEndpoint connectSdkApiKeyEndpoint(ConfigurableAuthenticator authenticator) {
return new ApiKeyEndpoint(authenticator);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* ReconfigurableAuthenticatorTest.java
* ConfigurableAuthenticatorTest.java
* Copyright 2023 Rob Spoor
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -24,26 +24,26 @@
import com.ingenico.connect.gateway.sdk.java.defaultimpl.AuthorizationType;

@SuppressWarnings("nls")
class ReconfigurableAuthenticatorTest {
class ConfigurableAuthenticatorTest {

@Test
void testSignatureWithInitialApiKey() {
String apiKeyId = UUID.randomUUID().toString();
String secretApiKey = UUID.randomUUID().toString();

Authenticator reconfigurableAuthenticator = new ReconfigurableAuthenticator(AuthorizationType.V1HMAC, apiKeyId, secretApiKey);
Authenticator authenticator = new ConfigurableAuthenticator(AuthorizationType.V1HMAC, apiKeyId, secretApiKey);

assertSignatureCalculation(reconfigurableAuthenticator, apiKeyId, secretApiKey);
assertSignatureCalculation(authenticator, apiKeyId, secretApiKey);
}

@Test
void testSignatureWithNewApiKey() {
String apiKeyId = UUID.randomUUID().toString();
String secretApiKey = UUID.randomUUID().toString();

ReconfigurableAuthenticator reconfigurableAuthenticator = new ReconfigurableAuthenticator(AuthorizationType.V1HMAC, "x", "x");
reconfigurableAuthenticator.setApiKey(AuthorizationType.V1HMAC, apiKeyId, secretApiKey);
ConfigurableAuthenticator authenticator = new ConfigurableAuthenticator(AuthorizationType.V1HMAC, "x", "x");
authenticator.setApiKey(AuthorizationType.V1HMAC, apiKeyId, secretApiKey);

assertSignatureCalculation(reconfigurableAuthenticator, apiKeyId, secretApiKey);
assertSignatureCalculation(authenticator, apiKeyId, secretApiKey);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import java.util.UUID;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import com.github.robtimus.connect.sdk.java.springboot.ReconfigurableAuthenticator;
import com.github.robtimus.connect.sdk.java.springboot.ConfigurableAuthenticator;
import com.ingenico.connect.gateway.sdk.java.defaultimpl.AuthorizationType;

@SuppressWarnings("nls")
Expand All @@ -35,26 +35,26 @@ void testWithoutAuthorizationType() {
String apiKeyId = UUID.randomUUID().toString();
String secretApiKey = UUID.randomUUID().toString();

ReconfigurableAuthenticator reconfigurableAuthenticator = new ReconfigurableAuthenticator(AuthorizationType.V1HMAC, "x", "x");
ConfigurableAuthenticator authenticator = new ConfigurableAuthenticator(AuthorizationType.V1HMAC, "x", "x");

ApiKeyEndpoint endpoint = new ApiKeyEndpoint(reconfigurableAuthenticator);
ApiKeyEndpoint endpoint = new ApiKeyEndpoint(authenticator);
endpoint.setApiKey(apiKeyId, secretApiKey, null);
reconfigurableAuthenticator.setApiKey(AuthorizationType.V1HMAC, apiKeyId, secretApiKey);
authenticator.setApiKey(AuthorizationType.V1HMAC, apiKeyId, secretApiKey);

assertSignatureCalculation(reconfigurableAuthenticator, apiKeyId, secretApiKey);
assertSignatureCalculation(authenticator, apiKeyId, secretApiKey);
}

@Test
void testWithAuthorizationType() {
String apiKeyId = UUID.randomUUID().toString();
String secretApiKey = UUID.randomUUID().toString();

ReconfigurableAuthenticator reconfigurableAuthenticator = new ReconfigurableAuthenticator(AuthorizationType.V1HMAC, "x", "x");
ConfigurableAuthenticator authenticator = new ConfigurableAuthenticator(AuthorizationType.V1HMAC, "x", "x");

ApiKeyEndpoint endpoint = new ApiKeyEndpoint(reconfigurableAuthenticator);
ApiKeyEndpoint endpoint = new ApiKeyEndpoint(authenticator);
endpoint.setApiKey(apiKeyId, secretApiKey, AuthorizationType.V1HMAC);

assertSignatureCalculation(reconfigurableAuthenticator, apiKeyId, secretApiKey);
assertSignatureCalculation(authenticator, apiKeyId, secretApiKey);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.github.robtimus.connect.sdk.java.springboot.ReconfigurableAuthenticator;
import com.github.robtimus.connect.sdk.java.springboot.ConfigurableAuthenticator;
import com.github.robtimus.connect.sdk.java.springboot.actuator.ApiKeyEndpoint;
import com.ingenico.connect.gateway.sdk.java.Authenticator;

Expand All @@ -49,7 +49,7 @@ void testNoAutoConfigurationWithExistingBean() {
assertThat(context).doesNotHaveBean("connectSdkAuthenticator");
assertThat(context).hasSingleBean(Authenticator.class);
assertThat(context).getBean(Authenticator.class).isSameAs(context.getBean(ExistingBeanProvider.class).authenticator());
assertThat(context).doesNotHaveBean(ReconfigurableAuthenticator.class);
assertThat(context).doesNotHaveBean(ConfigurableAuthenticator.class);
assertThat(context).doesNotHaveBean(ApiKeyEndpoint.class);
});
}
Expand All @@ -63,7 +63,7 @@ void testNoAutoConfigurationWithMissingProperties() {
"management.endpoints.jmx.exposure.include=connectSdkApiKey")
.run(context -> {
assertThat(context).doesNotHaveBean(Authenticator.class);
assertThat(context).doesNotHaveBean(ReconfigurableAuthenticator.class);
assertThat(context).doesNotHaveBean(ConfigurableAuthenticator.class);
assertThat(context).doesNotHaveBean(ApiKeyEndpoint.class);
});
contextRunner
Expand All @@ -73,7 +73,7 @@ void testNoAutoConfigurationWithMissingProperties() {
"management.endpoints.jmx.exposure.include=connectSdkApiKey")
.run(context -> {
assertThat(context).doesNotHaveBean(Authenticator.class);
assertThat(context).doesNotHaveBean(ReconfigurableAuthenticator.class);
assertThat(context).doesNotHaveBean(ConfigurableAuthenticator.class);
assertThat(context).doesNotHaveBean(ApiKeyEndpoint.class);
});
}
Expand All @@ -85,8 +85,8 @@ void testAutoConfigurationWithoutEndpoint() {
.run(context -> {
assertThat(context).hasBean("connectSdkAuthenticator");
assertThat(context).hasSingleBean(Authenticator.class);
assertThat(context).getBean(Authenticator.class).isExactlyInstanceOf(ReconfigurableAuthenticator.class);
assertThat(context).hasSingleBean(ReconfigurableAuthenticator.class);
assertThat(context).getBean(Authenticator.class).isExactlyInstanceOf(ConfigurableAuthenticator.class);
assertThat(context).hasSingleBean(ConfigurableAuthenticator.class);
assertThat(context).doesNotHaveBean(ApiKeyEndpoint.class);
});
}
Expand All @@ -99,8 +99,8 @@ void testAutoConfigurationWithEnabledEndpoint() {
.run(context -> {
assertThat(context).hasBean("connectSdkAuthenticator");
assertThat(context).hasSingleBean(Authenticator.class);
assertThat(context).getBean(Authenticator.class).isExactlyInstanceOf(ReconfigurableAuthenticator.class);
assertThat(context).hasSingleBean(ReconfigurableAuthenticator.class);
assertThat(context).getBean(Authenticator.class).isExactlyInstanceOf(ConfigurableAuthenticator.class);
assertThat(context).hasSingleBean(ConfigurableAuthenticator.class);
assertThat(context).doesNotHaveBean(ApiKeyEndpoint.class);
});
}
Expand All @@ -114,8 +114,8 @@ void testAutoConfigurationWithAvailableEndpoint() {
.run(context -> {
assertThat(context).hasBean("connectSdkAuthenticator");
assertThat(context).hasSingleBean(Authenticator.class);
assertThat(context).getBean(Authenticator.class).isExactlyInstanceOf(ReconfigurableAuthenticator.class);
assertThat(context).hasSingleBean(ReconfigurableAuthenticator.class);
assertThat(context).getBean(Authenticator.class).isExactlyInstanceOf(ConfigurableAuthenticator.class);
assertThat(context).hasSingleBean(ConfigurableAuthenticator.class);
assertThat(context).hasSingleBean(ApiKeyEndpoint.class);
});
}
Expand All @@ -131,8 +131,8 @@ void testNoEndpointWithMissingClass() throws IOException {
.run(context -> {
assertThat(context).hasBean("connectSdkAuthenticator");
assertThat(context).hasSingleBean(Authenticator.class);
assertThat(context).getBean(Authenticator.class).isExactlyInstanceOf(ReconfigurableAuthenticator.class);
assertThat(context).hasSingleBean(ReconfigurableAuthenticator.class);
assertThat(context).getBean(Authenticator.class).isExactlyInstanceOf(ConfigurableAuthenticator.class);
assertThat(context).hasSingleBean(ConfigurableAuthenticator.class);
assertThat(context).doesNotHaveBean(ApiKeyEndpoint.class);
});
}
Expand Down

0 comments on commit 6909e2d

Please sign in to comment.