Skip to content

Commit e51a97b

Browse files
authored
Merge pull request #12 from ggivo/verify-config-provided
Add check for missing IdentityProvider configuration.
2 parents a407114 + cb811ac commit e51a97b

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

.github/wordlist.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ ClusterPipeline
1616
ClusterPubSub
1717
ConnectionPool
1818
CoreCommands
19+
Entra
20+
EntraID
1921
EVAL
2022
EVALSHA
2123
Failback
@@ -30,6 +32,7 @@ GeoRadiusParam
3032
GeoRadiusStoreParam
3133
GeoUnit
3234
GraphCommands
35+
Gradle
3336
Grokzen's
3437
HostAndPort
3538
HostnameVerifier
@@ -41,6 +44,7 @@ JSONArray
4144
JSONCommands
4245
Jaeger
4346
Javadocs
47+
Jedis
4448
ListPosition
4549
Ludovico
4650
Magnocavallo
@@ -59,6 +63,7 @@ POJOs
5963
PubSub
6064
Queable
6165
READONLY
66+
Reauthentication
6267
RediSearch
6368
RediSearchCommands
6469
RedisBloom

entraid/src/main/java/redis/clients/authentication/entraid/EntraIDTokenAuthConfigBuilder.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,11 @@ public TokenAuthConfig build() {
118118
throw new RedisEntraIDException(
119119
"Cannot have both customEntraIdAuthenticationSupplier and ServicePrincipal/ManagedIdentity!");
120120
}
121+
if (this.customEntraIdAuthenticationSupplier == null && spi == null && mii == null) {
122+
throw new RedisEntraIDException(
123+
"Missing configuration. One of customEntraIdAuthenticationSupplier, ServicePrincipal or ManagedIdentity must be configured!");
124+
}
125+
121126
if (spi != null) {
122127
super.identityProviderConfig(
123128
new EntraIDIdentityProviderConfig(spi, scopes, tokenRequestExecTimeoutInMs));

entraid/src/test/java/redis/clients/authentication/EntraIDUnitTests.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
import java.util.concurrent.atomic.AtomicInteger;
3838
import java.util.function.Supplier;
3939

40+
import com.microsoft.aad.msal4j.IAccount;
41+
import com.microsoft.aad.msal4j.ITenantProfile;
4042
import org.awaitility.Awaitility;
4143
import org.awaitility.Durations;
4244
import org.junit.Test;
@@ -64,6 +66,7 @@
6466
import redis.clients.authentication.entraid.EntraIDTokenAuthConfigBuilder;
6567
import redis.clients.authentication.entraid.JWToken;
6668
import redis.clients.authentication.entraid.ManagedIdentityInfo;
69+
import redis.clients.authentication.entraid.RedisEntraIDException;
6770
import redis.clients.authentication.entraid.ServicePrincipalInfo;
6871
import redis.clients.authentication.entraid.ManagedIdentityInfo.UserManagedIdentityType;
6972

@@ -143,6 +146,28 @@ public void testConfigBuilder() {
143146
}
144147
}
145148

149+
@Test
150+
public void testConfigBuilderThrowsErrorIfMissconfigured() {
151+
152+
// Missing Configuration
153+
assertThrows(RedisEntraIDException.class,() -> EntraIDTokenAuthConfigBuilder.builder().build());
154+
155+
// spi & mpi configured
156+
assertThrows(RedisEntraIDException.class,() -> EntraIDTokenAuthConfigBuilder.builder()
157+
.clientId("clientid")
158+
.secret("secret")
159+
.systemAssignedManagedIdentity()
160+
.build());
161+
162+
// spi || mpi && customEntraIdAuthenticationSupplier configured
163+
assertThrows(RedisEntraIDException.class,() -> EntraIDTokenAuthConfigBuilder.builder()
164+
.clientId("clientid")
165+
.secret("secret")
166+
.customEntraIdAuthenticationSupplier(() -> mock(IAuthenticationResult.class))
167+
.build());
168+
}
169+
170+
146171
// T.1.2
147172
// Implement a stubbed IdentityProvider and verify that the TokenManager works normally and handles:
148173
// network errors or other exceptions thrown from the IdentityProvider
@@ -529,6 +554,7 @@ public void renewalTimingConfigTest() {
529554
int maxAttemptsToRetry = 6;
530555
int tokenRequestExecTimeoutInMs = 401;
531556
TokenAuthConfig tokenAuthConfig = EntraIDTokenAuthConfigBuilder.builder()
557+
.clientId("testClientId").secret("testSecret")
532558
.expirationRefreshRatio(refreshRatio).delayInMsToRetry(delayInMsToRetry)
533559
.lowerRefreshBoundMillis(lowerRefreshBoundMillis)
534560
.maxAttemptsToRetry(maxAttemptsToRetry)

0 commit comments

Comments
 (0)