Search in sources :

Example 31 with ActiveMQServerImpl

use of org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl in project activemq-artemis by apache.

the class AMQPConnectionCallbackTest method getServerSASLOnlyAllowedMechs.

@Test
public void getServerSASLOnlyAllowedMechs() throws Exception {
    ProtonProtocolManager protonProtocolManager = new ProtonProtocolManager(new ProtonProtocolManagerFactory(), null, null, null);
    protonProtocolManager.setSaslMechanisms(new String[] { PlainSASL.NAME });
    AMQPConnectionCallback connectionCallback = new AMQPConnectionCallback(protonProtocolManager, null, null, new ActiveMQServerImpl());
    assertEquals(1, connectionCallback.getSaslMechanisms().length);
    for (String mech : connectionCallback.getSaslMechanisms()) {
        assertNotNull(connectionCallback.getServerSASL(mech));
    }
    assertNull("can't get mechanism not in the list", connectionCallback.getServerSASL(GSSAPIServerSASL.NAME));
}
Also used : ActiveMQServerImpl(org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl) Test(org.junit.Test)

Example 32 with ActiveMQServerImpl

use of org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl in project activemq-artemis by apache.

the class AMQPConnectionCallbackTest method getServerSASLAnonDefault.

@Test
public void getServerSASLAnonDefault() throws Exception {
    ProtonProtocolManager protonProtocolManager = new ProtonProtocolManager(new ProtonProtocolManagerFactory(), null, null, null);
    protonProtocolManager.setSaslMechanisms(new String[] {});
    AMQPConnectionCallback connectionCallback = new AMQPConnectionCallback(protonProtocolManager, null, null, new ActiveMQServerImpl());
    assertNotNull("can get anon with empty list", connectionCallback.getServerSASL(AnonymousServerSASL.NAME));
}
Also used : ActiveMQServerImpl(org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl) Test(org.junit.Test)

Example 33 with ActiveMQServerImpl

use of org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl in project activemq-artemis by apache.

the class SecurityTest method testCustomSecurityManager.

@Test
public void testCustomSecurityManager() throws Exception {
    final Configuration configuration = createDefaultInVMConfig().setSecurityEnabled(true);
    final ActiveMQSecurityManager customSecurityManager = new ActiveMQSecurityManager() {

        @Override
        public boolean validateUser(final String username, final String password) {
            return (username.equals("foo") || username.equals("bar") || username.equals("all")) && password.equals("frobnicate");
        }

        @Override
        public boolean validateUserAndRole(final String username, final String password, final Set<Role> requiredRoles, final CheckType checkType) {
            if ((username.equals("foo") || username.equals("bar") || username.equals("all")) && password.equals("frobnicate")) {
                if (username.equals("all")) {
                    return true;
                } else if (username.equals("foo")) {
                    return checkType == CheckType.CONSUME || checkType == CheckType.CREATE_NON_DURABLE_QUEUE;
                } else if (username.equals("bar")) {
                    return checkType == CheckType.SEND || checkType == CheckType.CREATE_NON_DURABLE_QUEUE;
                } else {
                    return false;
                }
            } else {
                return false;
            }
        }
    };
    final ActiveMQServer server = addServer(new ActiveMQServerImpl(configuration, customSecurityManager));
    server.start();
    final ServerLocator locator = createInVMNonHALocator();
    locator.setBlockOnNonDurableSend(true).setBlockOnDurableSend(true);
    final ClientSessionFactory factory = createSessionFactory(locator);
    ClientSession adminSession = factory.createSession("all", "frobnicate", false, true, true, false, -1);
    final String queueName = "test.queue";
    adminSession.createQueue(queueName, queueName, false);
    // Wrong user name
    try {
        factory.createSession("baz", "frobnicate", false, true, true, false, -1);
        Assert.fail("should throw exception");
    } catch (ActiveMQSecurityException se) {
    // ok
    } catch (ActiveMQException e) {
        fail("Invalid Exception type:" + e.getType());
    }
    // Wrong password
    try {
        factory.createSession("foo", "xxx", false, true, true, false, -1);
        Assert.fail("should throw exception");
    } catch (ActiveMQSecurityException se) {
    // ok
    } catch (ActiveMQException e) {
        fail("Invalid Exception type:" + e.getType());
    }
    // Correct user and password, allowed to send but not receive
    {
        final ClientSession session = factory.createSession("foo", "frobnicate", false, true, true, false, -1);
        checkUserReceiveNoSend(queueName, session, adminSession);
    }
    // Correct user and password, allowed to receive but not send
    {
        final ClientSession session = factory.createSession("bar", "frobnicate", false, true, true, false, -1);
        checkUserSendNoReceive(queueName, session);
    }
}
Also used : ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) Set(java.util.Set) HashSet(java.util.HashSet) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) Configuration(org.apache.activemq.artemis.core.config.Configuration) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) CheckType(org.apache.activemq.artemis.core.security.CheckType) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ActiveMQServerImpl(org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl) ActiveMQSecurityException(org.apache.activemq.artemis.api.core.ActiveMQSecurityException) ActiveMQSecurityManager(org.apache.activemq.artemis.spi.core.security.ActiveMQSecurityManager) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator) Test(org.junit.Test)

