-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support passwordless connections for JMS ServiceBus in Spring (#33489)
Support passwordless connections for JMS ServiceBus in Spring.
- Loading branch information
1 parent
31b4310
commit 0aa7f47
Showing
37 changed files
with
1,615 additions
and
135 deletions.
There are no files selected for viewing
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
43 changes: 43 additions & 0 deletions
43
.../autoconfigure/implementation/passwordless/AzurePasswordlessEnvironmentPostProcessor.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,43 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
package com.azure.spring.cloud.autoconfigure.implementation.passwordless; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.context.config.ConfigDataEnvironmentPostProcessor; | ||
import org.springframework.boot.env.EnvironmentPostProcessor; | ||
import org.springframework.core.Ordered; | ||
import org.springframework.core.env.ConfigurableEnvironment; | ||
import org.springframework.core.env.PropertiesPropertySource; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Properties; | ||
|
||
/** | ||
* Add properties to 'spring.cloud.function.ineligible-definitions' to filter ineligible functions that used by passwordless autoconfigurations. | ||
* | ||
* @since 4.7.0 | ||
*/ | ||
public class AzurePasswordlessEnvironmentPostProcessor implements EnvironmentPostProcessor, Ordered { | ||
|
||
/** | ||
* The order value of the {@link AzurePasswordlessEnvironmentPostProcessor}. | ||
*/ | ||
public static final int ORDER = ConfigDataEnvironmentPostProcessor.ORDER + 2; | ||
|
||
@Override | ||
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) { | ||
Properties properties = new Properties(); | ||
List<String> passwordlessCredentialSupplier = new ArrayList<>(); | ||
passwordlessCredentialSupplier.add("azureRedisCredentialSupplier"); | ||
passwordlessCredentialSupplier.add("azureServiceBusJmsCredentialSupplier"); | ||
properties.setProperty("spring.cloud.function.ineligible-definitions", String.join(",", passwordlessCredentialSupplier)); | ||
environment.getPropertySources().addLast(new PropertiesPropertySource("passwordless", properties)); | ||
} | ||
|
||
@Override | ||
public int getOrder() { | ||
return ORDER; | ||
} | ||
} |
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
37 changes: 37 additions & 0 deletions
37
...n/java/com/azure/spring/cloud/autoconfigure/jms/AzureServiceBusJmsCredentialSupplier.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,37 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
package com.azure.spring.cloud.autoconfigure.jms; | ||
|
||
import com.azure.identity.extensions.implementation.template.AzureAuthenticationTemplate; | ||
|
||
import java.util.Properties; | ||
import java.util.function.Supplier; | ||
|
||
/** | ||
* AzureServiceBusJmsCredentialSupplier that provides a String as the password to connect Azure ServiceBus. | ||
* | ||
* @since 4.7.0 | ||
*/ | ||
public class AzureServiceBusJmsCredentialSupplier implements Supplier<String> { | ||
|
||
private final AzureAuthenticationTemplate azureAuthenticationTemplate; | ||
|
||
/** | ||
* Create {@link AzureServiceBusJmsCredentialSupplier} instance. | ||
* @param properties properties to initialize AzureServiceBusJmsCredentialSupplier. | ||
*/ | ||
public AzureServiceBusJmsCredentialSupplier(Properties properties) { | ||
azureAuthenticationTemplate = new AzureAuthenticationTemplate(); | ||
azureAuthenticationTemplate.init(properties); | ||
} | ||
|
||
@Override | ||
public String get() { | ||
return azureAuthenticationTemplate.getTokenAsPassword(); | ||
} | ||
|
||
AzureServiceBusJmsCredentialSupplier(AzureAuthenticationTemplate azureAuthenticationTemplate) { | ||
this.azureAuthenticationTemplate = azureAuthenticationTemplate; | ||
} | ||
} |
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
40 changes: 40 additions & 0 deletions
40
...java/com/azure/spring/cloud/autoconfigure/jms/ServiceBusJmsPasswordlessConfiguration.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,40 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
package com.azure.spring.cloud.autoconfigure.jms; | ||
|
||
import com.azure.spring.cloud.autoconfigure.jms.properties.AzureServiceBusJmsProperties; | ||
import org.apache.qpid.jms.JmsConnectionExtensions; | ||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
/** | ||
* {@link EnableAutoConfiguration Auto-configuration} for Azure Service Bus JMS passwordless support. | ||
* | ||
* @since 4.7.0 | ||
*/ | ||
@Configuration(proxyBeanMethods = false) | ||
@ConditionalOnProperty(value = "spring.jms.servicebus.passwordless-enabled", havingValue = "true") | ||
class ServiceBusJmsPasswordlessConfiguration { | ||
|
||
@Bean | ||
@ConditionalOnMissingBean | ||
AzureServiceBusJmsCredentialSupplier azureServiceBusJmsCredentialSupplier(AzureServiceBusJmsProperties azureServiceBusJmsProperties) { | ||
return new AzureServiceBusJmsCredentialSupplier(azureServiceBusJmsProperties.toPasswordlessProperties()); | ||
} | ||
|
||
@Bean | ||
ServiceBusJmsConnectionFactoryCustomizer jmsAADAuthenticationCustomizer(AzureServiceBusJmsCredentialSupplier credentialSupplier) { | ||
return factory -> { | ||
factory.setExtension(JmsConnectionExtensions.USERNAME_OVERRIDE.toString(), (connection, uri) -> "$jwt"); | ||
factory.setExtension(JmsConnectionExtensions.PASSWORD_OVERRIDE.toString(), (connection, uri) -> | ||
credentialSupplier.get() | ||
); | ||
}; | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.