org.apache.activemq.artemis.core.server.ActiveMQServer Java Examples

The following examples show how to use org.apache.activemq.artemis.core.server.ActiveMQServer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SecurityTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateDurableQueueWithRole() throws Exception {
   ActiveMQServer server = createServer();
   server.start();
   HierarchicalRepository<Set<Role>> securityRepository = server.getSecurityRepository();
   ActiveMQJAASSecurityManager securityManager = (ActiveMQJAASSecurityManager) server.getSecurityManager();
   securityManager.getConfiguration().addUser("auser", "pass");
   Role role = new Role("arole", false, false, true, false, false, false, false, false, true, false);
   Set<Role> roles = new HashSet<>();
   roles.add(role);
   securityRepository.addMatch(SecurityTest.addressA, roles);
   securityManager.getConfiguration().addRole("auser", "arole");
   ClientSessionFactory cf = createSessionFactory(locator);
   ClientSession session = cf.createSession("auser", "pass", false, true, true, false, -1);
   session.createQueue(new QueueConfiguration(SecurityTest.queueA).setAddress(SecurityTest.addressA));
   session.close();
}
 
Example #2
Source File: ReconnectTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
private ServerSession[] countMetadata(ActiveMQServer server, String parameter, int expected) throws Exception {
   List<ServerSession> sessionList = new LinkedList<>();

   for (int i = 0; i < 10 && sessionList.size() != expected; i++) {
      sessionList.clear();
      for (ServerSession sess : server.getSessions()) {
         if (sess.getMetaData(parameter) != null) {
            sessionList.add(sess);
         }
      }

      if (sessionList.size() != expected) {
         Thread.sleep(100);
      }
   }

   return sessionList.toArray(new ServerSession[sessionList.size()]);
}
 
Example #3
Source File: FederatedQueue.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
public FederatedQueue(Federation federation, FederationQueuePolicyConfiguration config, ActiveMQServer server, FederationUpstream federationUpstream) throws ActiveMQException {
   super(federation, server, federationUpstream);
   Objects.requireNonNull(config.getName());
   this.config = config;
   this.priorityAdjustment = federationUpstream.getPriorityAdjustment() + (config.getPriorityAdjustment() == null ? -1 : config.getPriorityAdjustment());
   String metaDataFilterString = config.isIncludeFederated() ? null : "hyphenated_props:" + FederatedQueueConsumer.FEDERATION_NAME +  " IS NOT NULL";
   metaDataFilter = FilterImpl.createFilter(metaDataFilterString);
   if (config.getIncludes().isEmpty()) {
      includes = Collections.emptySet();
   } else {
      includes = new HashSet<>(config.getIncludes().size());
      for (FederationQueuePolicyConfiguration.Matcher include : config.getIncludes()) {
         includes.add(new Matcher(include, wildcardConfiguration));
      }
   }

   if (config.getExcludes().isEmpty()) {
      excludes = Collections.emptySet();
   } else {
      excludes = new HashSet<>(config.getExcludes().size());
      for (FederationQueuePolicyConfiguration.Matcher exclude : config.getExcludes()) {
         excludes.add(new Matcher(exclude, wildcardConfiguration));
      }
   }
}
 
Example #4
Source File: HornetQProtocolManagerFactory.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Override
public ProtocolManager createProtocolManager(final ActiveMQServer server,
                                             final Map<String, Object> parameters,
                                             final List<BaseInterceptor> incomingInterceptors,
                                             List<BaseInterceptor> outgoingInterceptors) throws Exception {

   List<Interceptor> hqIncoming = filterInterceptors(incomingInterceptors);
   List<Interceptor> hqOutgoing = filterInterceptors(outgoingInterceptors);

   hqIncoming.add(new HQPropertiesConversionInterceptor(true));
   hqIncoming.add(new HQFilterConversionInterceptor());
   hqOutgoing.add(new HQPropertiesConversionInterceptor(false));

   stripPasswordParameters(parameters);
   return BeanSupport.setData(new HornetQProtocolManager(this, server, hqIncoming, hqOutgoing), parameters);
}
 
Example #5
Source File: StompWebSocketTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
/**
 * @return
 * @throws Exception
 */
