use of org.apache.activemq.artemis.spi.core.security.ActiveMQJAASSecurityManager in project activemq-artemis by apache.
the class EmbeddedRestActiveMQJMSTest method startEmbedded.
@BeforeClass
public static void startEmbedded() throws Exception {
server = new EmbeddedRestActiveMQJMS(null);
assertNotNull(server.embeddedActiveMQ);
server.getManager().setConfigResourcePath("activemq-rest.xml");
SecurityConfiguration securityConfiguration = createDefaultSecurityConfiguration();
ActiveMQJAASSecurityManager securityManager = new ActiveMQJAASSecurityManager(InVMLoginModule.class.getName(), securityConfiguration);
server.getEmbeddedJMS().setSecurityManager(securityManager);
server.start();
List<String> connectors = createInVmConnector();
server.getEmbeddedJMS().getJMSServerManager().createConnectionFactory("ConnectionFactory", false, JMSFactoryType.CF, connectors, "ConnectionFactory");
ClientRequest request = new ClientRequest(TestPortProvider.generateURL("/queues/exampleQueue"));
ClientResponse<?> response = request.head();
response.releaseConnection();
assertEquals(200, response.getStatus());
Link sender = response.getLinkHeader().getLinkByTitle("create");
System.out.println("create: " + sender);
Link consumers = response.getLinkHeader().getLinkByTitle("pull-consumers");
System.out.println("pull: " + consumers);
response = Util.setAutoAck(consumers, true);
consumeNext = response.getLinkHeader().getLinkByTitle("consume-next");
System.out.println("consume-next: " + consumeNext);
}
use of org.apache.activemq.artemis.spi.core.security.ActiveMQJAASSecurityManager in project activemq-artemis by apache.
the class EmbeddedTest method startEmbedded.
@BeforeClass
public static void startEmbedded() throws Exception {
server = new EmbeddedRestActiveMQJMS(null);
server.getManager().setConfigResourcePath("activemq-rest.xml");
SecurityConfiguration securityConfiguration = new SecurityConfiguration();
securityConfiguration.addUser("guest", "guest");
securityConfiguration.addRole("guest", "guest");
securityConfiguration.setDefaultUser("guest");
ActiveMQJAASSecurityManager securityManager = new ActiveMQJAASSecurityManager(InVMLoginModule.class.getName(), securityConfiguration);
server.getEmbeddedJMS().setSecurityManager(securityManager);
server.start();
List<String> connectors = new ArrayList<>();
connectors.add("in-vm");
server.getEmbeddedJMS().getJMSServerManager().createConnectionFactory("ConnectionFactory", false, JMSFactoryType.CF, connectors, "ConnectionFactory");
}
use of org.apache.activemq.artemis.spi.core.security.ActiveMQJAASSecurityManager in project activemq-artemis by apache.
the class LocalTestServer method start.
@Override
public synchronized void start(final HashMap<String, Object> configuration, final boolean clearJournal) throws Exception {
if (isStarted()) {
return;
}
if (clearJournal) {
// Delete the Journal environment
File dir = new File("target/data");
boolean deleted = LocalTestServer.deleteDirectory(dir);
JmsTestLogger.LOGGER.info("Deleted dir: " + dir.getAbsolutePath() + " deleted: " + deleted);
}
javax.management.MBeanServer beanServer = java.lang.management.ManagementFactory.getPlatformMBeanServer();
FileConfiguration fileConfiguration = new FileConfiguration();
ActiveMQJAASSecurityManager securityManager = new ActiveMQJAASSecurityManager(InVMLoginModule.class.getName(), new SecurityConfiguration());
securityManager.getConfiguration().addUser("guest", "guest");
securityManager.getConfiguration().setDefaultUser("guest");
securityManager.getConfiguration().addRole("guest", "guest");
ActiveMQServerImpl activeMQServer = new ActiveMQServerImpl(fileConfiguration, beanServer, securityManager);
jmsServerManager = new JMSServerManagerImpl(activeMQServer);
System.setProperty(Constants.SERVER_INDEX_PROPERTY_NAME, "" + getServerID());
jmsServerManager.setRegistry(new JndiBindingRegistry(getInitialContext()));
FileDeploymentManager deploymentManager = new FileDeploymentManager();
deploymentManager.addDeployable(fileConfiguration).readConfiguration();
jmsServerManager.start();
started = true;
}
use of org.apache.activemq.artemis.spi.core.security.ActiveMQJAASSecurityManager in project activemq-artemis by apache.
the class EmbeddedActiveMQ method initStart.
protected void initStart() throws Exception {
if (configuration == null) {
if (configResourcePath == null)
configResourcePath = "broker.xml";
FileDeploymentManager deploymentManager = new FileDeploymentManager(configResourcePath);
FileConfiguration config = new FileConfiguration();
deploymentManager.addDeployable(config);
deploymentManager.readConfiguration();
configuration = config;
}
if (securityManager == null) {
securityManager = new ActiveMQJAASSecurityManager();
}
if (mbeanServer == null) {
activeMQServer = new ActiveMQServerImpl(configuration, securityManager);
} else {
activeMQServer = new ActiveMQServerImpl(configuration, mbeanServer, securityManager);
}
}
use of org.apache.activemq.artemis.spi.core.security.ActiveMQJAASSecurityManager in project activemq-artemis by apache.
the class ServerLargeMessageTest method testSendServerMessageWithValidatedUser.
@Test
public void testSendServerMessageWithValidatedUser() throws Exception {
ActiveMQJAASSecurityManager securityManager = new ActiveMQJAASSecurityManager("PropertiesLogin");
ActiveMQServer server = addServer(ActiveMQServers.newActiveMQServer(createDefaultInVMConfig().setSecurityEnabled(true), ManagementFactory.getPlatformMBeanServer(), securityManager, false));
server.getConfiguration().setPopulateValidatedUser(true);
Role role = new Role("programmers", true, true, true, true, true, true, true, true, true, true);
Set<Role> roles = new HashSet<>();
roles.add(role);
server.getSecurityRepository().addMatch("#", roles);
server.start();
ServerLocator locator = createInVMNonHALocator();
ClientSessionFactory sf = createSessionFactory(locator);
try {
ClientSession session = sf.createSession("first", "secret", false, true, true, false, 0);
ClientMessage clientMessage = session.createMessage(false);
clientMessage.setBodyInputStream(ActiveMQTestBase.createFakeLargeStream(ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE));
session.createQueue("A", RoutingType.ANYCAST, "A");
ClientProducer prod = session.createProducer("A");
prod.send(clientMessage);
session.commit();
session.start();
ClientConsumer cons = session.createConsumer("A");
ClientMessage msg = cons.receive(5000);
assertEquals("first", msg.getValidatedUserID());
} finally {
sf.close();
locator.close();
server.stop();
}
}
Aggregations