use of org.apache.activemq.artemis.api.core.ActiveMQClusterSecurityException in project activemq-artemis by apache.
the class ClusterControllerTest method controlWithDifferentPassword.
@Test
public void controlWithDifferentPassword() throws Exception {
try (ServerLocatorImpl locator = (ServerLocatorImpl) createInVMNonHALocator()) {
locator.setProtocolManagerFactory(ActiveMQServerSideProtocolManagerFactory.getInstance(locator));
ClusterController controller = new ClusterController(getServer(1), getServer(1).getScheduledPool());
ClusterControl clusterControl = controller.connectToNodeInCluster((ClientSessionFactoryInternal) locator.createSessionFactory());
try {
clusterControl.authorize();
fail("should throw ActiveMQClusterSecurityException");
} catch (Exception e) {
assertTrue("should throw ActiveMQClusterSecurityException", e instanceof ActiveMQClusterSecurityException);
}
}
}
use of org.apache.activemq.artemis.api.core.ActiveMQClusterSecurityException in project activemq-artemis by apache.
the class ActiveMQPacketHandler method handleCreateSession.
private void handleCreateSession(final CreateSessionMessage request) {
boolean incompatibleVersion = false;
Packet response;
try {
Version version = server.getVersion();
if (!version.isCompatible(request.getVersion())) {
throw ActiveMQMessageBundle.BUNDLE.incompatibleClientServer();
}
if (!server.isStarted()) {
throw ActiveMQMessageBundle.BUNDLE.serverNotStarted();
}
if (connection.getChannelVersion() == 0) {
connection.setChannelVersion(request.getVersion());
} else if (connection.getChannelVersion() != request.getVersion()) {
ActiveMQServerLogger.LOGGER.incompatibleVersionAfterConnect(request.getVersion(), connection.getChannelVersion());
}
Channel channel = connection.getChannel(request.getSessionChannelID(), request.getWindowSize());
ActiveMQPrincipal activeMQPrincipal = null;
if (request.getUsername() == null) {
activeMQPrincipal = connection.getDefaultActiveMQPrincipal();
}
OperationContext sessionOperationContext = server.newOperationContext();
Map<SimpleString, RoutingType> routingTypeMap = protocolManager.getPrefixes();
CoreSessionCallback sessionCallback = new CoreSessionCallback(request.getName(), protocolManager, channel, connection);
ServerSession session = server.createSession(request.getName(), activeMQPrincipal == null ? request.getUsername() : activeMQPrincipal.getUserName(), activeMQPrincipal == null ? request.getPassword() : activeMQPrincipal.getPassword(), request.getMinLargeMessageSize(), connection, request.isAutoCommitSends(), request.isAutoCommitAcks(), request.isPreAcknowledge(), request.isXA(), request.getDefaultAddress(), sessionCallback, true, sessionOperationContext, routingTypeMap);
ServerProducer serverProducer = new ServerProducerImpl(session.getName(), "CORE", request.getDefaultAddress());
session.addProducer(serverProducer);
ServerSessionPacketHandler handler = new ServerSessionPacketHandler(server, protocolManager, session, server.getStorageManager(), channel);
channel.setHandler(handler);
sessionCallback.setSessionHandler(handler);
// TODO - where is this removed?
protocolManager.addSessionHandler(request.getName(), handler);
response = new CreateSessionResponseMessage(server.getVersion().getIncrementingVersion());
} catch (ActiveMQClusterSecurityException | ActiveMQSecurityException e) {
ActiveMQServerLogger.LOGGER.securityProblemWhileCreatingSession(e.getMessage());
response = new ActiveMQExceptionMessage(e);
} catch (ActiveMQException e) {
if (e.getType() == ActiveMQExceptionType.INCOMPATIBLE_CLIENT_SERVER_VERSIONS) {
incompatibleVersion = true;
logger.debug("Sending ActiveMQException after Incompatible client", e);
} else {
ActiveMQServerLogger.LOGGER.failedToCreateSession(e);
}
response = new ActiveMQExceptionMessage(e);
} catch (Exception e) {
ActiveMQServerLogger.LOGGER.failedToCreateSession(e);
response = new ActiveMQExceptionMessage(new ActiveMQInternalErrorException());
}
// are not compatible
if (incompatibleVersion) {
channel1.sendAndFlush(response);
} else {
channel1.send(response);
}
}
Aggregations