@Override
protected ActiveMQServer createServer() throws Exception {
   Map<String, Object> params = new HashMap<>();
   params.put(TransportConstants.PROTOCOLS_PROP_NAME, StompProtocolManagerFactory.STOMP_PROTOCOL_NAME);
   params.put(TransportConstants.PORT_PROP_NAME, TransportConstants.DEFAULT_STOMP_PORT + 1);
   TransportConfiguration stompTransport = new TransportConfiguration(NettyAcceptorFactory.class.getName(), params);

   Configuration config = createBasicConfig()
      .addAcceptorConfiguration(stompTransport)
      .addAcceptorConfiguration(new TransportConfiguration(InVMAcceptorFactory.class.getName()))
      .setPersistenceEnabled(isPersistenceEnabled())
      .addQueueConfiguration(new QueueConfiguration(getQueueName())
                                .setDurable(false));

   server = addServer(ActiveMQServers.newActiveMQServer(config));
   return server;
}
 
Example #6
Source File: ClusterTestBase.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
protected void setupDiscoveryClusterConnection(final String name,
                                               final int node,
                                               final String discoveryGroupName,
                                               final String address,
                                               final MessageLoadBalancingType messageLoadBalancingType,
                                               final int maxHops,
                                               final boolean netty) {
   ActiveMQServer server = servers[node];

   if (server == null) {
      throw new IllegalStateException("No server at node " + node);
   }

   TransportConfiguration connectorConfig = createTransportConfiguration(netty, false, generateParams(node, netty));
   server.getConfiguration().getConnectorConfigurations().put(name, connectorConfig);
   Configuration config = server.getConfiguration();
   ClusterConnectionConfiguration clusterConf = new ClusterConnectionConfiguration().setName(name).setAddress(address).setConnectorName(name).setRetryInterval(100).setDuplicateDetection(true).setMessageLoadBalancingType(messageLoadBalancingType).setMaxHops(maxHops).setConfirmationWindowSize(1024).setDiscoveryGroupName(discoveryGroupName);
   List<ClusterConnectionConfiguration> clusterConfs = config.getClusterConfigurations();

   clusterConfs.add(clusterConf);
}
 
Example #7
Source File: ArtemisTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Test
public void testMissingUserFileViaManagement() throws Exception {
   Run.setEmbedded(true);
   File instance1 = new File(temporaryFolder.getRoot(), "instance_user");
   System.setProperty("java.security.auth.login.config", instance1.getAbsolutePath() + "/etc/login.config");
   Artemis.main("create", instance1.getAbsolutePath(), "--silent", "--no-autotune", "--no-web", "--no-amqp-acceptor", "--no-mqtt-acceptor", "--no-stomp-acceptor", "--no-hornetq-acceptor");
   System.setProperty("artemis.instance", instance1.getAbsolutePath());
   Object result = Artemis.internalExecute("run");
   ActiveMQServer activeMQServer = ((Pair<ManagementContext, ActiveMQServer>)result).getB();
   ActiveMQServerControl activeMQServerControl = activeMQServer.getActiveMQServerControl();

   File userFile = new File(instance1.getAbsolutePath() + "/etc/artemis-users.properties");
   userFile.delete();
   //      File roleFile = new File(instance1.getAbsolutePath() + "/etc/artemis-roles.properties");

   try {
      activeMQServerControl.listUser("");
      fail();
   } catch (ActiveMQIllegalStateException expected) {
   }

   stopServer();
}
 
Example #8
Source File: ActiveMQTestBase.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
protected void waitForServerToStart(ActiveMQServer server, boolean activation) throws InterruptedException {
   if (server == null)
      return;
   final long wait = 5000;
   long timetowait = System.currentTimeMillis() + wait;
   while (!server.isStarted() && System.currentTimeMillis() < timetowait) {
      Thread.sleep(50);
   }

   if (!server.isStarted()) {
      baseLog.info(threadDump("Server didn't start"));
      fail("server didn't start: " + server);
   }

   if (activation) {
      if (!server.getHAPolicy().isBackup()) {
         if (!server.waitForActivation(wait, TimeUnit.MILLISECONDS))
            fail("Server didn't initialize: " + server);
      }
   }
}
 
