Search in sources :

Example 6 with DefaultSensitiveStringCodec

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);
    }
}
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) HashMap(java.util.HashMap) 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)

Example 7 with DefaultSensitiveStringCodec

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);
}
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 8 with DefaultSensitiveStringCodec

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);
}
Also used : Mask(org.apache.activemq.artemis.cli.commands.Mask) DefaultSensitiveStringCodec(org.apache.activemq.artemis.utils.DefaultSensitiveStringCodec) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Test(org.junit.Test)

Example 9 with DefaultSensitiveStringCodec

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());
}
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) 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)

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