Search in sources :

Example 1 with DefaultSensitiveStringCodec

use of org.apache.activemq.artemis.utils.DefaultSensitiveStringCodec in project activemq-artemis by apache.

the class FileConfigurationParserTest method testParsingDefaultServerConfigWithENCMaskedPwd.

@Test
public void testParsingDefaultServerConfigWithENCMaskedPwd() 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>ENC(5aec0780b12bf225a13ab70c6c76bc8e)</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");
    clusterPasswordPart = "<cluster-password>" + PasswordMaskingUtil.wrap(mask) + "</cluster-password>";
    configStr = firstPart + clusterPasswordPart + 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>" + PasswordMaskingUtil.wrap(mask) + "</cluster-password>";
    String codecPart = "<password-codec>" + "org.apache.activemq.artemis.utils.DefaultSensitiveStringCodec" + ";key=newkey</password-codec>";
    configStr = firstPart + clusterPasswordPart + codecPart + lastPart;
    config = parser.parseMainConfig(new ByteArrayInputStream(configStr.getBytes(StandardCharsets.UTF_8)));
    assertEquals("newpassword", config.getClusterPassword());
    configStr = firstPart + bridgePart + lastPart;
    config = parser.parseMainConfig(new ByteArrayInputStream(configStr.getBytes(StandardCharsets.UTF_8)));
    List<BridgeConfiguration> bridgeConfigs = config.getBridgeConfigurations();
    assertEquals(1, bridgeConfigs.size());
    BridgeConfiguration bconfig = bridgeConfigs.get(0);
    assertEquals("helloworld", bconfig.getPassword());
}
Also used : Configuration(org.apache.activemq.artemis.core.config.Configuration) SharedStoreMasterPolicyConfiguration(org.apache.activemq.artemis.core.config.ha.SharedStoreMasterPolicyConfiguration) ActiveMQDefaultConfiguration(org.apache.activemq.artemis.api.config.ActiveMQDefaultConfiguration) BridgeConfiguration(org.apache.activemq.artemis.core.config.BridgeConfiguration) WildcardConfiguration(org.apache.activemq.artemis.core.config.WildcardConfiguration) HAPolicyConfiguration(org.apache.activemq.artemis.core.config.HAPolicyConfiguration) ByteArrayInputStream(java.io.ByteArrayInputStream) HashMap(java.util.HashMap) BridgeConfiguration(org.apache.activemq.artemis.core.config.BridgeConfiguration) DefaultSensitiveStringCodec(org.apache.activemq.artemis.utils.DefaultSensitiveStringCodec) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) FileConfigurationParser(org.apache.activemq.artemis.core.deployers.impl.FileConfigurationParser) Test(org.junit.Test)

Example 2 with DefaultSensitiveStringCodec

use of org.apache.activemq.artemis.utils.DefaultSensitiveStringCodec in project activemq-artemis by apache.

the class ResourceAdapterTest method testMaskPassword.

@Test
public void testMaskPassword() throws Exception {
    ActiveMQResourceAdapter qResourceAdapter = new ActiveMQResourceAdapter();
    qResourceAdapter.setConnectorClassName(INVM_CONNECTOR_FACTORY);
    ActiveMQRATestBase.MyBootstrapContext ctx = new ActiveMQRATestBase.MyBootstrapContext();
    DefaultSensitiveStringCodec codec = new DefaultSensitiveStringCodec();
    String mask = codec.encode("helloworld");
    qResourceAdapter.setUseMaskedPassword(true);
    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 = (String) 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);
}
Also used : DefaultSensitiveStringCodec(org.apache.activemq.artemis.utils.DefaultSensitiveStringCodec) ActiveMQResourceAdapter(org.apache.activemq.artemis.ra.ActiveMQResourceAdapter) ActiveMQActivationSpec(org.apache.activemq.artemis.ra.inflow.ActiveMQActivationSpec) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 3 with DefaultSensitiveStringCodec

use of org.apache.activemq.artemis.utils.DefaultSensitiveStringCodec in project activemq-artemis by apache.

the class ResourceAdapterTest method testMaskPassword2ENC.

