Last active
October 4, 2024 03:10
-
-
Save unclebean/d39ac0b78108fad5635b1016ce27b064 to your computer and use it in GitHub Desktop.
az
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ManagedIdentityCredential managedIdentityCredential = new ManagedIdentityCredentialBuilder() | |
.clientId("your-umi-client-id") // User Managed Identity Client ID | |
.build(); | |
String token = managedIdentityCredential.getToken( | |
new TokenRequestContext().addScopes("https://ossrdbms-aad.database.windows.net/.default") | |
).block().getToken(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
azure: | |
identity: | |
managed-identity: | |
client-id: <UAMI-client-id> # Optional, only if you are using User-Assigned Managed Identity | |
active-directory: | |
client-id: <client-id> # Your Azure AD application client ID | |
tenant-id: <tenant-id> # Azure AD tenant ID |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Bean | |
public DataSource dataSource() { | |
PGSimpleDataSource dataSource = new PGSimpleDataSource(); | |
dataSource.setURL("jdbc:postgresql://<your-azure-postgres-server>:5432/<db-name>"); | |
dataSource.setUser("<username>"); | |
// Obtain token using MSAL (or Azure SDK for identity) | |
String accessToken = getAccessTokenForPostgres(); | |
dataSource.setPassword(accessToken); | |
return dataSource; | |
} | |
private String getAccessTokenForPostgres() { | |
TokenCredential tokenCredential = new ManagedIdentityCredentialBuilder() | |
.clientId("<UAMI-client-id>") | |
.build(); | |
AccessToken token = tokenCredential.getToken(new TokenRequestContext() | |
.addScopes("https://<your-azure-postgres-server>.database.windows.net/.default")).block(); | |
return token.getToken(); | |
} | |
@Bean | |
public BlobServiceClient blobServiceClient() { | |
TokenCredential tokenCredential = new ManagedIdentityCredentialBuilder() | |
.clientId("<UAMI-client-id>") | |
.build(); | |
return new BlobServiceClientBuilder() | |
.endpoint("<your-blob-endpoint>") | |
.credential(tokenCredential) | |
.buildClient(); | |
} | |
@Bean | |
public SearchClient searchClient() { | |
TokenCredential tokenCredential = new ManagedIdentityCredentialBuilder() | |
.clientId("<UAMI-client-id>") | |
.build(); | |
return new SearchClientBuilder() | |
.endpoint("<your-search-service-endpoint>") | |
.credential(tokenCredential) | |
.indexName("<index-name>") | |
.buildClient(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
azure: | |
postgres: | |
url: "jdbc:postgresql://<your-azure-postgres-server>:5432/<db-name>" | |
username: "<db-username>" | |
tenant-id: "<your-tenant-id>" | |
client-id: "<UAMI-client-id>" | |
blob: | |
endpoint: "<your-blob-endpoint>" | |
cognitive-search: | |
endpoint: "<your-search-service-endpoint>" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<dependency> | |
<groupId>com.azure.spring</groupId> | |
<artifactId>azure-spring-boot-starter-active-directory</artifactId> | |
<version>4.3.0</version> | |
</dependency> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment