use of org.apache.activemq.artemis.core.config.impl.SecurityConfiguration in project activemq-artemis by apache.
the class CriticalCrashTest method createServer.
ActiveMQServer createServer(String folder) throws Exception {
final AtomicBoolean blocked = new AtomicBoolean(false);
Configuration conf = createConfig(folder);
ActiveMQSecurityManager securityManager = new ActiveMQJAASSecurityManager(InVMLoginModule.class.getName(), new SecurityConfiguration());
conf.setPersistenceEnabled(true);
ActiveMQServer server = new ActiveMQServerImpl(conf, securityManager) {
@Override
protected StorageManager createStorageManager() {
JournalStorageManager storageManager = new JournalStorageManager(conf, getCriticalAnalyzer(), executorFactory, scheduledPool, ioExecutorFactory, shutdownOnCriticalIO) {
@Override
public void readLock() {
super.readLock();
if (blocked.get()) {
while (true) {
try {
System.out.println("Blocking forever");
Thread.sleep(1000);
} catch (Throwable ignored) {
}
}
}
}
@Override
public void storeMessage(Message message) throws Exception {
super.storeMessage(message);
blocked.set(true);
}
};
this.getCriticalAnalyzer().add(storageManager);
return storageManager;
}
};
return server;
}
use of org.apache.activemq.artemis.core.config.impl.SecurityConfiguration in project activemq-artemis by apache.
the class FileBrokerTest method testConfigFileReload.
@Test
public void testConfigFileReload() throws Exception {
ServerDTO serverDTO = new ServerDTO();
serverDTO.configuration = "broker-reload.xml";
FileBroker broker = null;
String path = null;
try {
SecurityConfiguration securityConfiguration = new SecurityConfiguration();
securityConfiguration.addUser("myUser", "myPass");
securityConfiguration.addRole("myUser", "guest");
ActiveMQJAASSecurityManager securityManager = new ActiveMQJAASSecurityManager(InVMLoginModule.class.getName(), securityConfiguration);
broker = new FileBroker(serverDTO, securityManager);
broker.start();
ActiveMQServerImpl activeMQServer = (ActiveMQServerImpl) broker.getComponents().get("core");
Assert.assertNotNull(activeMQServer);
Assert.assertTrue(activeMQServer.isStarted());
Assert.assertTrue(broker.isStarted());
File file = new File(activeMQServer.getConfiguration().getConfigurationUrl().toURI());
path = file.getPath();
Assert.assertNotNull(activeMQServer.getConfiguration().getConfigurationUrl());
Thread.sleep(activeMQServer.getConfiguration().getConfigurationFileRefreshPeriod() * 2);
ServerLocator locator = ActiveMQClient.createServerLocator("tcp://localhost:61616");
ClientSessionFactory sf = locator.createSessionFactory();
ClientSession session = sf.createSession("myUser", "myPass", false, true, false, false, 0);
ClientProducer producer = session.createProducer("DLQ");
producer.send(session.createMessage(true));
replacePatternInFile(path, "guest", "X");
Thread.sleep(activeMQServer.getConfiguration().getConfigurationFileRefreshPeriod() * 2);
try {
producer.send(session.createMessage(true));
fail("Should throw a security exception");
} catch (Exception e) {
}
locator.close();
} finally {
assert broker != null;
broker.stop();
if (path != null) {
replacePatternInFile(path, "X", "guest");
}
}
}
use of org.apache.activemq.artemis.core.config.impl.SecurityConfiguration 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.core.config.impl.SecurityConfiguration 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.core.config.impl.SecurityConfiguration 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;
}
Aggregations