Example #9
Source File: ArtemisBrokerBase.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
protected final ActiveMQServer createServer(final boolean realFiles,
                                            final Configuration configuration,
                                            final int pageSize,
                                            final int maxAddressSize,
                                            final AddressFullMessagePolicy fullPolicy,
                                            final Map<String, AddressSettings> settings) {
   ActiveMQServer server = ActiveMQServers.newActiveMQServer(configuration, realFiles);
   if (settings != null) {
      for (Map.Entry<String, AddressSettings> setting : settings.entrySet()) {
         server.getAddressSettingsRepository().addMatch(setting.getKey(), setting.getValue());
      }
   }

   AddressSettings defaultSetting = new AddressSettings();
   defaultSetting.setPageSizeBytes(pageSize);
   defaultSetting.setMaxSizeBytes(maxAddressSize);
   defaultSetting.setAddressFullMessagePolicy(fullPolicy);

   server.getAddressSettingsRepository().addMatch("#", defaultSetting);

   return server;
}
 
Example #10
Source File: RetryCLIClientIDTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Test
public void testWrongUserAndPass() throws Exception {
   try {
      Run.setEmbedded(true);
      File instance1 = new File(temporaryFolder.getRoot(), "instance_user");
      System.setProperty("java.security.auth.login.config", instance1.getAbsolutePath() + "/etc/login.config");
      Artemis.main("create", instance1.getAbsolutePath(), "--silent", "--no-autotune", "--no-web", "--no-amqp-acceptor", "--no-mqtt-acceptor", "--no-stomp-acceptor", "--no-hornetq-acceptor", "--user", "dumb", "--password", "dumber", "--require-login");
      System.setProperty("artemis.instance", instance1.getAbsolutePath());
      Object result = Artemis.internalExecute("run");
      ActiveMQServer activeMQServer = ((Pair<ManagementContext, ActiveMQServer>) result).getB();
      ActiveMQServerControl activeMQServerControl = activeMQServer.getActiveMQServerControl();

      ConnectionTest test = new ConnectionTest();
      test.setSilentInput(true);
      test.setClientID("someClientID");
      ActiveMQConnectionFactory cf = test.newCF();
      Assert.assertEquals("someClientID", cf.getClientID());

   } finally {
      stopServer();
   }
}
 
Example #11
Source File: SecurityTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Test
public void testDeleteDurableQueueWithRole() throws Exception {
   ActiveMQServer server = createServer();
   server.start();
   HierarchicalRepository<Set<Role>> securityRepository = server.getSecurityRepository();
   ActiveMQJAASSecurityManager securityManager = (ActiveMQJAASSecurityManager) server.getSecurityManager();
   securityManager.getConfiguration().addUser("auser", "pass");
   Role role = new Role("arole", false, false, true, true, false, false, false, false, true, true);
   Set<Role> roles = new HashSet<>();
   roles.add(role);
   securityRepository.addMatch(SecurityTest.addressA, roles);
   securityManager.getConfiguration().addRole("auser", "arole");
   ClientSessionFactory cf = createSessionFactory(locator);
   ClientSession session = cf.createSession("auser", "pass", false, true, true, false, -1);
   session.createQueue(new QueueConfiguration(SecurityTest.queueA).setAddress(SecurityTest.addressA));
   session.deleteQueue(SecurityTest.queueA);
   session.close();
}
 
Example #12
Source File: SecurityTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Test
public void testDeleteDurableQueueWithoutRole() throws Exception {
   ActiveMQServer server = createServer();
   server.start();
   HierarchicalRepository<Set<Role>> securityRepository = server.getSecurityRepository();
   ActiveMQJAASSecurityManager securityManager = (ActiveMQJAASSecurityManager) server.getSecurityManager();
   securityManager.getConfiguration().addUser("auser", "pass");
   Role role = new Role("arole", false, false, true, false, false, false, false, false, true, false);
   Set<Role> roles = new HashSet<>();
   roles.add(role);
   securityRepository.addMatch(SecurityTest.addressA, roles);
   securityManager.getConfiguration().addRole("auser", "arole");
   ClientSessionFactory cf = createSessionFactory(locator);
   ClientSession session = cf.createSession("auser", "pass", false, true, true, false, -1);
   session.createQueue(new QueueConfiguration(SecurityTest.queueA).setAddress(SecurityTest.addressA));
   try {
      session.deleteQueue(SecurityTest.queueA);
      Assert.fail("should throw exception");
   } catch (ActiveMQSecurityException se) {
      //ok
   } catch (ActiveMQException e) {
      fail("Invalid Exception type:" + e.getType());
   }
   session.close();
}
 
