forked from Azure/azure-sdk-for-java
-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bridge azure properties to spring starter to authenticate #5
Closed
moarychan
wants to merge
10
commits into
saragluna:feature/unify-azure-spring-credential
from
moarychan:feature/unify-azure-spring-credential
Closed
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
94353ba
temp saved for cosmos, storage and keyvault
6ec0e05
merge branch
0e5ec4c
use mapping properties provider to bridge
92f0f85
Extract the abstract interface to customize the client builder
6fdd070
test cosmos
d45335a
test and fix generic type issue
79749ea
Add TokenCredentialCallback interface and default implementation
548b429
Fixes comments and test storage with SP and cert file
c332fd2
Delete unused file
d8e972e
Update configuration
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
...oud-autoconfigure/src/main/java/com/azure/spring/MappingCredentialPropertiesProvider.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
package com.azure.spring; | ||
|
||
import com.azure.core.credential.TokenCredential; | ||
import com.azure.spring.autoconfigure.unity.CredentialProperties; | ||
import com.azure.spring.autoconfigure.unity.EnvironmentProperties; | ||
import com.azure.spring.identity.CredentialPropertiesProvider; | ||
|
||
/** | ||
* An interface to provide all credential related properties based on the properties subclass. | ||
*/ | ||
public interface MappingCredentialPropertiesProvider extends CredentialPropertiesProvider { | ||
|
||
void mapAzureProperties(CredentialProperties credentialProperties, EnvironmentProperties environment); | ||
|
||
TokenCredential mappingTokenCredential(); | ||
} |
82 changes: 82 additions & 0 deletions
82
...toconfigure/src/main/java/com/azure/spring/SpringMappingCredentialPropertiesProvider.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
package com.azure.spring; | ||
|
||
import com.azure.core.credential.TokenCredential; | ||
import com.azure.spring.autoconfigure.unity.AzureProperties; | ||
import com.azure.spring.autoconfigure.unity.CredentialProperties; | ||
import com.azure.spring.autoconfigure.unity.EnvironmentProperties; | ||
import com.azure.spring.identity.SpringEnvironmentCredentialBuilder; | ||
|
||
import java.util.Optional; | ||
|
||
/** | ||
* An implementation to provide all credential related properties based on properties subclass. | ||
*/ | ||
public class SpringMappingCredentialPropertiesProvider implements MappingCredentialPropertiesProvider { | ||
|
||
CredentialProperties credentialProperties; | ||
EnvironmentProperties environment; | ||
|
||
public SpringMappingCredentialPropertiesProvider(AzureProperties azureProperties) { | ||
if (azureProperties != null) { | ||
mapAzureProperties(azureProperties.getCredential(), azureProperties.getEnvironment()); | ||
} | ||
} | ||
|
||
@Override | ||
public void mapAzureProperties(CredentialProperties credentialProperties, | ||
EnvironmentProperties environment) { | ||
this.credentialProperties = credentialProperties; | ||
this.environment = environment; | ||
} | ||
|
||
|
||
@Override | ||
public TokenCredential mappingTokenCredential() { | ||
SpringEnvironmentCredentialBuilder mapEnvironmentCredentialBuilder = | ||
new SpringEnvironmentCredentialBuilder().credentialPropertiesProvider(this); | ||
return mapEnvironmentCredentialBuilder.build(); | ||
} | ||
|
||
@Override | ||
public String getTenantId() { | ||
return Optional.ofNullable(credentialProperties).map(CredentialProperties::getTenantId).orElse(null); | ||
} | ||
|
||
@Override | ||
public String getClientId() { | ||
return Optional.ofNullable(credentialProperties).map(CredentialProperties::getClientId).orElse(null); | ||
} | ||
|
||
@Override | ||
public String getClientSecret() { | ||
return Optional.ofNullable(credentialProperties).map(CredentialProperties::getClientSecret).orElse(null); | ||
} | ||
|
||
@Override | ||
public String getClientCertificatePath() { | ||
return Optional.ofNullable(credentialProperties).map(CredentialProperties::getCertificatePath).orElse(null); | ||
} | ||
|
||
@Override | ||
public String getCertificatePassword() { | ||
return Optional.ofNullable(credentialProperties).map(CredentialProperties::getCertificatePassword).orElse(null); | ||
} | ||
|
||
@Override | ||
public String getUsername() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public String getPassword() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public String getAuthorityHost() { | ||
return Optional.ofNullable(environment).map(EnvironmentProperties::getAuthorityHost).orElse(null); | ||
} | ||
} |
This file contains 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
29 changes: 29 additions & 0 deletions
29
...re/src/main/java/com/azure/spring/autoconfigure/cosmos/CosmosClientBuilderConfigurer.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
package com.azure.spring.autoconfigure.cosmos; | ||
|
||
import com.azure.cosmos.CosmosClientBuilder; | ||
import com.azure.spring.identity.AbstractClientBuilderConfigurer; | ||
import com.azure.spring.identity.AzureKeyCredentialClientBuilderCustomizer; | ||
|
||
/** | ||
* Configurer for extending Azure Cosmos service client builder configuration. | ||
*/ | ||
public class CosmosClientBuilderConfigurer extends AbstractClientBuilderConfigurer<CosmosClientBuilder> { | ||
|
||
private AzureKeyCredentialClientBuilderCustomizer<CosmosClientBuilder> azureKeyCredentialCustomizer; | ||
|
||
public void setAzureKeyCredentialCustomizer(AzureKeyCredentialClientBuilderCustomizer<CosmosClientBuilder> azureKeyCredentialCustomizer) { | ||
this.azureKeyCredentialCustomizer = azureKeyCredentialCustomizer; | ||
} | ||
|
||
@Override | ||
public CosmosClientBuilder configure(CosmosClientBuilder builder) { | ||
super.configure(builder); | ||
if (azureKeyCredentialCustomizer != null) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about omitting the DefaultSkipCredentialCallback and setting the credential by precedence, first setting the lower precedence and higher precedence. |
||
azureKeyCredentialCustomizer.keyCredential(builder); | ||
} | ||
return builder; | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need this to be a bean?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean the source of this key could only be the CosmosProperties.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For @saragluna, we need to check the key rotation logic here.