use of org.apache.activemq.artemis.utils.DefaultSensitiveStringCodec in project activemq-artemis by apache.
the class JMSBridgeTest method testPasswordCodec.
@Test
public void testPasswordCodec() throws Exception {
JMSBridgeImpl bridge = null;
Connection connSource = null;
Connection connTarget = null;
DefaultSensitiveStringCodec codec = new DefaultSensitiveStringCodec();
Map<String, String> prop = new HashMap<>();
prop.put("key", "bridgekey");
codec.init(prop);
String mask = (String) codec.encode("guest");
try {
final int NUM_MESSAGES = 10;
bridge = new JMSBridgeImpl(cff0, cff1, sourceQueueFactory, targetQueueFactory, "guest", mask, "guest", mask, null, 5000, 10, QualityOfServiceMode.AT_MOST_ONCE, 1, -1, null, null, false).setBridgeName("test-bridge");
bridge.setUseMaskedPassword(true);
bridge.setPasswordCodec(codec.getClass().getName() + ";key=bridgekey");
bridge.start();
connSource = cf0.createConnection();
Session sessSend = connSource.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer prod = sessSend.createProducer(sourceQueue);
for (int i = 0; i < NUM_MESSAGES; i++) {
TextMessage tm = sessSend.createTextMessage("message" + i);
prod.send(tm);
}
connTarget = cf1.createConnection();
Session sessRec = connTarget.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer cons = sessRec.createConsumer(targetQueue);
connTarget.start();
for (int i = 0; i < NUM_MESSAGES; i++) {
TextMessage tm = (TextMessage) cons.receive(10000);
Assert.assertNotNull(tm);
Assert.assertEquals("message" + i, tm.getText());
}
Message m = cons.receiveNoWait();
Assert.assertNull(m);
} finally {
if (connSource != null) {
connSource.close();
}
if (connTarget != null) {
connTarget.close();
}
if (bridge != null) {
bridge.stop();
}
removeAllMessages(sourceQueue.getQueueName(), 0);
}
}
use of org.apache.activemq.artemis.utils.DefaultSensitiveStringCodec in project activemq-artemis by apache.
the class ResourceAdapterTest method testMaskPassword2.
@Test
public void testMaskPassword2() throws Exception {
ActiveMQResourceAdapter qResourceAdapter = new ActiveMQResourceAdapter();
qResourceAdapter.setConnectorClassName(INVM_CONNECTOR_FACTORY);
ActiveMQRATestBase.MyBootstrapContext ctx = new ActiveMQRATestBase.MyBootstrapContext();
qResourceAdapter.setUseMaskedPassword(true);
qResourceAdapter.setPasswordCodec(DefaultSensitiveStringCodec.class.getName() + ";key=anotherkey");
DefaultSensitiveStringCodec codec = new DefaultSensitiveStringCodec();
Map<String, String> prop = new HashMap<>();
prop.put("key", "anotherkey");
codec.init(prop);
String mask = codec.encode("helloworld");
qResourceAdapter.setPassword(mask);
qResourceAdapter.start(ctx);
assertEquals("helloworld", qResourceAdapter.getPassword());
ActiveMQActivationSpec spec = new ActiveMQActivationSpec();
spec.setResourceAdapter(qResourceAdapter);
spec.setUseJNDI(false);
spec.setDestinationType("javax.jms.Queue");
spec.setDestination(MDBQUEUE);
mask = codec.encode("mdbpassword");
spec.setPassword(mask);
qResourceAdapter.setConnectorClassName(INVM_CONNECTOR_FACTORY);
CountDownLatch latch = new CountDownLatch(1);
DummyMessageEndpoint endpoint = new DummyMessageEndpoint(latch);
DummyMessageEndpointFactory endpointFactory = new DummyMessageEndpointFactory(endpoint, false);
qResourceAdapter.endpointActivation(endpointFactory, spec);
assertEquals("mdbpassword", spec.getPassword());
qResourceAdapter.stop();
assertTrue(endpoint.released);
}
use of org.apache.activemq.artemis.utils.DefaultSensitiveStringCodec in project activemq-artemis by apache.
the class ArtemisTest method testMaskCommand.
@Test
public void testMaskCommand() throws Exception {
String password1 = "password";
String encrypt1 = "3a34fd21b82bf2a822fa49a8d8fa115d";
String newKey = "artemisfun";
String encrypt2 = "-2b8e3b47950b9b481a6f3100968e42e9";
TestActionContext context = new TestActionContext();
Mask mask = new Mask();
mask.setPassword(password1);
String result = (String) mask.execute(context);
System.out.println(context.getStdout());
assertEquals(encrypt1, result);
context = new TestActionContext();
mask = new Mask();
mask.setPassword(password1);
mask.setHash(true);
result = (String) mask.execute(context);
System.out.println(context.getStdout());
DefaultSensitiveStringCodec codec = mask.getCodec();
codec.verify(password1.toCharArray(), result);
context = new TestActionContext();
mask = new Mask();
mask.setPassword(password1);
mask.setKey(newKey);
result = (String) mask.execute(context);
System.out.println(context.getStdout());
assertEquals(encrypt2, result);
}
use of org.apache.activemq.artemis.utils.DefaultSensitiveStringCodec in project activemq-artemis by apache.
the class FileConfigurationParserTest method testParsingDefaultServerConfig.
@Test
public void testParsingDefaultServerConfig() throws Exception {
FileConfigurationParser parser = new FileConfigurationParser();
String configStr = firstPart + lastPart;
ByteArrayInputStream input = new ByteArrayInputStream(configStr.getBytes(StandardCharsets.UTF_8));
Configuration config = parser.parseMainConfig(input);
String clusterPassword = config.getClusterPassword();
assertEquals(ActiveMQDefaultConfiguration.getDefaultClusterPassword(), clusterPassword);
// if we add cluster-password, it should be default plain text
String clusterPasswordPart = "<cluster-password>helloworld</cluster-password>";
configStr = firstPart + clusterPasswordPart + lastPart;
config = parser.parseMainConfig(new ByteArrayInputStream(configStr.getBytes(StandardCharsets.UTF_8)));
assertEquals("helloworld", config.getClusterPassword());
// if we add mask, it should be able to decode correctly
DefaultSensitiveStringCodec codec = new DefaultSensitiveStringCodec();
String mask = (String) codec.encode("helloworld");
String maskPasswordPart = "<mask-password>true</mask-password>";
clusterPasswordPart = "<cluster-password>" + mask + "</cluster-password>";
configStr = firstPart + clusterPasswordPart + maskPasswordPart + lastPart;
config = parser.parseMainConfig(new ByteArrayInputStream(configStr.getBytes(StandardCharsets.UTF_8)));
assertEquals("helloworld", config.getClusterPassword());
// if we change key, it should be able to decode correctly
codec = new DefaultSensitiveStringCodec();
Map<String, String> prop = new HashMap<>();
prop.put("key", "newkey");
codec.init(prop);
mask = (String) codec.encode("newpassword");
clusterPasswordPart = "<cluster-password>" + mask + "</cluster-password>";
String codecPart = "<password-codec>" + "org.apache.activemq.artemis.utils.DefaultSensitiveStringCodec" + ";key=newkey</password-codec>";
configStr = firstPart + clusterPasswordPart + maskPasswordPart + codecPart + lastPart;
config = parser.parseMainConfig(new ByteArrayInputStream(configStr.getBytes(StandardCharsets.UTF_8)));
assertEquals("newpassword", config.getClusterPassword());
}
Aggregations