Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class CosmosProperties {
private String defaultScope;
private String tenantId;
private String clientId;
private String managedIdentityId;
private String clientSecret;
private String databaseName;
private boolean queryMetricsEnabled;
Expand Down Expand Up @@ -47,6 +48,14 @@ public void setClientId(String clientId) {
this.clientId = clientId;
}

public String getManagedIdentityId() {
return managedIdentityId;
}

public void setManagedIdentityId(String managedIdentityId) {
this.managedIdentityId = managedIdentityId;
}

public String getClientSecret() {
return clientSecret;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.azure.cosmos.CosmosClientBuilder;
import com.azure.cosmos.DirectConnectionConfig;
import com.azure.identity.ClientSecretCredentialBuilder;
import com.azure.identity.DefaultAzureCredentialBuilder;
import com.azure.spring.data.cosmos.config.AbstractCosmosConfiguration;
import com.azure.spring.data.cosmos.config.CosmosConfig;
import com.azure.spring.data.cosmos.core.ResponseDiagnostics;
Expand Down Expand Up @@ -42,11 +43,10 @@ public SampleAppConfiguration(CosmosProperties properties){
@Bean
public CosmosClientBuilder cosmosClientBuilder() {
DirectConnectionConfig directConnectionConfig = DirectConnectionConfig.getDefaultConfig();
TokenCredential servicePrincipal = new ClientSecretCredentialBuilder()
TokenCredential servicePrincipal = new DefaultAzureCredentialBuilder()
.authorityHost("https://login.microsoftonline.com") //this line is not required (is redundant) if connecting to AAD
.tenantId(properties.getTenantId())
.clientId(properties.getClientId())
.clientSecret(properties.getClientSecret())
.managedIdentityClientId(properties.getClientId())
.build();

//if this check fails, review error in logs and AAD setup as well as connectivity to AAD.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ spring:
tenantId: <TENANT_ID>
clientId: <CLIENT_ID>
clientSecret: <CLIENT_SECRET>
managedIdentityId: <MANAGED_IDENTITY_ID>
defaultScope: https://<COSMOS_ACCOUNT>.documents.azure.com/.default
databaseName: testdb
queryMetricsEnabled: true