Skip to content

Commit 5f9ba1f

Browse files
Merge pull request #311690 from mrm9084/JavaAudienceEntraId
App Config Java Audience Usage
2 parents 7f3d751 + b2f2c7f commit 5f9ba1f

1 file changed

Lines changed: 64 additions & 0 deletions

File tree

articles/azure-app-configuration/concept-enable-rbac.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,70 @@ builder.AddAzureAppConfiguration(o =>
105105
});
106106
```
107107

108+
### [Java](#tab/java)
109+
110+
The Audience for the target cloud must be configured for the following packages.
111+
112+
- Azure SDK for Java: azure-data-appconfiguration >= 1.8.0
113+
- Java configuration provider: spring-cloud-azure-appconfiguration-config >= 5.22.0
114+
115+
In the **Azure SDK for Java**, audience is configured by passing the `audience` option to the `ConfigurationClientBuilder` when building a `ConfigurationClient`.
116+
117+
The following code snippet demonstrates how to instantiate a configuration client with a cloud-specific audience.
118+
119+
```java
120+
ConfigurationClient configurationClient = new ConfigurationClientBuilder()
121+
.endpoint(myStoreEndpoint)
122+
.credential(new DefaultAzureCredentialBuilder().build())
123+
.audience(ConfigurationAudience.fromString("{Cloud specific audience here}"))
124+
.buildClient();
125+
```
126+
127+
In the **Spring configuration provider**, audience is configured by customizing the `ConfigurationClientBuilder` through the `ConfigurationClientCustomizer` interface, then adding it to the bootstrap registry.
128+
129+
The following code snippet demonstrates how to add the Azure App Configuration provider into a Spring Boot application with a cloud-specific audience.
130+
131+
```java
132+
import com.azure.data.appconfiguration.ConfigurationClientBuilder;
133+
import com.azure.data.appconfiguration.models.ConfigurationAudience;
134+
import com.azure.spring.cloud.appconfiguration.config.ConfigurationClientCustomizer;
135+
136+
public class CustomClient implements ConfigurationClientCustomizer {
137+
138+
@Override
139+
public void customize(ConfigurationClientBuilder builder, String endpoint) {
140+
builder.audience(ConfigurationAudience.fromString("{Cloud specific audience here}"));
141+
}
142+
}
143+
```
144+
145+
Then, register the `CustomClient` in the bootstrap registry.
146+
147+
```java
148+
import org.springframework.boot.SpringApplication;
149+
import org.springframework.boot.autoconfigure.AutoConfiguration;
150+
import org.springframework.boot.autoconfigure.SpringBootApplication;
151+
152+
import hello.impl.AppConfigClientImpl;
153+
154+
@SpringBootApplication
155+
@AutoConfiguration
156+
public class Application {
157+
158+
public static void main(String[] args) {
159+
SpringApplication app = new SpringApplication(Application.class);
160+
161+
// Register the ConfigurationClientCustomizer in the bootstrap context
162+
app.addBootstrapRegistryInitializer(registry -> {
163+
registry.register(CustomClient.class, context -> new CustomClient());
164+
});
165+
166+
app.run(args);
167+
}
168+
169+
}
170+
```
171+
108172
### [JavaScript](#tab/javascript)
109173

110174
The Audience for the target cloud must be configured for the following packages.

0 commit comments

Comments
 (0)