Example 34 with ActiveMQServerImpl

use of org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl in project activemq-artemis by apache.

the class ClearActivateCallbackTest method simpleTest.

@Test
public void simpleTest() throws Exception {
    server = createServer(false, createDefaultNettyConfig());
    server.start();
    int initialCallbackCount = ((ActiveMQServerImpl) server).getActivateCallbacks().size();
    server.registerActivateCallback(new ActivateCallback() {
    });
    assertEquals(1, ((ActiveMQServerImpl) server).getActivateCallbacks().size() - initialCallbackCount);
    server.stop();
    assertEquals(0, ((ActiveMQServerImpl) server).getActivateCallbacks().size());
    server.start();
    assertEquals(initialCallbackCount, ((ActiveMQServerImpl) server).getActivateCallbacks().size());
}
Also used : ActiveMQServerImpl(org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl) ActivateCallback(org.apache.activemq.artemis.core.server.ActivateCallback) Test(org.junit.Test)

Example 35 with ActiveMQServerImpl

use of org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl in project activemq-artemis by apache.

the class FileBrokerTest method startWithoutJMS.

@Test
public void startWithoutJMS() throws Exception {
    ServerDTO serverDTO = new ServerDTO();
    serverDTO.configuration = "broker-nojms.xml";
    FileBroker broker = null;
    try {
        broker = new FileBroker(serverDTO, new ActiveMQJAASSecurityManager());
        broker.start();
        JMSServerManagerImpl jmsServerManager = (JMSServerManagerImpl) broker.getComponents().get("jms");
        Assert.assertNull(jmsServerManager);
        ActiveMQServerImpl activeMQServer = (ActiveMQServerImpl) broker.getComponents().get("core");
        Assert.assertNotNull(activeMQServer);
        Assert.assertTrue(activeMQServer.isStarted());
        Assert.assertTrue(broker.isStarted());
    } finally {
        assert broker != null;
        broker.stop();
    }
}
Also used : FileBroker(org.apache.activemq.artemis.integration.FileBroker) ServerDTO(org.apache.activemq.artemis.dto.ServerDTO) JMSServerManagerImpl(org.apache.activemq.artemis.jms.server.impl.JMSServerManagerImpl) ActiveMQJAASSecurityManager(org.apache.activemq.artemis.spi.core.security.ActiveMQJAASSecurityManager) ActiveMQServerImpl(org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl) Test(org.junit.Test)

Aggregations

ActiveMQServerImpl (org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl)49 Test (org.junit.Test)35 Configuration (org.apache.activemq.artemis.core.config.Configuration)28 StoreConfiguration (org.apache.activemq.artemis.core.config.StoreConfiguration)19 HAPolicyConfiguration (org.apache.activemq.artemis.core.config.HAPolicyConfiguration)16 Activation (org.apache.activemq.artemis.core.server.impl.Activation)16 SharedNothingBackupActivation (org.apache.activemq.artemis.core.server.impl.SharedNothingBackupActivation)16 HAPolicy (org.apache.activemq.artemis.core.server.cluster.ha.HAPolicy)15 ColocatedActivation (org.apache.activemq.artemis.core.server.impl.ColocatedActivation)15 LiveOnlyActivation (org.apache.activemq.artemis.core.server.impl.LiveOnlyActivation)15 SharedNothingLiveActivation (org.apache.activemq.artemis.core.server.impl.SharedNothingLiveActivation)15 SharedStoreBackupActivation (org.apache.activemq.artemis.core.server.impl.SharedStoreBackupActivation)15 SharedStoreLiveActivation (org.apache.activemq.artemis.core.server.impl.SharedStoreLiveActivation)15 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)14 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)10 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)9 ScaleDownPolicy (org.apache.activemq.artemis.core.server.cluster.ha.ScaleDownPolicy)9 ActiveMQJAASSecurityManager (org.apache.activemq.artemis.spi.core.security.ActiveMQJAASSecurityManager)9 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)8 TransportConfiguration (org.apache.activemq.artemis.api.core.TransportConfiguration)8