use of org.apache.activemq.artemis.core.config.impl.SecurityConfiguration in project activemq-artemis by apache.
the class ActiveMQTestBase method createInVMFailoverServer.
protected ActiveMQServer createInVMFailoverServer(final boolean realFiles, final Configuration configuration, final int pageSize, final int maxAddressSize, final Map<String, AddressSettings> settings, NodeManager nodeManager, final int id) {
ActiveMQServer server;
ActiveMQSecurityManager securityManager = new ActiveMQJAASSecurityManager(InVMLoginModule.class.getName(), new SecurityConfiguration());
configuration.setPersistenceEnabled(realFiles);
server = addServer(new InVMNodeManagerServer(configuration, ManagementFactory.getPlatformMBeanServer(), securityManager, nodeManager));
try {
server.setIdentity("Server " + id);
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);
server.getAddressSettingsRepository().addMatch("#", defaultSetting);
return server;
} finally {
addServer(server);
}
}
use of org.apache.activemq.artemis.core.config.impl.SecurityConfiguration in project activemq-artemis by apache.
the class EmbeddedExample method main.
public static void main(final String[] args) throws Exception {
// Step 1. Configure security.
SecurityConfiguration securityConfig = new SecurityConfiguration();
securityConfig.addUser("guest", "guest");
securityConfig.addRole("guest", "guest");
securityConfig.setDefaultUser("guest");
ActiveMQJAASSecurityManager securityManager = new ActiveMQJAASSecurityManager(InVMLoginModule.class.getName(), securityConfig);
// Step 2. Create and start embedded broker.
ActiveMQServer server = ActiveMQServers.newActiveMQServer("broker.xml", null, securityManager);
server.start();
System.out.println("Started Embedded Broker");
InitialContext initialContext = null;
// Step 3. Create an initial context to perform the JNDI lookup.
initialContext = new InitialContext();
// Step 4. Look-up the JMS queue
Queue queue = (Queue) initialContext.lookup("queue/exampleQueue");
// Step 5. Look-up the JMS connection factory
ConnectionFactory cf = (ConnectionFactory) initialContext.lookup("ConnectionFactory");
// Step 6. Send and receive a message using JMS API
try (Connection connection = cf.createConnection()) {
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer producer = session.createProducer(queue);
TextMessage message = session.createTextMessage("Hello sent at " + new Date());
System.out.println("Sending message: " + message.getText());
producer.send(message);
MessageConsumer messageConsumer = session.createConsumer(queue);
connection.start();
TextMessage messageReceived = (TextMessage) messageConsumer.receive(1000);
System.out.println("Received message:" + messageReceived.getText());
} finally {
// Step 7. Stop the embedded broker.
server.stop();
System.out.println("Stopped the Embedded Broker");
}
}
Aggregations