use of org.apache.activemq.broker.Connector in project activemq-artemis by apache.
the class JaasDualAuthenticationBrokerTest method testInsecureConnector.
public void testInsecureConnector() {
Connector connector = new TransportConnector(nonSslTransportServer);
connectionContext.setConnector(connector);
connectionInfo.setUserName(INSECURE_USERNAME);
try {
authBroker.addConnection(connectionContext, connectionInfo);
} catch (Exception e) {
fail("Call to addConnection failed: " + e.getMessage());
}
assertEquals("Number of addConnection calls to underlying Broker must match number of calls made to " + "AuthenticationBroker.", 1, receiveBroker.addConnectionData.size());
ConnectionContext receivedContext = receiveBroker.addConnectionData.getFirst().connectionContext;
assertEquals("The SecurityContext's userName must be set to that of the UserPrincipal.", INSECURE_USERNAME, receivedContext.getSecurityContext().getUserName());
Set<Principal> receivedPrincipals = receivedContext.getSecurityContext().getPrincipals();
assertEquals("2 Principals received", 2, receivedPrincipals.size());
for (Iterator<Principal> iter = receivedPrincipals.iterator(); iter.hasNext(); ) {
Principal currentPrincipal = iter.next();
if (currentPrincipal instanceof UserPrincipal) {
assertEquals("UserPrincipal is '" + INSECURE_USERNAME + "'", INSECURE_USERNAME, currentPrincipal.getName());
} else if (currentPrincipal instanceof GroupPrincipal) {
assertEquals("GroupPrincipal is '" + INSECURE_GROUP + "'", INSECURE_GROUP, currentPrincipal.getName());
} else {
fail("Unexpected Principal subclass found.");
}
}
try {
authBroker.removeConnection(connectionContext, connectionInfo, null);
} catch (Exception e) {
fail("Call to removeConnection failed: " + e.getMessage());
}
assertEquals("Number of removeConnection calls to underlying Broker must match number of calls made to " + "AuthenticationBroker.", 1, receiveBroker.removeConnectionData.size());
}
use of org.apache.activemq.broker.Connector in project activemq-artemis by apache.
the class QueueOptimizedDispatchExceptionTest method TestOptimizedDispatchCME.
@Test
public void TestOptimizedDispatchCME() throws Exception {
final PersistenceAdapter persistenceAdapter = broker.getPersistenceAdapter();
final MessageStore queueMessageStore = persistenceAdapter.createQueueMessageStore(destination);
final ConnectionContext contextNotInTx = new ConnectionContext();
contextNotInTx.setConnection(new Connection() {
@Override
public void stop() throws Exception {
}
@Override
public void start() throws Exception {
}
@Override
public void updateClient(ConnectionControl control) {
}
@Override
public void serviceExceptionAsync(IOException e) {
}
@Override
public void serviceException(Throwable error) {
}
@Override
public Response service(Command command) {
return null;
}
@Override
public boolean isSlow() {
return false;
}
@Override
public boolean isNetworkConnection() {
return false;
}
@Override
public boolean isManageable() {
return false;
}
@Override
public boolean isFaultTolerantConnection() {
return false;
}
@Override
public boolean isConnected() {
return true;
}
@Override
public boolean isBlocked() {
return false;
}
@Override
public boolean isActive() {
return false;
}
@Override
public ConnectionStatistics getStatistics() {
return null;
}
@Override
public String getRemoteAddress() {
return null;
}
@Override
public int getDispatchQueueSize() {
return 0;
}
@Override
public Connector getConnector() {
// TODO Auto-generated method stub
return null;
}
@Override
public String getConnectionId() {
return null;
}
@Override
public void dispatchSync(Command message) {
}
@Override
public void dispatchAsync(Command command) {
}
@Override
public int getActiveTransactionCount() {
return 0;
}
@Override
public Long getOldestActiveTransactionDuration() {
return null;
}
});
final DestinationStatistics destinationStatistics = new DestinationStatistics();
final Queue queue = new Queue(broker, destination, queueMessageStore, destinationStatistics, broker.getTaskRunnerFactory());
final MockMemoryUsage usage = new MockMemoryUsage();
queue.setOptimizedDispatch(true);
queue.initialize();
queue.start();
queue.memoryUsage = usage;
ProducerBrokerExchange producerExchange = new ProducerBrokerExchange();
ProducerInfo producerInfo = new ProducerInfo();
ProducerState producerState = new ProducerState(producerInfo);
producerExchange.setProducerState(producerState);
producerExchange.setConnectionContext(contextNotInTx);
// populate the queue store, exceed memory limit so that cache is disabled
for (int i = 0; i < count; i++) {
Message message = getMessage(i);
queue.send(producerExchange, message);
}
usage.setFull(false);
try {
queue.wakeup();
} catch (Exception e) {
LOG.error("Queue threw an unexpected exception: " + e.toString());
fail("Should not throw an exception.");
}
}
use of org.apache.activemq.broker.Connector in project activemq-artemis by apache.
the class JaasDualAuthenticationBrokerTest method testSecureConnector.
public void testSecureConnector() {
Connector connector = new TransportConnector(sslTransportServer);
connectionContext.setConnector(connector);
connectionInfo.setTransportContext(new StubX509Certificate[] {});
try {
authBroker.addConnection(connectionContext, connectionInfo);
} catch (Exception e) {
fail("Call to addConnection failed: " + e.getMessage());
}
assertEquals("Number of addConnection calls to underlying Broker must match number of calls made to " + "AuthenticationBroker.", 1, receiveBroker.addConnectionData.size());
ConnectionContext receivedContext = receiveBroker.addConnectionData.getFirst().connectionContext;
assertEquals("The SecurityContext's userName must be set to that of the UserPrincipal.", DN_USERNAME, receivedContext.getSecurityContext().getUserName());
Set<Principal> receivedPrincipals = receivedContext.getSecurityContext().getPrincipals();
assertEquals("2 Principals received", 2, receivedPrincipals.size());
for (Iterator<Principal> iter = receivedPrincipals.iterator(); iter.hasNext(); ) {
Principal currentPrincipal = iter.next();
if (currentPrincipal instanceof UserPrincipal) {
assertEquals("UserPrincipal is '" + DN_USERNAME + "'", DN_USERNAME, currentPrincipal.getName());
} else if (currentPrincipal instanceof GroupPrincipal) {
assertEquals("GroupPrincipal is '" + DN_GROUP + "'", DN_GROUP, currentPrincipal.getName());
} else {
fail("Unexpected Principal subclass found.");
}
}
try {
authBroker.removeConnection(connectionContext, connectionInfo, null);
} catch (Exception e) {
fail("Call to removeConnection failed: " + e.getMessage());
}
assertEquals("Number of removeConnection calls to underlying Broker must match number of calls made to " + "AuthenticationBroker.", 1, receiveBroker.removeConnectionData.size());
}
Aggregations