Add secured connection support to Artemis

This commit aligns the feature introduced in gh-6071 to Artemis.

Closes gh-6179
pull/6176/merge
Stephane Nicoll 9 years ago
parent 731d326799
commit a273d8d0c8

@ -31,6 +31,7 @@ import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
import org.springframework.beans.factory.ListableBeanFactory;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.StringUtils;
/**
* Factory to create an Artemis {@link ActiveMQConnectionFactory} instance from properties
@ -130,8 +131,14 @@ class ArtemisConnectionFactoryFactory {
NettyConnectorFactory.class.getName(), params);
Constructor<T> constructor = factoryClass.getConstructor(boolean.class,
TransportConfiguration[].class);
return constructor.newInstance(false,
new TransportConfiguration[] { transportConfiguration });
T connectionFactory = constructor.newInstance(false,
new TransportConfiguration[] {transportConfiguration});
String user = this.properties.getUser();
if (StringUtils.hasText(user)) {
connectionFactory.setUser(user);
connectionFactory.setPassword(this.properties.getPassword());
}
return connectionFactory;
}
}

@ -1,5 +1,5 @@
/*
* Copyright 2012-2015 the original author or authors.
* Copyright 2012-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -51,6 +51,16 @@ public class ArtemisProperties {
*/
private int port = 61616;
/**
* Login user of the broker.
*/
private String user;
/**
* Login password of the broker.
*/
private String password;
private final Embedded embedded = new Embedded();
public ArtemisMode getMode() {
@ -77,6 +87,22 @@ public class ArtemisProperties {
this.port = port;
}
public String getUser() {
return this.user;
}
public void setUser(String user) {
this.user = user;
}
public String getPassword() {
return this.password;
}
public void setPassword(String password) {
this.password = password;
}
public Embedded getEmbedded() {
return this.embedded;
}

@ -84,6 +84,8 @@ public class ArtemisAutoConfigurationTests {
.getBean(ActiveMQConnectionFactory.class);
assertThat(connectionFactory).isEqualTo(jmsTemplate.getConnectionFactory());
assertNettyConnectionFactory(connectionFactory, "localhost", 61616);
assertThat(connectionFactory.getUser()).isNull();
assertThat(connectionFactory.getPassword()).isNull();
}
@Test
@ -95,6 +97,19 @@ public class ArtemisAutoConfigurationTests {
assertNettyConnectionFactory(connectionFactory, "192.168.1.144", 9876);
}
@Test
public void nativeConnectionFactoryCredentials() {
load(EmptyConfiguration.class, "spring.artemis.mode:native",
"spring.artemis.user:user", "spring.artemis.password:secret");
JmsTemplate jmsTemplate = this.context.getBean(JmsTemplate.class);
ActiveMQConnectionFactory connectionFactory = this.context
.getBean(ActiveMQConnectionFactory.class);
assertThat(connectionFactory).isEqualTo(jmsTemplate.getConnectionFactory());
assertNettyConnectionFactory(connectionFactory, "localhost", 61616);
assertThat(connectionFactory.getUser()).isEqualTo("user");
assertThat(connectionFactory.getPassword()).isEqualTo("secret");
}
@Test
public void embeddedConnectionFactory() {
load(EmptyConfiguration.class, "spring.artemis.mode:embedded");

@ -829,7 +829,9 @@ content into your application; rather pick only the properties that you need.
spring.artemis.embedded.topics= # Comma-separated list of topics to create on startup.
spring.artemis.host=localhost # Artemis broker host.
spring.artemis.mode= # Artemis deployment mode, auto-detected by default. Can be explicitly set to "native" or "embedded".
spring.artemis.password= # Login password of the broker.
spring.artemis.port=61616 # Artemis broker port.
spring.artemis.user= # Login user of the broker.
# SPRING BATCH ({sc-spring-boot-autoconfigure}/batch/BatchProperties.{sc-ext}[BatchProperties])
spring.batch.initializer.enabled=true # Create the required batch tables on startup if necessary.

Loading…
Cancel
Save