Search in sources :

Example 1 with FileConfigurationParser

use of org.apache.activemq.artemis.core.deployers.impl.FileConfigurationParser in project activemq-artemis by apache.

the class FileConfiguration method parse.

@Override
public void parse(Element config, URL url) throws Exception {
    FileConfigurationParser parser = new FileConfigurationParser();
    // https://jira.jboss.org/browse/HORNETQ-478 - We only want to validate AIO when
    // starting the server
    // and we don't want to do it when deploying activemq-queues.xml which uses the same parser and XML format
    parser.setValidateAIO(true);
    parser.parseMainConfig(config, this);
    setConfigurationUrl(url);
    parseSystemProperties();
    parsed = true;
}
Also used : FileConfigurationParser(org.apache.activemq.artemis.core.deployers.impl.FileConfigurationParser)

Example 2 with FileConfigurationParser

use of org.apache.activemq.artemis.core.deployers.impl.FileConfigurationParser 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 3 with FileConfigurationParser

use of org.apache.activemq.artemis.core.deployers.impl.FileConfigurationParser 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)

Example 4 with FileConfigurationParser

use of org.apache.activemq.artemis.core.deployers.impl.FileConfigurationParser in project activemq-artemis by apache.

the class FileConfigurationParserTest method testParsingClusterConnectionURIs.

@Test
public void testParsingClusterConnectionURIs() throws Exception {
    FileConfigurationParser parser = new FileConfigurationParser();
    String configStr = firstPart + "<cluster-connections>\n" + "   <cluster-connection-uri name=\"my-cluster\" address=\"multicast://my-discovery-group?messageLoadBalancingType=STRICT;retryInterval=333;connectorName=netty-connector;maxHops=1\"/>\n" + "</cluster-connections>\n" + lastPart;
    ByteArrayInputStream input = new ByteArrayInputStream(configStr.getBytes(StandardCharsets.UTF_8));
    Configuration config = parser.parseMainConfig(input);
    Assert.assertEquals(1, config.getClusterConfigurations().size());
    Assert.assertEquals("my-discovery-group", config.getClusterConfigurations().get(0).getDiscoveryGroupName());
    Assert.assertEquals(333, config.getClusterConfigurations().get(0).getRetryInterval());
}
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) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) FileConfigurationParser(org.apache.activemq.artemis.core.deployers.impl.FileConfigurationParser) Test(org.junit.Test)

Example 5 with FileConfigurationParser

use of org.apache.activemq.artemis.core.deployers.impl.FileConfigurationParser in project activemq-artemis by apache.

the class FileConfigurationParserTest method testParsingHaSharedStoreWaitForActivation.

@Test
public void testParsingHaSharedStoreWaitForActivation() throws Exception {
    FileConfigurationParser parser = new FileConfigurationParser();
    String configStr = firstPart + "<ha-policy><shared-store><master><wait-for-activation>false</wait-for-activation></master></shared-store></ha-policy>" + lastPart;
    ByteArrayInputStream input = new ByteArrayInputStream(configStr.getBytes(StandardCharsets.UTF_8));
    Configuration config = parser.parseMainConfig(input);
    HAPolicyConfiguration haConfig = config.getHAPolicyConfiguration();
    assertTrue(haConfig instanceof SharedStoreMasterPolicyConfiguration);
    SharedStoreMasterPolicyConfiguration masterConfig = (SharedStoreMasterPolicyConfiguration) haConfig;
    assertFalse(masterConfig.isWaitForActivation());
}
Also used : HAPolicyConfiguration(org.apache.activemq.artemis.core.config.HAPolicyConfiguration) 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) SharedStoreMasterPolicyConfiguration(org.apache.activemq.artemis.core.config.ha.SharedStoreMasterPolicyConfiguration) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) FileConfigurationParser(org.apache.activemq.artemis.core.deployers.impl.FileConfigurationParser) Test(org.junit.Test)

Aggregations

FileConfigurationParser (org.apache.activemq.artemis.core.deployers.impl.FileConfigurationParser)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 Test (org.junit.Test)6 ActiveMQDefaultConfiguration (org.apache.activemq.artemis.api.config.ActiveMQDefaultConfiguration)5 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)5 BridgeConfiguration (org.apache.activemq.artemis.core.config.BridgeConfiguration)5 Configuration (org.apache.activemq.artemis.core.config.Configuration)5 HAPolicyConfiguration (org.apache.activemq.artemis.core.config.HAPolicyConfiguration)5 WildcardConfiguration (org.apache.activemq.artemis.core.config.WildcardConfiguration)5 SharedStoreMasterPolicyConfiguration (org.apache.activemq.artemis.core.config.ha.SharedStoreMasterPolicyConfiguration)5 HashMap (java.util.HashMap)2 DefaultSensitiveStringCodec (org.apache.activemq.artemis.utils.DefaultSensitiveStringCodec)2