org.apache.activemq.security.SimpleAuthenticationPlugin Java Examples

The following examples show how to use org.apache.activemq.security.SimpleAuthenticationPlugin. 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: CustomConfigurationExampleTest.java    From amqp-10-jms-spring-boot with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setUp() throws Exception {
    brokerService = new BrokerService();

    brokerService.addConnector("amqp://localhost:5672");
    brokerService.setPersistent(false);
    brokerService.getManagementContext().setCreateConnector(false);

    ArrayList<BrokerPlugin> plugins = new ArrayList<BrokerPlugin>();

    List<AuthenticationUser> users = new ArrayList<AuthenticationUser>();
    users.add(new AuthenticationUser("admin", "admin", "admins"));

    SimpleAuthenticationPlugin authenticationPlugin = new SimpleAuthenticationPlugin(users);
    plugins.add(authenticationPlugin);
    plugins.add(configureAuthorization());

    brokerService.setPlugins(plugins.toArray(new BrokerPlugin[2]));
    brokerService.start();
    brokerService.waitUntilStarted();
}
 
Example #2
Source File: ActiveMQJmsPoolTestSupport.java    From pooled-jms with Apache License 2.0 5 votes vote down vote up
protected String createBroker() throws Exception {
    brokerService = new BrokerService();
    brokerService.setDeleteAllMessagesOnStartup(true);
    brokerService.setPersistent(false);
    brokerService.setUseJmx(true);
    brokerService.getManagementContext().setCreateConnector(false);
    brokerService.getManagementContext().setCreateMBeanServer(false);
    brokerService.setAdvisorySupport(false);
    brokerService.setSchedulerSupport(false);
    brokerService.addConnector("tcp://localhost:0").setName("test");

    ArrayList<BrokerPlugin> plugins = new ArrayList<BrokerPlugin>();

    List<AuthenticationUser> users = new ArrayList<AuthenticationUser>();
    users.add(new AuthenticationUser(USER, USER_PASSWORD, "users"));
    users.add(new AuthenticationUser(GUEST, USER_PASSWORD, "guests"));
    users.add(new AuthenticationUser(ADMIN, ADMIN, "admins"));

    SimpleAuthenticationPlugin authenticationPlugin = new SimpleAuthenticationPlugin(users);
    authenticationPlugin.setAnonymousAccessAllowed(true);

    plugins.add(authenticationPlugin);
    plugins.add(configureAuthorization());

    brokerService.setPlugins(plugins.toArray(new BrokerPlugin[2]));

    brokerService.start();
    brokerService.waitUntilStarted();

    return brokerService.getTransportConnectorByName("test").getPublishableConnectString();
}
 
Example #3
Source File: JmsIOTest.java    From beam with Apache License 2.0 5 votes vote down vote up
@Before
public void startBroker() throws Exception {
  broker = new BrokerService();
  broker.setUseJmx(false);
  broker.setPersistenceAdapter(new MemoryPersistenceAdapter());
  broker.addConnector(BROKER_URL);
  broker.setBrokerName("localhost");
  broker.setPopulateJMSXUserID(true);
  broker.setUseAuthenticatedPrincipalForJMSXUserID(true);

  // enable authentication
  List<AuthenticationUser> users = new ArrayList<>();
  // username and password to use to connect to the broker.
  // This user has users privilege (able to browse, consume, produce, list destinations)
  users.add(new AuthenticationUser(USERNAME, PASSWORD, "users"));
  SimpleAuthenticationPlugin plugin = new SimpleAuthenticationPlugin(users);
  BrokerPlugin[] plugins = new BrokerPlugin[] {plugin};
  broker.setPlugins(plugins);

  broker.start();

  // create JMS connection factory
  connectionFactory = new ActiveMQConnectionFactory(BROKER_URL);
  connectionFactoryWithSyncAcksAndWithoutPrefetch =
      new ActiveMQConnectionFactory(
          BROKER_URL + "?jms.prefetchPolicy.all=0&jms.sendAcksAsync=false");
}
 
Example #4
Source File: TestJmsSource.java    From datacollector with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
  baseDir = Files.createTempDir();
  tmpDir = new File(baseDir, "tmp");
  dataDir = new File(baseDir, "data");
  Assert.assertTrue(tmpDir.mkdir());
  passwordFile = new File(baseDir, "password");
  Files.write(PASSWORD.getBytes(StandardCharsets.UTF_8), passwordFile);

  broker = new BrokerService();

  broker.addConnector(BROKER_BIND_URL);
  broker.setTmpDataDirectory(tmpDir);
  broker.setDataDirectoryFile(dataDir);
  List<AuthenticationUser> users = Lists.newArrayList();
  users.add(new AuthenticationUser(USERNAME, PASSWORD, ""));
  SimpleAuthenticationPlugin authentication = new SimpleAuthenticationPlugin(users);
  broker.setPlugins(new BrokerPlugin[]{authentication});
  broker.start();

  basicConfig = new BasicConfig();
  credentialsConfig = new CredentialsConfig();
  messageConfig = new MessageConfig();
  jmsSourceConfig = new JmsSourceConfig();
  credentialsConfig.useCredentials = true;
  credentialsConfig.username = () -> USERNAME;
  credentialsConfig.password = () -> PASSWORD;
  jmsSourceConfig.initialContextFactory = INITIAL_CONTEXT_FACTORY;
  jmsSourceConfig.connectionFactory = CONNECTION_FACTORY;
  jmsSourceConfig.destinationName = JNDI_PREFIX + DESTINATION_NAME;
  jmsSourceConfig.providerURL = BROKER_BIND_URL;
  // Create a connection and start
  ConnectionFactory factory = new ActiveMQConnectionFactory(USERNAME,
      PASSWORD, BROKER_BIND_URL);
  connection = factory.createConnection();
  connection.start();
}
 