Example #13
Source File: AmqpClientTestSupport.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
protected void configureAddressPolicy(ActiveMQServer server) {
   // Address configuration
   AddressSettings addressSettings = new AddressSettings();

   addressSettings.setAddressFullMessagePolicy(AddressFullMessagePolicy.PAGE);
   addressSettings.setAutoCreateQueues(isAutoCreateQueues());
   addressSettings.setAutoCreateAddresses(isAutoCreateAddresses());
   addressSettings.setDeadLetterAddress(SimpleString.toSimpleString(getDeadLetterAddress()));
   addressSettings.setExpiryAddress(SimpleString.toSimpleString(getDeadLetterAddress()));

   server.getConfiguration().getAddressesSettings().put("#", addressSettings);
   Set<TransportConfiguration> acceptors = server.getConfiguration().getAcceptorConfigurations();
   for (TransportConfiguration tc : acceptors) {
      if (tc.getName().equals("netty-acceptor")) {
         tc.getExtraParams().put("anycastPrefix", "anycast://");
         tc.getExtraParams().put("multicastPrefix", "multicast://");
      }
   }
}
 
Example #14
Source File: JMSMessageGroupsTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Override
protected void configureAddressPolicy(ActiveMQServer server) {
   super.configureAddressPolicy(server);

   AddressSettings addressSettings = new AddressSettings();

   addressSettings.setAddressFullMessagePolicy(AddressFullMessagePolicy.PAGE);
   addressSettings.setAutoCreateQueues(isAutoCreateQueues());
   addressSettings.setAutoCreateAddresses(isAutoCreateAddresses());
   addressSettings.setDeadLetterAddress(SimpleString.toSimpleString(getDeadLetterAddress()));
   addressSettings.setExpiryAddress(SimpleString.toSimpleString(getDeadLetterAddress()));
   addressSettings.setDefaultGroupFirstKey(SimpleString.toSimpleString("JMSXFirstInGroupID"));


   server.getConfiguration().getAddressesSettings().put("GroupFirst.#", addressSettings);
}
 
Example #15
Source File: SecureConfigurationTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
protected ActiveMQServer getActiveMQServer(String brokerConfig) throws Exception {
   FileConfiguration fc = new FileConfiguration();
   FileJMSConfiguration fileConfiguration = new FileJMSConfiguration();
   FileDeploymentManager deploymentManager = new FileDeploymentManager(brokerConfig);
   deploymentManager.addDeployable(fc);
   deploymentManager.addDeployable(fileConfiguration);
   deploymentManager.readConfiguration();

   SecurityConfiguration securityConfiguration = new SecurityConfiguration();
   securityConfiguration.addUser("a", "a");
   securityConfiguration.addRole("a", "a");

   securityConfiguration.addUser("b", "b");
   securityConfiguration.addRole("b", "b");

   securityConfiguration.addUser("c", "c");
   securityConfiguration.addRole("c", "c");

   ActiveMQJAASSecurityManager sm = new ActiveMQJAASSecurityManager(InVMLoginModule.class.getName(), securityConfiguration);

   return addServer(new ActiveMQServerImpl(fc, sm));
}
 
