Last active
July 12, 2024 14:39
-
-
Save kell05/e9124c5b985526310569fa1d34592a83 to your computer and use it in GitHub Desktop.
proxy
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
import com.azure.spring.cloud.core.properties.AzureProperties; | |
import com.azure.spring.cloud.stream.binder.eventhubs.config.EventHubsBinderConfiguration; | |
import com.azure.spring.cloud.stream.binder.eventhubs.properties.EventHubsBinderConfigurationProperties; | |
import com.azure.spring.cloud.stream.binder.eventhubs.properties.EventHubsExtendedBindingProperties; | |
import com.azure.core.amqp.AmqpTransportType; | |
import com.azure.core.amqp.ProxyOptions; | |
import org.springframework.boot.context.properties.ConfigurationProperties; | |
import org.springframework.context.annotation.Bean; | |
import org.springframework.context.annotation.Configuration; | |
import org.springframework.context.annotation.Import; | |
import java.net.Authenticator; | |
import java.net.PasswordAuthentication; | |
@Configuration | |
@Import(EventHubsBinderConfiguration.class) | |
public class EventHubsConfig { | |
@Bean | |
@ConfigurationProperties(prefix = "spring.cloud.azure.eventhubs") | |
public AzureProperties azureProperties() { | |
AzureProperties properties = new AzureProperties(); | |
properties.setNamespace("your-eventhubs-namespace"); | |
// Set other properties as needed | |
return properties; | |
} | |
@Bean | |
@ConfigurationProperties(prefix = "spring.cloud.stream.eventhubs.binder") | |
public EventHubsBinderConfigurationProperties configurationProperties(AzureProperties azureProperties) { | |
EventHubsBinderConfigurationProperties properties = new EventHubsBinderConfigurationProperties(azureProperties); | |
properties.setTransportType(AmqpTransportType.AMQP_WEB_SOCKETS); | |
properties.setProxyOptions(createKerberosAuthenticatedProxy()); | |
return properties; | |
} | |
@Bean | |
@ConfigurationProperties(prefix = "spring.cloud.stream.eventhubs.bindings") | |
public EventHubsExtendedBindingProperties bindingProperties() { | |
return new EventHubsExtendedBindingProperties(); | |
} | |
private ProxyOptions createKerberosAuthenticatedProxy() { | |
Authenticator.setDefault(new Authenticator() { | |
@Override | |
protected PasswordAuthentication getPasswordAuthentication() { | |
if (getRequestorType() == RequestorType.PROXY) { | |
return new PasswordAuthentication("", "".toCharArray()); | |
} | |
return null; | |
} | |
}); | |
System.setProperty("http.proxyHost", "your_proxy_host"); | |
System.setProperty("http.proxyPort", "your_proxy_port"); | |
System.setProperty("java.security.auth.login.config", "/path/to/jaas.conf"); | |
System.setProperty("javax.security.auth.useSubjectCredsOnly", "false"); | |
System.setProperty("sun.security.krb5.debug", "true"); // For debugging | |
return ProxyOptions.SYSTEM_DEFAULTS; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment