Skip to content

Commit 4a81e04

Browse files
committed
Add check for missing IdentityProvider configuration.
1 parent a407114 commit 4a81e04

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

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: 25 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

0 commit comments

Comments
 (0)