Example #16
Source File: SecurityTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateTempQueueWithoutRole() throws Exception {
   ActiveMQServer server = createServer();

   server.start();
   HierarchicalRepository<Set<Role>> securityRepository = server.getSecurityRepository();
   ActiveMQJAASSecurityManager securityManager = (ActiveMQJAASSecurityManager) server.getSecurityManager();
   securityManager.getConfiguration().addUser("auser", "pass");
   Role role = new Role("arole", false, false, false, false, false, false, false, false, false, false);
   Set<Role> roles = new HashSet<>();
   roles.add(role);
   securityRepository.addMatch(SecurityTest.addressA, roles);
   securityManager.getConfiguration().addRole("auser", "arole");
   ClientSessionFactory cf = createSessionFactory(locator);
   ClientSession session = cf.createSession("auser", "pass", false, true, true, false, -1);
   try {
      session.createQueue(new QueueConfiguration(SecurityTest.queueA).setAddress(SecurityTest.addressA).setDurable(false));
      Assert.fail("should throw exception");
   } catch (ActiveMQSecurityException se) {
      //ok
   } catch (ActiveMQException e) {
      fail("Invalid Exception type:" + e.getType());
   }
   session.close();
}
 
Example #17
Source File: ManagementServiceImplTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Test
public void testHandleManagementMessageWithOperationWhichFails() throws Exception {
   Configuration config = createBasicConfig().setJMXManagementEnabled(false);

   ActiveMQServer server = addServer(ActiveMQServers.newActiveMQServer(config, false));
   server.start();

   // invoke attribute and operation on the server
   CoreMessage message = new CoreMessage(1, 100);
   ManagementHelper.putOperationInvocation(message, ResourceNames.BROKER, "thereIsNoSuchOperation");

   ICoreMessage reply = server.getManagementService().handleMessage(message);

   Assert.assertFalse(ManagementHelper.hasOperationSucceeded(reply));
   Assert.assertNotNull(ManagementHelper.getResult(reply));
}
 
Example #18
Source File: SecurityTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Test
public void testNonBlockSendManagementWithoutRole() throws Exception {
   ActiveMQServer server = createServer();

   server.start();
   HierarchicalRepository<Set<Role>> securityRepository = server.getSecurityRepository();
   ActiveMQJAASSecurityManager securityManager = (ActiveMQJAASSecurityManager) server.getSecurityManager();
   securityManager.getConfiguration().addUser("auser", "pass");
   Role role = new Role("arole", false, false, true, false, false, false, false, false, true, false);
   Set<Role> roles = new HashSet<>();
   roles.add(role);
   securityRepository.addMatch(configuration.getManagementAddress().toString(), roles);
   securityManager.getConfiguration().addRole("auser", "arole");
   ClientSessionFactory cf = createSessionFactory(locator);
   ClientSession session = cf.createSession("auser", "pass", false, true, true, false, -1);
   session.createQueue(new QueueConfiguration(SecurityTest.queueA).setAddress(configuration.getManagementAddress().toString()));
   ClientProducer cp = session.createProducer(configuration.getManagementAddress());
   cp.send(session.createMessage(false));
   session.close();

   Queue binding = (Queue) server.getPostOffice().getBinding(new SimpleString(SecurityTest.queueA)).getBindable();
   Assert.assertEquals(0, getMessageCount(binding));

}
 
Example #19
Source File: ExportFormatTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Test
public void testConsumeFromFormat() throws Exception {
   ActiveMQServer server = createServer(true);

   DecodeJournal.importJournal(server.getConfiguration().getJournalLocation().getAbsolutePath(), "activemq-data", "amq", 2, 102400, new StringReader(journalFile));
   DecodeJournal.importJournal(server.getConfiguration().getBindingsLocation().getAbsolutePath(), "activemq-bindings", "bindings", 2, 1048576, new StringReader(bindingsFile));
   server.start();

   ServerLocator locator = createInVMNonHALocator();
   ClientSessionFactory factory = createSessionFactory(locator);
   ClientSession session = factory.createSession();
   session.start();

   ClientConsumer consumer = session.createConsumer("A1");
   for (int i = 0; i < 10; i++) {
      ClientMessage msg = consumer.receive(5000);
      assertNotNull(msg);
      msg.acknowledge();
      assertEquals(i, msg.getIntProperty("key").intValue());
   }

   session.commit();
}
 
Example #20
Source File: ClusterTestBase.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
protected ActiveMQServer getServer(final int node) {
   if (servers[node] == null) {
      throw new IllegalArgumentException("No server at node " + node);
   }

   return servers[node];
}
 