Example #5
Source File: TestJmsTarget.java    From datacollector with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
  baseDir = Files.createTempDir();
  tmpDir = new File(baseDir, "tmp");
  dataDir = new File(baseDir, "data");
  Assert.assertTrue(tmpDir.mkdir());
  passwordFile = new File(baseDir, "password");
  Files.write(PASSWORD.getBytes(StandardCharsets.UTF_8), passwordFile);

  broker = new BrokerService();

  broker.addConnector(BROKER_BIND_URL);
  broker.setTmpDataDirectory(tmpDir);
  broker.setDataDirectoryFile(dataDir);
  List<AuthenticationUser> users = Lists.newArrayList();
  users.add(new AuthenticationUser(USERNAME, PASSWORD, ""));
  SimpleAuthenticationPlugin authentication = new SimpleAuthenticationPlugin(users);
  broker.setPlugins(new BrokerPlugin[]{authentication});
  broker.start();

  credentialsConfig = new CredentialsConfig();
  jmsTargetConfig = new JmsTargetConfig();
  credentialsConfig.useCredentials = true;
  credentialsConfig.username = () -> USERNAME;
  credentialsConfig.password = () -> PASSWORD;
  jmsTargetConfig.destinationName = JNDI_PREFIX + DESTINATION_NAME;
  jmsTargetConfig.initialContextFactory = INITIAL_CONTEXT_FACTORY;
  jmsTargetConfig.connectionFactory = CONNECTION_FACTORY;
  jmsTargetConfig.providerURL = BROKER_BIND_URL;
  // Create a connection and start
  ConnectionFactory factory = new ActiveMQConnectionFactory(USERNAME,
      PASSWORD, BROKER_BIND_URL);
  connection = factory.createConnection();
  connection.start();
}
 
Example #6
Source File: AMQ4889Test.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
protected BrokerPlugin configureAuthentication() throws Exception {
   List<AuthenticationUser> users = new ArrayList<>();
   users.add(new AuthenticationUser(USER, GOOD_USER_PASSWORD, "users"));
   SimpleAuthenticationPlugin authenticationPlugin = new SimpleAuthenticationPlugin(users);

   return authenticationPlugin;
}
 
Example #7
Source File: ExceptionListenerTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Before
public void startBroker() throws Exception {
   brokerService = new BrokerService();
   brokerService.setAdvisorySupport(false);
   brokerService.setUseJmx(false);
   brokerService.setPersistent(false);
   brokerService.setPlugins(new BrokerPlugin[]{new SimpleAuthenticationPlugin(new ArrayList())});
   brokerUri = brokerService.addConnector("tcp://0.0.0.0:0").getConnectUri();
   brokerService.start();
}
 
Example #8
Source File: ActiveMQTestBase.java    From vertx-proton with Apache License 2.0 5 votes vote down vote up
protected BrokerPlugin configureAuthentication() throws Exception {
  List<AuthenticationUser> users = new ArrayList<AuthenticationUser>();
  users.add(new AuthenticationUser(USERNAME_ADMIN, PASSWORD_ADMIN, "users,admins"));
  users.add(new AuthenticationUser(USERNAME_USER, PASSWORD_USER, "users"));
  users.add(new AuthenticationUser(USERNAME_GUEST, PASSWORD_GUEST, "guests"));
  SimpleAuthenticationPlugin authenticationPlugin = new SimpleAuthenticationPlugin(users);
  authenticationPlugin.setAnonymousAccessAllowed(isAnonymousAccessAllowed());

  return authenticationPlugin;
}
 
Example #9
Source File: QpidJmsTestSupport.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
protected BrokerPlugin configureAuthentication() throws Exception {
    List<AuthenticationUser> users = new ArrayList<AuthenticationUser>();
    users.add(new AuthenticationUser("system", "manager", "users,admins"));
    users.add(new AuthenticationUser("user", "password", "users"));
    users.add(new AuthenticationUser("guest", "password", "guests"));
    SimpleAuthenticationPlugin authenticationPlugin = new SimpleAuthenticationPlugin(users);
    authenticationPlugin.setAnonymousAccessAllowed(true);

    return authenticationPlugin;
}
 