@Test
public void testMaskPassword2ENC() throws Exception {
    ActiveMQResourceAdapter qResourceAdapter = new ActiveMQResourceAdapter();
    qResourceAdapter.setConnectorClassName(INVM_CONNECTOR_FACTORY);
    ActiveMQRATestBase.MyBootstrapContext ctx = new ActiveMQRATestBase.MyBootstrapContext();
    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(PasswordMaskingUtil.wrap(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(PasswordMaskingUtil.wrap(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);
}
Also used : HashMap(java.util.HashMap) DefaultSensitiveStringCodec(org.apache.activemq.artemis.utils.DefaultSensitiveStringCodec) ActiveMQResourceAdapter(org.apache.activemq.artemis.ra.ActiveMQResourceAdapter) ActiveMQActivationSpec(org.apache.activemq.artemis.ra.inflow.ActiveMQActivationSpec) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 4 with DefaultSensitiveStringCodec

use of org.apache.activemq.artemis.utils.DefaultSensitiveStringCodec in project activemq-artemis by apache.

the class ResourceAdapterTest method testMaskPasswordENC.

@Test
public void testMaskPasswordENC() throws Exception {
    ActiveMQResourceAdapter qResourceAdapter = new ActiveMQResourceAdapter();
    qResourceAdapter.setConnectorClassName(INVM_CONNECTOR_FACTORY);
    ActiveMQRATestBase.MyBootstrapContext ctx = new ActiveMQRATestBase.MyBootstrapContext();
    DefaultSensitiveStringCodec codec = new DefaultSensitiveStringCodec();
    String mask = codec.encode("helloworld");
    qResourceAdapter.setPassword(PasswordMaskingUtil.wrap(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(PasswordMaskingUtil.wrap(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);
}
Also used : DefaultSensitiveStringCodec(org.apache.activemq.artemis.utils.DefaultSensitiveStringCodec) ActiveMQResourceAdapter(org.apache.activemq.artemis.ra.ActiveMQResourceAdapter) ActiveMQActivationSpec(org.apache.activemq.artemis.ra.inflow.ActiveMQActivationSpec) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 5 with DefaultSensitiveStringCodec

use of org.apache.activemq.artemis.utils.DefaultSensitiveStringCodec in project activemq-artemis by apache.

the class JMSBridgeTest method testMaskPassword.

@Test
public void testMaskPassword() throws Exception {
    JMSBridgeImpl bridge = null;
    Connection connSource = null;
    Connection connTarget = null;
    DefaultSensitiveStringCodec codec = new DefaultSensitiveStringCodec();
    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.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);
    }
}
Also used : MessageConsumer(javax.jms.MessageConsumer) ActiveMQMessage(org.apache.activemq.artemis.jms.client.ActiveMQMessage) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) JMSBridgeImpl(org.apache.activemq.artemis.jms.bridge.impl.JMSBridgeImpl) Connection(javax.jms.Connection) DefaultSensitiveStringCodec(org.apache.activemq.artemis.utils.DefaultSensitiveStringCodec) MessageProducer(javax.jms.MessageProducer) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session) Test(org.junit.Test)

Aggregations

DefaultSensitiveStringCodec (org.apache.activemq.artemis.utils.DefaultSensitiveStringCodec)9 Test (org.junit.Test)9 HashMap (java.util.HashMap)5 CountDownLatch (java.util.concurrent.CountDownLatch)4 ActiveMQResourceAdapter (org.apache.activemq.artemis.ra.ActiveMQResourceAdapter)4 ActiveMQActivationSpec (org.apache.activemq.artemis.ra.inflow.ActiveMQActivationSpec)4 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 Connection (javax.jms.Connection)2 Message (javax.jms.Message)2 MessageConsumer (javax.jms.MessageConsumer)2 MessageProducer (javax.jms.MessageProducer)2 Session (javax.jms.Session)2 TextMessage (javax.jms.TextMessage)2 ActiveMQDefaultConfiguration (org.apache.activemq.artemis.api.config.ActiveMQDefaultConfiguration)2 BridgeConfiguration (org.apache.activemq.artemis.core.config.BridgeConfiguration)2 Configuration (org.apache.activemq.artemis.core.config.Configuration)2 HAPolicyConfiguration (org.apache.activemq.artemis.core.config.HAPolicyConfiguration)2 WildcardConfiguration (org.apache.activemq.artemis.core.config.WildcardConfiguration)2 SharedStoreMasterPolicyConfiguration (org.apache.activemq.artemis.core.config.ha.SharedStoreMasterPolicyConfiguration)2