Example #21
Source File: MultiServerTestBase.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
protected ActiveMQServer setupBackupServer(final int node,
                                           final int liveNode,
                                           final NodeManager nodeManager) throws Exception {
   TransportConfiguration serverConfigAcceptor = createTransportConfiguration(useNetty(), true, generateParams(node, useNetty()));
   TransportConfiguration thisConnector = createTransportConfiguration(useNetty(), false, generateParams(node, useNetty()));

   Configuration configuration = createBasicConfig(useSharedStorage() ? liveNode : node).clearAcceptorConfigurations().addAcceptorConfiguration(serverConfigAcceptor).addConnectorConfiguration("thisConnector", thisConnector).setHAPolicyConfiguration(useSharedStorage() ? new SharedStoreSlavePolicyConfiguration() : new ReplicaPolicyConfiguration());

   List<String> targetServersOnConnection = new ArrayList<>();

   for (int targetNode = 0; targetNode < getNumberOfServers(); targetNode++) {
      //         if (targetNode == node)
      //         {
      //            // moving on from itself
      //            continue;
      //         }
      String targetConnectorName = "targetConnector-" + targetNode;
      TransportConfiguration targetServer = createTransportConfiguration(useNetty(), false, generateParams(targetNode, useNetty()));
      configuration.addConnectorConfiguration(targetConnectorName, targetServer);
      targetServersOnConnection.add(targetConnectorName);
   }

   ClusterConnectionConfiguration clusterConf = new ClusterConnectionConfiguration().setName("localCluster" + node).setAddress("cluster-queues").setConnectorName("thisConnector").setRetryInterval(100).setConfirmationWindowSize(1024).setMessageLoadBalancingType(MessageLoadBalancingType.ON_DEMAND).setStaticConnectors(targetServersOnConnection);

   configuration.getClusterConfigurations().add(clusterConf);

   ActiveMQServer server;

   if (useSharedStorage()) {
      server = createInVMFailoverServer(true, configuration, nodeManager, liveNode);
   } else {
      server = addServer(ActiveMQServers.newActiveMQServer(configuration, useRealFiles()));
   }
   server.setIdentity(this.getClass().getSimpleName() + "/Backup(" + node + " of live " + liveNode + ")");
   return server;
}
 
Example #22
Source File: AmqpClientTestSupport.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
protected void configureBrokerSecurity(ActiveMQServer server) {
   if (isSecurityEnabled()) {
      ActiveMQJAASSecurityManager securityManager = (ActiveMQJAASSecurityManager) server.getSecurityManager();

      // User additions
      securityManager.getConfiguration().addUser(noprivUser, noprivPass);
      securityManager.getConfiguration().addRole(noprivUser, "nothing");
      securityManager.getConfiguration().addUser(browseUser, browsePass);
      securityManager.getConfiguration().addRole(browseUser, "browser");
      securityManager.getConfiguration().addUser(guestUser, guestPass);
      securityManager.getConfiguration().addRole(guestUser, "guest");
      securityManager.getConfiguration().addUser(fullUser, fullPass);
      securityManager.getConfiguration().addRole(fullUser, "full");

      // Configure roles
      HierarchicalRepository<Set<Role>> securityRepository = server.getSecurityRepository();
      HashSet<Role> value = new HashSet<>();
      value.add(new Role("nothing", false, false, false, false, false, false, false, false, false, false));
      value.add(new Role("browser", false, false, false, false, false, false, false, true, false, false));
      value.add(new Role("guest", false, true, false, false, false, false, false, true, false, false));
      value.add(new Role("full", true, true, true, true, true, true, true, true, true, true));
      securityRepository.addMatch(getQueueName(), value);

      server.getConfiguration().setSecurityEnabled(true);
   } else {
      server.getConfiguration().setSecurityEnabled(false);
   }
}
 
Example #23
Source File: BackupSyncDelay.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
/**
 * @param backup
 * @param live
 * @param packetCode which packet is going to be intercepted.
 */
public BackupSyncDelay(ActiveMQServer backup, ActiveMQServer live, byte packetCode) {
   this.backup = backup;
   this.live = live;
   live.getRemotingService().addIncomingInterceptor(this);
   handler = new ReplicationChannelHandler(packetCode);
}
 
