|
3 | 3 |
|
4 | 4 | package com.azure.spring.cloud.autoconfigure.implementation.passwordless.properties; |
5 | 5 |
|
| 6 | +import com.azure.spring.cloud.core.implementation.properties.AzurePasswordlessPropertiesMapping; |
6 | 7 | import com.azure.spring.cloud.core.properties.PasswordlessProperties; |
7 | 8 | import com.azure.spring.cloud.core.properties.authentication.TokenCredentialProperties; |
8 | 9 | import com.azure.spring.cloud.core.properties.profile.AzureProfileProperties; |
9 | 10 | import com.azure.spring.cloud.core.provider.AzureProfileOptionsProvider; |
10 | 11 |
|
11 | 12 | import java.util.HashMap; |
12 | 13 | import java.util.Map; |
| 14 | +import java.util.Properties; |
13 | 15 |
|
14 | 16 | /** |
15 | 17 | * Configuration properties for passwordless connections with Azure Redis. |
@@ -43,11 +45,22 @@ public class AzureRedisPasswordlessProperties implements PasswordlessProperties |
43 | 45 |
|
44 | 46 | /** |
45 | 47 | * Get the scopes required for the access token. |
| 48 | + * Returns null if scopes have not been explicitly set, so that the default |
| 49 | + * scopes can be computed from the merged cloud type after property merging. |
46 | 50 | * |
47 | | - * @return scopes required for the access token |
| 51 | + * @return scopes required for the access token, or null if not explicitly set |
48 | 52 | */ |
49 | 53 | @Override |
50 | 54 | public String getScopes() { |
| 55 | + return this.scopes; |
| 56 | + } |
| 57 | + |
| 58 | + /** |
| 59 | + * Get the effective scopes, returning default cloud-specific scopes when not explicitly set. |
| 60 | + * |
| 61 | + * @return scopes required for the access token |
| 62 | + */ |
| 63 | + public String getEffectiveScopes() { |
51 | 64 | return this.scopes == null ? getDefaultScopes() : this.scopes; |
52 | 65 | } |
53 | 66 |
|
@@ -121,4 +134,25 @@ public TokenCredentialProperties getCredential() { |
121 | 134 | public void setCredential(TokenCredentialProperties credential) { |
122 | 135 | this.credential = credential; |
123 | 136 | } |
| 137 | + |
| 138 | + /** |
| 139 | + * Convert {@link AzureRedisPasswordlessProperties} to {@link Properties}. |
| 140 | + * Uses the effective scopes (cloud-type-aware) rather than the raw scopes value, |
| 141 | + * ensuring the correct default scope is used when scopes have not been explicitly set. |
| 142 | + * |
| 143 | + * @return converted {@link Properties} instance |
| 144 | + */ |
| 145 | + @Override |
| 146 | + public Properties toPasswordlessProperties() { |
| 147 | + Properties properties = new Properties(); |
| 148 | + for (AzurePasswordlessPropertiesMapping m : AzurePasswordlessPropertiesMapping.values()) { |
| 149 | + String value = m == AzurePasswordlessPropertiesMapping.SCOPES |
| 150 | + ? getEffectiveScopes() |
| 151 | + : m.getGetter().apply(this); |
| 152 | + if (value != null) { |
| 153 | + m.getSetter().accept(properties, value); |
| 154 | + } |
| 155 | + } |
| 156 | + return properties; |
| 157 | + } |
124 | 158 | } |
0 commit comments