Skip to content

Commit 83089b4

Browse files
authored
Merge branch 'main' into dependabot/maven/org.slf4j-slf4j-api-2.0.17
2 parents bbc3cdd + 077e460 commit 83089b4

File tree

15 files changed

+461
-14
lines changed

15 files changed

+461
-14
lines changed

.github/workflows/core_integration.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
java-version: '8'
3636
distribution: 'temurin'
3737
- name: Cache dependencies
38-
uses: actions/cache@v2
38+
uses: actions/cache@v4
3939
with:
4040
path: |
4141
~/.m2/repository

.github/workflows/core_snapshot.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
server-username: MAVEN_USERNAME
2929
server-password: MAVEN_PASSWORD
3030
- name: Cache dependencies
31-
uses: actions/cache@v2
31+
uses: actions/cache@v4
3232
with:
3333
path: |
3434
~/.m2/repository

.github/workflows/entraid_integration.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
java-version: '8'
3535
distribution: 'temurin'
3636
- name: Cache dependencies
37-
uses: actions/cache@v2
37+
uses: actions/cache@v4
3838
with:
3939
path: |
4040
~/.m2/repository
@@ -64,3 +64,4 @@ jobs:
6464
AZURE_CERT: ${{secrets.AZURE_CERT}}
6565
AZURE_PRIVATE_KEY: ${{secrets.AZURE_PRIVATE_KEY}}
6666
AZURE_REDIS_SCOPES: ${{secrets.AZURE_REDIS_SCOPES}}
67+
AZURE_TENANT_ID: ${{secrets.AZURE_TENANT_ID}}

.github/workflows/entraid_snapshot.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
server-username: MAVEN_USERNAME
3030
server-password: MAVEN_PASSWORD
3131
- name: Cache dependencies
32-
uses: actions/cache@v2
32+
uses: actions/cache@v4
3333
with:
3434
path: |
3535
~/.m2/repository

core/src/main/java/redis/clients/authentication/core/Dispatcher.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
/*
2-
* Copyright 2024, Redis Ltd. and Contributors All rights reserved. Licensed under the MIT License.
2+
* Copyright 2024, Redis Ltd. and Contributors
3+
* All rights reserved.
4+
*
5+
* Licensed under the MIT License.
36
*/
47
package redis.clients.authentication.core;
58

core/src/main/java/redis/clients/authentication/core/RenewalScheduler.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
/*
2-
* Copyright 2024, Redis Ltd. and Contributors All rights reserved. Licensed under the MIT License.
2+
* Copyright 2024, Redis Ltd. and Contributors
3+
* All rights reserved.
4+
*
5+
* Licensed under the MIT License.
36
*/
47
package redis.clients.authentication.core;
58

core/src/main/java/redis/clients/authentication/core/TokenManager.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
/*
2-
* Copyright 2024, Redis Ltd. and Contributors All rights reserved. Licensed under the MIT License.
2+
* Copyright 2024, Redis Ltd. and Contributors
3+
* All rights reserved.
4+
*
5+
* Licensed under the MIT License.
36
*/
47
package redis.clients.authentication.core;
58