Example #10
Source File: Broker.java    From hazelcast-simulator with Apache License 2.0 5 votes vote down vote up
public Broker start() {
    LOGGER.info("Starting broker using brokerURL: [" + brokerURL + "]");

    try {
        broker = new BrokerService();
        broker.setPersistent(false);
        broker.deleteAllMessages();
        broker.setDeleteAllMessagesOnStartup(true);
        broker.setUseJmx(false);
        broker.getSystemUsage().getTempUsage().setLimit(USAGE_LIMIT);
        broker.getSystemUsage().getStoreUsage().setLimit(USAGE_LIMIT);
        broker.addConnector(brokerURL);

        if (username != null) {
            AuthenticationUser user = new AuthenticationUser(username, password, "producers,consumer");
            SimpleAuthenticationPlugin authenticationPlugin = new SimpleAuthenticationPlugin();
            authenticationPlugin.setAnonymousAccessAllowed(false);
            authenticationPlugin.setUsers(singletonList(user));
            broker.setPlugins(new BrokerPlugin[]{authenticationPlugin});
        }

        broker.start();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }

    LOGGER.info("Successfully started broker");
    return this;
}
 
Example #11
Source File: IgniteJmsStreamerTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * Test for ExceptionListener functionality.
 *
 * @throws Exception If fails.
 */
@Test
public void testExceptionListener() throws Exception {
    // restart broker with auth plugin
    if (broker.isStarted())
        broker.stop();

    broker.waitUntilStopped();

    broker.setPlugins(new BrokerPlugin[]{new SimpleAuthenticationPlugin(new ArrayList())});

    broker.start(true);

    connFactory = new ActiveMQConnectionFactory(BrokerRegistry.getInstance().findFirst().getVmConnectorURI());

    final List<Throwable> lsnrExceptions = new LinkedList<>();

    final CountDownLatch latch = new CountDownLatch(1);

    Destination dest = new ActiveMQQueue(QUEUE_NAME);

    try (IgniteDataStreamer<String, String> dataStreamer = grid().dataStreamer(DEFAULT_CACHE_NAME)) {
        JmsStreamer<ObjectMessage, String, String> jmsStreamer = newJmsStreamer(ObjectMessage.class, dataStreamer);

        jmsStreamer.setExceptionListener(new ExceptionListener() {
            @Override public void onException(JMSException e) {
                System.out.println("ERROR");

                lsnrExceptions.add(e);

                latch.countDown();
            }
        });

        jmsStreamer.setDestination(dest);

        GridTestUtils.assertThrowsWithCause(new Callable<Void>() {
            @Override public Void call() throws Exception {
                jmsStreamer.start();

                return null;
            }
        }, SecurityException.class);

        assertTrue(latch.await(10, TimeUnit.SECONDS));

        assertTrue(lsnrExceptions.size() > 0);

        GridTestUtils.assertThrowsWithCause(new Callable<Void>() {
            @Override public Void call() throws Exception {
                jmsStreamer.stop();

                return null;
            }
        }, IgniteException.class);
    }
}
 
Example #12
Source File: TestIntegrationActiveMQ.java    From mt-flume with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
@Before
public void setup() throws Exception {
  baseDir = Files.createTempDir();
  tmpDir = new File(baseDir, "tmp");
  dataDir = new File(baseDir, "data");
  Assert.assertTrue(tmpDir.mkdir());
  passwordFile = new File(baseDir, "password");
  Files.write(PASSWORD.getBytes(Charsets.UTF_8), passwordFile);

  broker = new BrokerService();

  broker.addConnector(BROKER_BIND_URL);
  broker.setTmpDataDirectory(tmpDir);
  broker.setDataDirectoryFile(dataDir);
  List<AuthenticationUser> users = Lists.newArrayList();
  users.add(new AuthenticationUser(USERNAME, PASSWORD, ""));
  SimpleAuthenticationPlugin authentication = new SimpleAuthenticationPlugin(users);
  broker.setPlugins(new BrokerPlugin[]{authentication});
  broker.start();

  context = new Context();
  context.put(JMSSourceConfiguration.INITIAL_CONTEXT_FACTORY, INITIAL_CONTEXT_FACTORY);
  context.put(JMSSourceConfiguration.PROVIDER_URL, BROKER_BIND_URL);
  context.put(JMSSourceConfiguration.DESTINATION_NAME, DESTINATION_NAME);
  context.put(JMSSourceConfiguration.USERNAME, USERNAME);
  context.put(JMSSourceConfiguration.PASSWORD_FILE, passwordFile.getAbsolutePath());

  events = Lists.newArrayList();
  source = new JMSSource();
  source.setName("JMSSource-" + UUID.randomUUID());
  ChannelProcessor channelProcessor = mock(ChannelProcessor.class);
  doAnswer(new Answer<Void>() {
    @Override
    public Void answer(InvocationOnMock invocation) throws Throwable {
      events.addAll((List<Event>)invocation.getArguments()[0]);
      return null;
    }
  }).when(channelProcessor).processEventBatch(any(List.class));
  source.setChannelProcessor(channelProcessor);


}