From ce7b474717f5f86e5286a24684cf4ebfdb183eac Mon Sep 17 00:00:00 2001 From: petruki <31597636+petruki@users.noreply.github.com> Date: Sun, 24 May 2026 16:41:14 -0700 Subject: [PATCH 1/2] chore: replaced switcher.autorefreshtoken with switcher.auth.autorefresh --- ...eshTokenTest.java => SwitcherRemoteAuthAutoRefreshTest.java} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename src/test/java/com/switcherapi/client/{SwitcherRemoteAutoRefreshTokenTest.java => SwitcherRemoteAuthAutoRefreshTest.java} (98%) diff --git a/src/test/java/com/switcherapi/client/SwitcherRemoteAutoRefreshTokenTest.java b/src/test/java/com/switcherapi/client/SwitcherRemoteAuthAutoRefreshTest.java similarity index 98% rename from src/test/java/com/switcherapi/client/SwitcherRemoteAutoRefreshTokenTest.java rename to src/test/java/com/switcherapi/client/SwitcherRemoteAuthAutoRefreshTest.java index 948a954..5c3afe3 100644 --- a/src/test/java/com/switcherapi/client/SwitcherRemoteAutoRefreshTokenTest.java +++ b/src/test/java/com/switcherapi/client/SwitcherRemoteAuthAutoRefreshTest.java @@ -91,7 +91,7 @@ private void givenAutoRefreshToken(boolean enabled) { .domain("domain") .apiKey("apiKey") .component("component") - .autoRefreshToken(enabled)); + .authAutoRefresh(enabled)); SwitchersBase.initializeClient(); } From 16651e55a76f54d2bb8b25b228e44d396cac76b1 Mon Sep 17 00:00:00 2001 From: petruki <31597636+petruki@users.noreply.github.com> Date: Sun, 24 May 2026 16:41:43 -0700 Subject: [PATCH 2/2] chore: replaced switcher.autorefreshtoken with switcher.auth.autorefresh --- README.md | 2 +- .../switcherapi/client/ContextBuilder.java | 8 +++++-- .../switcherapi/client/SwitcherConfig.java | 24 +++++++++++++++---- .../client/SwitcherContextBase.java | 2 +- .../client/SwitcherPropertiesImpl.java | 4 ++-- .../switcherapi/client/model/ContextKey.java | 2 +- .../service/remote/ClientRemoteService.java | 2 +- .../client/SwitcherConfigTest.java | 4 ++++ .../SwitcherRemoteAuthAutoRefreshTest.java | 10 ++++---- .../com/switcherapi/playground/Features.java | 2 +- 10 files changed, 42 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index a03295c..7b6192d 100644 --- a/README.md +++ b/README.md @@ -145,7 +145,7 @@ switcher.poolsize=2 | `switcher.environment` | ❌ | default | Environment name (dev, staging, default) | | `switcher.local` | ❌ | false | Enable local-only mode | | `switcher.check` | ❌ | false | Validate switcher keys on startup | -| `switcher.autorefreshtoken` | ❌ | false | Automatically refresh API token before expiration | +| `switcher.auth.autorefresh` | ❌ | false | Automatically refresh API token before expiration | | `switcher.relay.restrict` | ❌ | true | Defines if client will trigger local snapshot relay verification | | `switcher.snapshot.location` | ❌ | - | Directory for snapshot files | | `switcher.snapshot.auto` | ❌ | false | Auto-load snapshots on startup | diff --git a/src/main/java/com/switcherapi/client/ContextBuilder.java b/src/main/java/com/switcherapi/client/ContextBuilder.java index 6f49290..f45d790 100644 --- a/src/main/java/com/switcherapi/client/ContextBuilder.java +++ b/src/main/java/com/switcherapi/client/ContextBuilder.java @@ -235,8 +235,12 @@ public ContextBuilder poolConnectionSize(Integer poolSize) { return this; } - public ContextBuilder autoRefreshToken(boolean autoRefreshToken) { - switcherProperties.setValue(ContextKey.AUTO_REFRESH_TOKEN, autoRefreshToken); + /** + * @param authAutoRefresh true/false When true, it will enable automatic refresh of authentication token + * @return ContextBuilder + */ + public ContextBuilder authAutoRefresh(boolean authAutoRefresh) { + switcherProperties.setValue(ContextKey.AUTH_AUTO_REFRESH, authAutoRefresh); return this; } } diff --git a/src/main/java/com/switcherapi/client/SwitcherConfig.java b/src/main/java/com/switcherapi/client/SwitcherConfig.java index 98b7b3c..ccd6176 100644 --- a/src/main/java/com/switcherapi/client/SwitcherConfig.java +++ b/src/main/java/com/switcherapi/client/SwitcherConfig.java @@ -12,15 +12,16 @@ abstract class SwitcherConfig { protected boolean local; protected boolean check; - protected boolean autoRefreshToken; protected String silent; protected Integer timeout; protected Integer poolSize; + protected AuthConfig auth; protected RelayConfig relay; protected SnapshotConfig snapshot; protected TruststoreConfig truststore; SwitcherConfig() { + this.auth = new AuthConfig(); this.relay = new RelayConfig(); this.snapshot = new SnapshotConfig(); this.truststore = new TruststoreConfig(); @@ -39,11 +40,14 @@ protected void updateSwitcherConfig(SwitcherProperties properties) { setEnvironment(properties.getValue(ContextKey.ENVIRONMENT)); setLocal(properties.getBoolean(ContextKey.LOCAL_MODE)); setCheck(properties.getBoolean(ContextKey.CHECK_SWITCHERS)); - setAutoRefreshToken(properties.getBoolean(ContextKey.AUTO_REFRESH_TOKEN)); setSilent(properties.getValue(ContextKey.SILENT_MODE)); setTimeout(properties.getInt(ContextKey.TIMEOUT_MS)); setPoolSize(properties.getInt(ContextKey.POOL_CONNECTION_SIZE)); + AuthConfig authConfig = new AuthConfig(); + authConfig.setAutoRefresh(properties.getBoolean(ContextKey.AUTH_AUTO_REFRESH)); + setAuth(authConfig); + RelayConfig relayConfig = new RelayConfig(); relayConfig.setRestrict(properties.getBoolean(ContextKey.RESTRICT_RELAY)); setRelay(relayConfig); @@ -107,8 +111,8 @@ public void setCheck(boolean check) { this.check = check; } - public void setAutoRefreshToken(boolean autoRefreshToken) { - this.autoRefreshToken = autoRefreshToken; + public void setAuth(AuthConfig auth) { + this.auth = auth; } public void setSilent(String silent) { @@ -134,6 +138,18 @@ public void setTruststore(TruststoreConfig truststore) { this.truststore = truststore; } + public static class AuthConfig { + private boolean autoRefresh; + + public boolean isAutoRefresh() { + return autoRefresh; + } + + public void setAutoRefresh(boolean autoRefresh) { + this.autoRefresh = autoRefresh; + } + } + public static class RelayConfig { private boolean restrict; diff --git a/src/main/java/com/switcherapi/client/SwitcherContextBase.java b/src/main/java/com/switcherapi/client/SwitcherContextBase.java index 50e9f23..9293680 100644 --- a/src/main/java/com/switcherapi/client/SwitcherContextBase.java +++ b/src/main/java/com/switcherapi/client/SwitcherContextBase.java @@ -112,7 +112,7 @@ protected void configureClient() { .restrictRelay(relay.isRestrict()) .silentMode(silent) .timeoutMs(timeout) - .autoRefreshToken(autoRefreshToken) + .authAutoRefresh(auth.isAutoRefresh()) .poolConnectionSize(poolSize) .snapshotLocation(snapshot.getLocation()) .snapshotAutoLoad(snapshot.isAuto()) diff --git a/src/main/java/com/switcherapi/client/SwitcherPropertiesImpl.java b/src/main/java/com/switcherapi/client/SwitcherPropertiesImpl.java index 8d18b06..3995520 100644 --- a/src/main/java/com/switcherapi/client/SwitcherPropertiesImpl.java +++ b/src/main/java/com/switcherapi/client/SwitcherPropertiesImpl.java @@ -30,7 +30,7 @@ private void initDefaults() { setValue(ContextKey.LOCAL_MODE, false); setValue(ContextKey.CHECK_SWITCHERS, false); setValue(ContextKey.RESTRICT_RELAY, true); - setValue(ContextKey.AUTO_REFRESH_TOKEN, false); + setValue(ContextKey.AUTH_AUTO_REFRESH, false); } @Override @@ -50,7 +50,7 @@ public void loadFromProperties(Properties prop) { setValue(ContextKey.LOCAL_MODE, getBoolDefault(resolveProperties(ContextKey.LOCAL_MODE.getParam(), prop), false)); setValue(ContextKey.CHECK_SWITCHERS, getBoolDefault(resolveProperties(ContextKey.CHECK_SWITCHERS.getParam(), prop), false)); setValue(ContextKey.RESTRICT_RELAY, getBoolDefault(resolveProperties(ContextKey.RESTRICT_RELAY.getParam(), prop), true)); - setValue(ContextKey.AUTO_REFRESH_TOKEN, getBoolDefault(resolveProperties(ContextKey.AUTO_REFRESH_TOKEN.getParam(), prop), false)); + setValue(ContextKey.AUTH_AUTO_REFRESH, getBoolDefault(resolveProperties(ContextKey.AUTH_AUTO_REFRESH.getParam(), prop), false)); setValue(ContextKey.REGEX_TIMEOUT, getIntDefault(resolveProperties(ContextKey.REGEX_TIMEOUT.getParam(), prop), DEFAULT_REGEX_TIMEOUT)); setValue(ContextKey.TRUSTSTORE_PATH, resolveProperties(ContextKey.TRUSTSTORE_PATH.getParam(), prop)); setValue(ContextKey.TRUSTSTORE_PASSWORD, resolveProperties(ContextKey.TRUSTSTORE_PASSWORD.getParam(), prop)); diff --git a/src/main/java/com/switcherapi/client/model/ContextKey.java b/src/main/java/com/switcherapi/client/model/ContextKey.java index e89d67e..3b18c18 100644 --- a/src/main/java/com/switcherapi/client/model/ContextKey.java +++ b/src/main/java/com/switcherapi/client/model/ContextKey.java @@ -114,7 +114,7 @@ public enum ContextKey { /** * (boolean) Enables automatic refresh of authentication token (default is false) */ - AUTO_REFRESH_TOKEN("switcher.autorefreshtoken"); + AUTH_AUTO_REFRESH("switcher.auth.autorefresh"); private final String param; diff --git a/src/main/java/com/switcherapi/client/service/remote/ClientRemoteService.java b/src/main/java/com/switcherapi/client/service/remote/ClientRemoteService.java index 5e798dd..281ca6c 100644 --- a/src/main/java/com/switcherapi/client/service/remote/ClientRemoteService.java +++ b/src/main/java/com/switcherapi/client/service/remote/ClientRemoteService.java @@ -170,7 +170,7 @@ private void scheduleNextAuth() { } private boolean isAutoRefreshable() { - return switcherProperties.getBoolean(ContextKey.AUTO_REFRESH_TOKEN) && + return switcherProperties.getBoolean(ContextKey.AUTH_AUTO_REFRESH) && (Objects.isNull(refreshFuture) || refreshFuture.isDone()); } diff --git a/src/test/java/com/switcherapi/client/SwitcherConfigTest.java b/src/test/java/com/switcherapi/client/SwitcherConfigTest.java index 18dd77d..eeff1a9 100644 --- a/src/test/java/com/switcherapi/client/SwitcherConfigTest.java +++ b/src/test/java/com/switcherapi/client/SwitcherConfigTest.java @@ -38,6 +38,9 @@ void shouldInitializeClientFromSwitcherConfig_Minimal() { private T buildSwitcherClientConfig(T classConfig, String component, String domain) { + SwitcherConfig.AuthConfig auth = new SwitcherConfig.AuthConfig(); + auth.setAutoRefresh(false); + SwitcherConfig.RelayConfig relay = new SwitcherConfig.RelayConfig(); relay.setRestrict(false); @@ -61,6 +64,7 @@ private T buildSwitcherClientConfig(T classConfig, St classConfig.setSilent("5m"); classConfig.setTimeout(3000); classConfig.setPoolSize(2); + classConfig.setAuth(auth); classConfig.setRelay(relay); classConfig.setSnapshot(snapshot); classConfig.setTruststore(truststore); diff --git a/src/test/java/com/switcherapi/client/SwitcherRemoteAuthAutoRefreshTest.java b/src/test/java/com/switcherapi/client/SwitcherRemoteAuthAutoRefreshTest.java index 5c3afe3..9908463 100644 --- a/src/test/java/com/switcherapi/client/SwitcherRemoteAuthAutoRefreshTest.java +++ b/src/test/java/com/switcherapi/client/SwitcherRemoteAuthAutoRefreshTest.java @@ -14,7 +14,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; -class SwitcherRemoteAutoRefreshTokenTest extends MockWebServerHelper { +class SwitcherRemoteAuthAutoRefreshTest extends MockWebServerHelper { @BeforeEach void setup() throws IOException { @@ -40,7 +40,7 @@ void shouldAutoRefreshAuthToken() { givenResponse(generateCriteriaResponse("true", false)); //when - givenAutoRefreshToken(true); + givenAuthAutoRefresh(true); //test SwitcherRequest switcher = SwitchersBase.getSwitcher(SwitchersBase.USECASE11); @@ -58,7 +58,7 @@ void shouldNotAutoRefreshAuthTokenWhenDisabled() { givenResponse(generateCriteriaResponse("true", false)); //when - givenAutoRefreshToken(false); + givenAuthAutoRefresh(false); //test SwitcherRequest switcher = SwitchersBase.getSwitcher(SwitchersBase.USECASE11); @@ -75,7 +75,7 @@ void shouldNotAutoRefreshAuthTokenWhenAuthFails() { givenResponse(generateStatusResponse("500")); //when - givenAutoRefreshToken(true); + givenAuthAutoRefresh(true); //test SwitcherRequest switcher = SwitchersBase.getSwitcher(SwitchersBase.USECASE11); @@ -84,7 +84,7 @@ void shouldNotAutoRefreshAuthTokenWhenAuthFails() { assertThrows(SwitcherRemoteException.class, switcher::isItOn); } - private void givenAutoRefreshToken(boolean enabled) { + private void givenAuthAutoRefresh(boolean enabled) { SwitchersBase.configure(ContextBuilder.builder(true) .context(SwitchersBase.class.getName()) .url(String.format("http://localhost:%s", mockBackEnd.getPort())) diff --git a/src/test/java/com/switcherapi/playground/Features.java b/src/test/java/com/switcherapi/playground/Features.java index e7a4299..3dd9c42 100644 --- a/src/test/java/com/switcherapi/playground/Features.java +++ b/src/test/java/com/switcherapi/playground/Features.java @@ -17,7 +17,7 @@ protected void configureClient() { .apiKey(System.getenv("switcher.api.key")) .component(System.getenv("switcher.component")) .domain(System.getenv("switcher.domain")) - .autoRefreshToken(true)); + .authAutoRefresh(true)); initializeClient(); }