entraid/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@
6767
<artifactId>msal4j</artifactId>
6868
<version>1.17.2</version>
6969
</dependency>
70+
<dependency>
71+
<groupId>com.azure</groupId>
72+
<artifactId>azure-identity</artifactId>
73+
<version>1.15.3</version>
74+
</dependency>
7075
<dependency>
7176
<groupId>junit</groupId>
7277
<artifactId>junit</artifactId>
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Copyright 2024, Redis Ltd. and Contributors
3+
* All rights reserved.
4+
*
5+
* Licensed under the MIT License.
6+
*/
7+
package redis.clients.authentication.entraid;
8+
9+
import java.time.Duration;
10+
import java.util.ArrayList;
11+
import java.util.Set;
12+
import java.util.function.Supplier;
13+
14+
import com.azure.core.credential.AccessToken;
15+
import com.azure.core.credential.TokenRequestContext;
16+
import com.azure.identity.DefaultAzureCredential;
17+
import redis.clients.authentication.core.IdentityProvider;
18+
import redis.clients.authentication.core.Token;
19+
20+
/**
21+
* AzureIdentityProvider is an implementation of the IdentityProvider interface
22+
* that uses Azure's DefaultAzureCredential to obtain access tokens.
23+
*
24+
* <p>This class is designed to work with Azure's identity platform to provide
25+
* authentication tokens for accessing Azure resources. It uses a
26+
* DefaultAzureCredential to request tokens with specified scopes and a timeout(in milliseconds).
27+
* For most cases you will not need to use it directly since AzureTokenAuthConfigBuilder
28+
* will do the work for you as shown in the example below:
29+
* <pre>
30+
* {@code
31+
* TokenAuthConfig config = AzureTokenAuthConfigBuilder.builder()
32+
* .defaultAzureCredential(new DefaultAzureCredential()).build();
33+
* }
34+
* </pre>
35+
* <p>In you case you need your own implementation for relevant reasons, you can use it as follows:
36+
* <pre>
37+
* {@code
38+
* Set<String> scopes = new HashSet<>(Arrays.asList("https://redis.azure.com/.default"));
39+
* AzureIdentityProvider provider = new AzureIdentityProvider(
40+
* new DefaultAzureCredentialBuilder().build(), scopes, 5000);
41+
* TokenAuthConfig config = AzureTokenAuthConfigBuilder.builder().identityProviderConfig(()-> provider)).build();
42+
* }
43+
* </pre>
44+
*
45+
* <p>Thread Safety: This class is thread-safe as long as the provided
46+
* DefaultAzureCredential is thread-safe.
47+
*
48+
* @see redis.clients.authentication.entraid.AzureTokenAuthConfigBuilder
49+
* @see com.azure.identity.DefaultAzureCredentialBuilder
50+
*/
51+
52+
public final class AzureIdentityProvider implements IdentityProvider {
53+
54+
private Supplier<AccessToken> accessTokenSupplier;
55+
56+
public AzureIdentityProvider(DefaultAzureCredential defaultAzureCredential, Set<String> scopes,
57+
int timeout) {
58+
TokenRequestContext ctx = new TokenRequestContext()
59+
.setScopes(new ArrayList<String>(scopes));
60+
accessTokenSupplier = () -> defaultAzureCredential.getToken(ctx)
61+
.block(Duration.ofMillis(timeout));
62+
}
63+
64+
@Override
65+
public Token requestToken() {
66+
return new JWToken(accessTokenSupplier.get().getToken());
67+
}
68+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Copyright 2024, Redis Ltd. and Contributors
3+
* All rights reserved.
4+
*
5+
* Licensed under the MIT License.
6+
*/
7+
package redis.clients.authentication.entraid;
8+
9+
import java.util.Set;
10+
import java.util.function.Supplier;
11+
12+
import com.azure.identity.DefaultAzureCredential;
13+
14+
import redis.clients.authentication.core.IdentityProvider;
15+
import redis.clients.authentication.core.IdentityProviderConfig;
16+
17+
/**
18+
* Configuration class for Azure Identity Provider.
19+
* This class implements the {@link IdentityProviderConfig} interface and provides
20+
* a configuration for creating an {@link AzureIdentityProvider} instance.
21+
*
22+
* <p>This class uses {@link DefaultAzureCredential} for authentication and allows
23+
* specifying scopes and a timeout(in milliseconds) for the identity provider.</p>
24+
* For most cases you will not need to use it directly since AzureTokenAuthConfigBuilder
25+
* will do the work for you as shown in the example below:
26+
* <pre>
27+
* {@code
28+
* TokenAuthConfig config = AzureTokenAuthConfigBuilder.builder()
29+
* .defaultAzureCredential(new DefaultAzureCredentialBuilder()).build();
30+
* }
31+
* </pre>
32+
* <p>In you case you need your own implementation for relevant reasons, you can use it as follows:
33+
* <pre>
34+
* {@code
35+
* DefaultAzureCredential credential = new DefaultAzureCredentialBuilder().build();
36+
* Set<String> scopes = Set.of("https://redis.azure.com/.default");
37+
* AzureIdentityProviderConfig azureIDPConfig = new AzureIdentityProviderConfig(credential, scopes, 5000);
38+
* TokenAuthConfig config = AzureTokenAuthConfigBuilder.builder().identityProviderConfig(azureIDPConfig).build();
39+
* }
40+
* </pre>
41+
*
42+
* For more information and details on how to use, please see:
43+
* https://github.com/redis/jedis/blob/master/docs/advanced-usage.md#token-based-authentication
44+
* https://github.com/redis/lettuce/blob/main/docs/user-guide/connecting-redis.md#microsoft-entra-id-authentication
45+
*
46+
* @see IdentityProviderConfig
47+
* @see AzureIdentityProvider
48+
* @see DefaultAzureCredential
49+
*/
50+
public final class AzureIdentityProviderConfig implements IdentityProviderConfig {
51+
52+
private final Supplier<IdentityProvider> providerSupplier;
53+
54+
public AzureIdentityProviderConfig(DefaultAzureCredential defaultAzureCredential, Set<String> scopes, int timeout) {
55+
providerSupplier = () -> new AzureIdentityProvider(defaultAzureCredential, scopes, timeout);
56+
}
57+
58+
@Override
59+
public IdentityProvider getProvider() {
60+
return providerSupplier.get();
61+
}
62+
}

0 commit comments

Comments
 (0)