Skip to content
Merged
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 @@ -10,7 +10,7 @@
import com.azure.spring.cloud.core.implementation.util.AzurePasswordlessPropertiesUtils;
import com.azure.spring.cloud.core.implementation.util.AzureSpringIdentifier;
import com.azure.spring.cloud.service.implementation.identity.credential.provider.SpringTokenCredentialProvider;
import com.azure.spring.cloud.service.implementation.passwordless.AzureJdbcPasswordlessProperties;
import com.azure.spring.cloud.autoconfigure.implementation.passwordless.properties.AzureJdbcPasswordlessProperties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,12 @@ public class AzureServiceBusJmsProperties implements InitializingBean, Passwordl

private static final String SERVICE_BUS_SCOPE_AZURE = "https://servicebus.azure.net/.default";
private static final String SERVICE_BUS_SCOPE_AZURE_CHINA = SERVICE_BUS_SCOPE_AZURE;
private static final String SERVICE_BUS_SCOPE_AZURE_GERMANY = SERVICE_BUS_SCOPE_AZURE;
private static final String SERVICE_BUS_SCOPE_AZURE_US_GOVERNMENT = SERVICE_BUS_SCOPE_AZURE;

private static final Map<CloudType, String> SERVICEBUS_SCOPE_MAP = new HashMap<CloudType, String>() {
{
put(CloudType.AZURE, SERVICE_BUS_SCOPE_AZURE);
put(CloudType.AZURE_CHINA, SERVICE_BUS_SCOPE_AZURE_CHINA);
put(CloudType.AZURE_GERMANY, SERVICE_BUS_SCOPE_AZURE_GERMANY);
put(CloudType.AZURE_US_GOVERNMENT, SERVICE_BUS_SCOPE_AZURE_US_GOVERNMENT);
}
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.spring.cloud.service.implementation.passwordless;
package com.azure.spring.cloud.autoconfigure.implementation.passwordless.properties;

import com.azure.spring.cloud.core.properties.PasswordlessProperties;
import com.azure.spring.cloud.core.properties.authentication.TokenCredentialProperties;
Expand All @@ -17,14 +17,12 @@ public class AzureJdbcPasswordlessProperties implements PasswordlessProperties {

private static final String JDBC_SCOPE_AZURE = "https://ossrdbms-aad.database.windows.net/.default";
private static final String JDBC_SCOPE_AZURE_CHINA = "https://ossrdbms-aad.database.chinacloudapi.cn/.default";
private static final String JDBC_SCOPE_AZURE_GERMANY = "https://ossrdbms-aad.database.cloudapi.de/.default";
private static final String JDBC_SCOPE_AZURE_US_GOVERNMENT = "https://ossrdbms-aad.database.usgovcloudapi.net/.default";

private static final Map<CloudType, String> JDBC_SCOPE_MAP = new HashMap<CloudType, String>() {
{
put(CloudType.AZURE, JDBC_SCOPE_AZURE);
put(CloudType.AZURE_CHINA, JDBC_SCOPE_AZURE_CHINA);
put(CloudType.AZURE_GERMANY, JDBC_SCOPE_AZURE_GERMANY);
put(CloudType.AZURE_US_GOVERNMENT, JDBC_SCOPE_AZURE_US_GOVERNMENT);
}
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.spring.cloud.service.implementation.passwordless;
package com.azure.spring.cloud.autoconfigure.implementation.passwordless.properties;

import com.azure.spring.cloud.core.properties.PasswordlessProperties;
import com.azure.spring.cloud.core.properties.authentication.TokenCredentialProperties;
import com.azure.spring.cloud.core.properties.profile.AzureProfileProperties;

/**
* Configuration properties for passwordless connections with Azure ServiceBus.
* Configuration properties for passwordless connections with Azure Event Hubs Kafka.
*/
public class AzureKafkaPasswordlessProperties implements PasswordlessProperties {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -532,68 +532,68 @@
"name": "spring.datasource.azure.credential.client-id",
"type": "java.lang.String",
"description": "Client ID to use when performing service principal authentication with Azure.",
"sourceType": "com.azure.spring.cloud.service.implementation.passwordless.AzureJdbcPasswordlessProperties"
"sourceType": "com.azure.spring.cloud.autoconfigure.implementation.passwordless.properties.AzureJdbcPasswordlessProperties"
},
{
"name": "spring.datasource.azure.credential.client-secret",
"type": "java.lang.String",
"description": "Client secret to use when performing service principal authentication with Azure.",
"sourceType": "com.azure.spring.cloud.service.implementation.passwordless.AzureJdbcPasswordlessProperties"
"sourceType": "com.azure.spring.cloud.autoconfigure.implementation.passwordless.properties.AzureJdbcPasswordlessProperties"
},
{
"name": "spring.datasource.azure.credential.client-certificate-password",
"type": "java.lang.String",
"description": "Password of the certificate file.",
"sourceType": "com.azure.spring.cloud.service.implementation.passwordless.AzureJdbcPasswordlessProperties"
"sourceType": "com.azure.spring.cloud.autoconfigure.implementation.passwordless.properties.AzureJdbcPasswordlessProperties"
},
{
"name": "spring.datasource.azure.credential.client-certificate-path",
"type": "java.lang.String",
"description": "Path of a PEM certificate file to use when performing service principal authentication with Azure.",
"sourceType": "com.azure.spring.cloud.service.implementation.passwordless.AzureJdbcPasswordlessProperties"
"sourceType": "com.azure.spring.cloud.autoconfigure.implementation.passwordless.properties.AzureJdbcPasswordlessProperties"
},
{
"name": "spring.datasource.azure.credential.username",
"type": "java.lang.String",
"description": "Username to use when performing username\/password authentication with Azure.",
"sourceType": "com.azure.spring.cloud.service.implementation.passwordless.AzureJdbcPasswordlessProperties"
"sourceType": "com.azure.spring.cloud.autoconfigure.implementation.passwordless.properties.AzureJdbcPasswordlessProperties"
},
{
"name": "spring.datasource.azure.credential.password",
"type": "java.lang.String",
"description": "Password to use when performing username\/password authentication with Azure.",
"sourceType": "com.azure.spring.cloud.service.implementation.passwordless.AzureJdbcPasswordlessProperties"
"sourceType": "com.azure.spring.cloud.autoconfigure.implementation.passwordless.properties.AzureJdbcPasswordlessProperties"
},
{
"name": "spring.datasource.azure.credential.managed-identity-enabled",
"type": "java.lang.Boolean",
"description": "Whether to enable managed identity to authenticate with Azure. If true and the client-id is set, will use the client ID as user assigned managed identity client ID.",
"sourceType": "com.azure.spring.cloud.service.implementation.passwordless.AzureJdbcPasswordlessProperties",
"sourceType": "com.azure.spring.cloud.autoconfigure.implementation.passwordless.properties.AzureJdbcPasswordlessProperties",
"defaultValue": false
},
{
"name": "spring.datasource.azure.profile.environment.active-directory-endpoint",
"type": "java.lang.String",
"description": "The Azure Active Directory endpoint to connect to.",
"sourceType": "com.azure.spring.cloud.service.implementation.passwordless.AzureJdbcPasswordlessProperties"
"sourceType": "com.azure.spring.cloud.autoconfigure.implementation.passwordless.properties.AzureJdbcPasswordlessProperties"
},
{
"name": "spring.datasource.azure.profile.tenant-id",
"type": "java.lang.String",
"description": "Tenant ID for Azure resources.",
"sourceType": "com.azure.spring.cloud.service.implementation.passwordless.AzureJdbcPasswordlessProperties"
"sourceType": "com.azure.spring.cloud.autoconfigure.implementation.passwordless.properties.AzureJdbcPasswordlessProperties"
},
{
"name": "spring.datasource.azure.profile.cloud-type",
"type": "java.lang.String",
"description": "Name of the Azure cloud to connect to. Supported types are: AZURE, AZURE_CHINA, AZURE_US_GOVERNMENT, OTHER. The default value is `AZURE`.",
"sourceType": "com.azure.spring.cloud.service.implementation.passwordless.AzureJdbcPasswordlessProperties"
"sourceType": "com.azure.spring.cloud.autoconfigure.implementation.passwordless.properties.AzureJdbcPasswordlessProperties"
},
{
"name": "spring.datasource.azure.passwordless-enabled",
"type": "java.lang.Boolean",
"description": "Whether to enable passwordless connections to Azure databases by using OAuth2 Azure Active Directory token credentials.",
"sourceType": "com.azure.spring.cloud.service.implementation.passwordless.AzureJdbcPasswordlessProperties",
"sourceType": "com.azure.spring.cloud.autoconfigure.implementation.passwordless.properties.AzureJdbcPasswordlessProperties",
"defaultValue": false
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import com.azure.spring.cloud.autoconfigure.implementation.context.AzureTokenCredentialAutoConfiguration;
import com.azure.spring.cloud.autoconfigure.implementation.context.properties.AzureGlobalProperties;
import com.azure.spring.cloud.service.implementation.identity.credential.provider.SpringTokenCredentialProvider;
import com.azure.spring.cloud.service.implementation.passwordless.AzureJdbcPasswordlessProperties;
import com.azure.spring.cloud.autoconfigure.implementation.passwordless.properties.AzureJdbcPasswordlessProperties;
import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.spring.cloud.core.implementation.properties;

import com.azure.identity.extensions.implementation.enums.AuthProperty;
import com.azure.spring.cloud.core.properties.PasswordlessProperties;

import java.util.Properties;
import java.util.function.BiConsumer;
import java.util.function.Function;

/**
* A mapping util used to convert a {@link PasswordlessProperties} instance to a {@link Properties} instance.
*/
public enum AzurePasswordlessPropertiesMapping {

/**
* Getter function and setter biConsumer for scopes.
*/
SCOPES(p -> p.getScopes(),
(p, s) -> p.setProperty(AuthProperty.SCOPES.getPropertyKey(), s)),

/**
* Getter function and setter biConsumer for clientCertificatePassword.
*/
CLIENT_CERTIFICATE_PASSWORD(p -> p.getCredential().getClientCertificatePassword(),
(p, s) -> p.setProperty(AuthProperty.CLIENT_CERTIFICATE_PASSWORD.getPropertyKey(), s)),

/**
* Getter function and setter biConsumer for clientCertificatePath.
*/
CLIENT_CERTIFICATE_PATH(p -> p.getCredential().getClientCertificatePath(),
(p, s) -> p.setProperty(AuthProperty.CLIENT_CERTIFICATE_PATH.getPropertyKey(), s)),

/**
* Getter function and setter biConsumer for clientId.
*/
CLIENT_ID(p -> p.getCredential().getClientId(),
(p, s) -> p.setProperty(AuthProperty.CLIENT_ID.getPropertyKey(), s)),

/**
* Getter function and setter biConsumer for clientSecret.
*/
CLIENT_SECRET(p -> p.getCredential().getClientSecret(),
(p, s) -> p.setProperty(AuthProperty.CLIENT_SECRET.getPropertyKey(), s)),

/**
* Getter function and setter biConsumer for managedIdentityEnabled.
*/
MANAGED_IDENTITY_ENABLED(p -> String.valueOf(p.getCredential().isManagedIdentityEnabled()),
(p, s) -> p.setProperty(AuthProperty.MANAGED_IDENTITY_ENABLED.getPropertyKey(), s)),

/**
* Getter function and setter biConsumer for password.
*/
PASSWORD(p -> p.getCredential().getPassword(),
(p, s) -> p.setProperty(AuthProperty.PASSWORD.getPropertyKey(), s)),

/**
* Getter function and setter biConsumer for username.
*/
USERNAME(p -> p.getCredential().getUsername(),
(p, s) -> p.setProperty(AuthProperty.USERNAME.getPropertyKey(), s)),

/**
* Getter function and setter biConsumer for tenantId.
*/
TENANT_ID(p -> p.getProfile().getTenantId(),
(p, s) -> p.setProperty(AuthProperty.TENANT_ID.getPropertyKey(), s)),

/**
* Getter function and setter biConsumer for authorityHost.
*/
AUTHORITY_HOST(p -> p.getProfile().getEnvironment().getActiveDirectoryEndpoint(),
(p, s) -> p.setProperty(AuthProperty.AUTHORITY_HOST.getPropertyKey(), s));

private Function<PasswordlessProperties, String> getter;
private BiConsumer<Properties, String> setter;

public Function<PasswordlessProperties, String> getGetter() {
return getter;
}

public BiConsumer<Properties, String> getSetter() {
return setter;
}

AzurePasswordlessPropertiesMapping(Function<PasswordlessProperties, String> getter, BiConsumer<Properties,
String> setter) {
this.getter = getter;
this.setter = setter;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@

package com.azure.spring.cloud.core.properties;

import com.azure.identity.extensions.implementation.enums.AuthProperty;
import com.azure.spring.cloud.core.implementation.properties.AzurePasswordlessPropertiesMapping;
import com.azure.spring.cloud.core.provider.AzureProfileOptionsProvider;
import com.azure.spring.cloud.core.provider.authentication.TokenCredentialOptionsProvider;

import java.util.Properties;
import java.util.function.BiConsumer;
import java.util.function.Function;

/**
* Unified properties for Azure passwordless clients.
Expand Down Expand Up @@ -51,87 +49,11 @@ public interface PasswordlessProperties extends TokenCredentialOptionsProvider,
default Properties toPasswordlessProperties() {
Properties target = new Properties();
for (AzurePasswordlessPropertiesMapping m : AzurePasswordlessPropertiesMapping.values()) {
if (m.getter.apply(this) != null) {
m.setter.accept(target, m.getter.apply(this));
if (m.getGetter().apply(this) != null) {
m.getSetter().accept(target, m.getGetter().apply(this));
}
}
return target;
}

/**
* A mapping util used to convert a {@link PasswordlessProperties} instance to a {@link Properties} instance.
*/
enum AzurePasswordlessPropertiesMapping {

/**
* Getter function and setter biConsumer for scopes.
*/
scopes(p -> p.getScopes(),
(p, s) -> p.setProperty(AuthProperty.SCOPES.getPropertyKey(), s)),

/**
* Getter function and setter biConsumer for clientCertificatePassword.
*/
clientCertificatePassword(p -> p.getCredential().getClientCertificatePassword(),
(p, s) -> p.setProperty(AuthProperty.CLIENT_CERTIFICATE_PASSWORD.getPropertyKey(), s)),

/**
* Getter function and setter biConsumer for clientCertificatePath.
*/
clientCertificatePath(p -> p.getCredential().getClientCertificatePath(),
(p, s) -> p.setProperty(AuthProperty.CLIENT_CERTIFICATE_PATH.getPropertyKey(), s)),

/**
* Getter function and setter biConsumer for clientId.
*/
clientId(p -> p.getCredential().getClientId(),
(p, s) -> p.setProperty(AuthProperty.CLIENT_ID.getPropertyKey(), s)),

/**
* Getter function and setter biConsumer for clientSecret.
*/
clientSecret(p -> p.getCredential().getClientSecret(),
(p, s) -> p.setProperty(AuthProperty.CLIENT_SECRET.getPropertyKey(), s)),

/**
* Getter function and setter biConsumer for managedIdentityEnabled.
*/
managedIdentityEnabled(p -> String.valueOf(p.getCredential().isManagedIdentityEnabled()),
(p, s) -> p.setProperty(AuthProperty.MANAGED_IDENTITY_ENABLED.getPropertyKey(), s)),

/**
* Getter function and setter biConsumer for password.
*/
password(p -> p.getCredential().getPassword(),
(p, s) -> p.setProperty(AuthProperty.PASSWORD.getPropertyKey(), s)),

/**
* Getter function and setter biConsumer for username.
*/
username(p -> p.getCredential().getUsername(),
(p, s) -> p.setProperty(AuthProperty.USERNAME.getPropertyKey(), s)),

/**
* Getter function and setter biConsumer for tenantId.
*/
tenantId(p -> p.getProfile().getTenantId(),
(p, s) -> p.setProperty(AuthProperty.TENANT_ID.getPropertyKey(), s)),

/**
* Getter function and setter biConsumer for authorityHost.
*/
authorityHost(p -> p.getProfile().getEnvironment().getActiveDirectoryEndpoint(),
(p, s) -> p.setProperty(AuthProperty.AUTHORITY_HOST.getPropertyKey(), s));

private Function<PasswordlessProperties, String> getter;
private BiConsumer<Properties, String> setter;

AzurePasswordlessPropertiesMapping(Function<PasswordlessProperties, String> getter, BiConsumer<Properties,
String> setter) {
this.getter = getter;
this.setter = setter;
}

}
}

Loading