Example #24
Source File: QueueManagerImpl.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
public QueueManagerImpl(ActiveMQServer server, SimpleString queueName) {
   // This needs to be an executor
   // otherwise we may have dead-locks in certain cases such as failure,
   // where consumers are closed after callbacks
   super(server.getExecutorFactory().getExecutor());
   this.server = server;
   this.queueName = queueName;
   this.setTask(this::doIt);
}
 
Example #25
Source File: ReplicatedPagedFailoverTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
protected ActiveMQServer createInVMFailoverServer(final boolean realFiles,
                                                  final Configuration configuration,
                                                  final NodeManager nodeManager,
                                                  int id) {
   return createInVMFailoverServer(realFiles, configuration, PAGE_SIZE, PAGE_MAX, new HashMap<String, AddressSettings>(), nodeManager, id);
}
 
Example #26
Source File: AckBatchSizeTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testAckBatchSizeZero() throws Exception {
   ActiveMQServer server = createServer(false);

   server.start();
   ServerLocator locator = createInVMNonHALocator().setAckBatchSize(0).setBlockOnAcknowledge(true);
   ClientSessionFactory cf = createSessionFactory(locator);
   ClientSession sendSession = cf.createSession(false, true, true);
   int numMessages = 100;

   ClientSession session = cf.createSession(false, true, true);
   session.createQueue(new QueueConfiguration(queueA).setAddress(addressA).setDurable(false));
   ClientProducer cp = sendSession.createProducer(addressA);
   for (int i = 0; i < numMessages; i++) {
      cp.send(sendSession.createMessage(false));
   }

   ClientConsumer consumer = session.createConsumer(queueA);
   session.start();
   Queue q = (Queue) server.getPostOffice().getBinding(queueA).getBindable();
   ClientMessage[] messages = new ClientMessage[numMessages];
   for (int i = 0; i < numMessages; i++) {
      messages[i] = consumer.receive(5000);
      Assert.assertNotNull(messages[i]);
   }
   for (int i = 0; i < numMessages; i++) {
      messages[i].acknowledge();
      Assert.assertEquals(numMessages - i - 1, q.getDeliveringCount());
   }
   sendSession.close();
   session.close();
}
 
Example #27
Source File: MQTTSecurityCRLTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
private ActiveMQServer initServer() throws Exception {
   Configuration configuration = createDefaultNettyConfig().setSecurityEnabled(false);

   addMqttTransportConfiguration(configuration);
   addWildCardConfiguration(configuration);

   ActiveMQServer server = createServer(true, configuration);
   return server;
}
 
Example #28
Source File: MQTTProtocolManagerFactory.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
public ProtocolManager createProtocolManager(ActiveMQServer server,
                                             final Map<String, Object> parameters,
                                             List<BaseInterceptor> incomingInterceptors,
                                             List<BaseInterceptor> outgoingInterceptors) throws Exception {
   stripPasswordParameters(parameters);
   return BeanSupport.setData(new MQTTProtocolManager(server, connectedClients, sessionStates, incomingInterceptors, outgoingInterceptors), parameters);
}
 
Example #29
Source File: ColocatedActiveMQServer.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
public ActiveMQServer createBackupServer(Configuration configuration) {
   ColocatedActiveMQServer backup = new ColocatedActiveMQServer(configuration, this, nodeManagerBackup, nodeManagerLive);
   backup.backup = true;
   this.backupServer = backup;
   return backup;
}
 
Example #30
Source File: JMSLVQTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
protected void addConfiguration(ActiveMQServer server) {
   server.getConfiguration().setPersistenceEnabled(false);
   server.getConfiguration().setMessageExpiryScanPeriod(1000);
   server.getAddressSettingsRepository().addMatch(NORMAL_QUEUE_NAME, new AddressSettings());
   server.getAddressSettingsRepository().addMatch(LVQ_QUEUE_NAME, new AddressSettings().setDefaultLastValueQueue(true));
   server.getAddressSettingsRepository().addMatch(LVQ_CUSTOM_KEY_QUEUE_NAME, new AddressSettings().setDefaultLastValueQueue(true).setDefaultLastValueKey(SimpleString.toSimpleString(CUSTOM_KEY)));
}