Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -210,14 +210,14 @@ public void init(AMQPSessionContext protonSession, SASLResult saslResult) throws
false, // boolean autoCommitAcks,
false, // boolean preAcknowledge,
true, //boolean xa,
null, this, true, operationContext, manager.getPrefixes(), manager.getSecurityDomain(), false);
null, this, true, operationContext, manager.getPrefixes(), manager.getTemporaryPrefixes(), manager.getSecurityDomain(), false);
} else {
serverSession = manager.getServer().createSession(name, connection.getUser(), connection.getPassword(), ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE, protonSPI.getProtonConnectionDelegate(), // RemotingConnection remotingConnection,
false, // boolean autoCommitSends
false, // boolean autoCommitAcks,
false, // boolean preAcknowledge,
true, //boolean xa,
null, this, true, operationContext, manager.getPrefixes(), manager.getSecurityDomain(), connection.getValidatedUser(), false);
null, this, true, operationContext, manager.getPrefixes(), manager.getTemporaryPrefixes(), manager.getSecurityDomain(), connection.getValidatedUser(), false);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ ServerSessionImpl createServerSession(String username, String password, String v
MQTTUtil.SESSION_AUTO_CREATE_QUEUE,
session.getSessionContext(),
session.getProtocolManager().getPrefixes(),
session.getProtocolManager().getTemporaryPrefixes(),
session.getProtocolManager().getSecurityDomain(),
validatedUser,
false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,7 @@ private static int getSize(Command command) {
}

private void createInternalSession(ConnectionInfo info) throws Exception {
internalSession = server.createSession(UUIDGenerator.getInstance().generateStringUUID(), context.getUserName(), info.getPassword(), -1, this, true, false, false, false, null, null, true, operationContext, protocolManager.getPrefixes(), protocolManager.getSecurityDomain(), validatedUser, false);
internalSession = server.createSession(UUIDGenerator.getInstance().generateStringUUID(), context.getUserName(), info.getPassword(), -1, this, true, false, false, false, null, null, true, operationContext, protocolManager.getPrefixes(), protocolManager.getTemporaryPrefixes(), protocolManager.getSecurityDomain(), validatedUser, false);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public void initialize() {
// now

try {
coreSession = server.createSession(name, username, password, minLargeMessageSize, connection, true, false, false, false, null, this, true, connection.getOperationContext(), protocolManager.getPrefixes(), protocolManager.getSecurityDomain(), connection.getValidatedUser(), false);
coreSession = server.createSession(name, username, password, minLargeMessageSize, connection, true, false, false, false, null, this, true, connection.getOperationContext(), protocolManager.getPrefixes(), protocolManager.getTemporaryPrefixes(), protocolManager.getSecurityDomain(), connection.getValidatedUser(), false);
} catch (Exception e) {
logger.error("error init session", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void testActorStateVisibility() throws Exception {
ServerSession serverSession = Mockito.mock(ServerSession.class);
Mockito.when(serverSession.getName()).thenReturn("session");
Mockito.doReturn(serverSession).when(server).createSession(Mockito.anyString(), Mockito.any(), Mockito.any(), Mockito.anyInt(), Mockito.any(), Mockito.anyBoolean(), Mockito.anyBoolean(), Mockito.anyBoolean(),
Mockito.anyBoolean(), Mockito.any(), Mockito.any(), Mockito.anyBoolean(), Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.any(), Mockito.anyBoolean());
Mockito.anyBoolean(), Mockito.any(), Mockito.any(), Mockito.anyBoolean(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.any(), Mockito.anyBoolean());

OpenWireProtocolManager openWireProtocolManager = new OpenWireProtocolManager(null, server, null, null);
openWireProtocolManager.setSecurityDomain("securityDomain");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void testNullPrimaryOnNodeUp() throws Exception {
Mockito.when(securityStore.authenticate(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(null);
ServerSession serverSession = Mockito.mock(ServerSession.class);
Mockito.when(serverSession.getName()).thenReturn("session");
Mockito.doReturn(serverSession).when(server).createSession(Mockito.anyString(), Mockito.any(), Mockito.any(), Mockito.anyInt(), Mockito.any(), Mockito.anyBoolean(), Mockito.anyBoolean(), Mockito.anyBoolean(), Mockito.anyBoolean(), Mockito.any(), Mockito.any(), Mockito.anyBoolean(), Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.any(), Mockito.anyBoolean());
Mockito.doReturn(serverSession).when(server).createSession(Mockito.anyString(), Mockito.any(), Mockito.any(), Mockito.anyInt(), Mockito.any(), Mockito.anyBoolean(), Mockito.anyBoolean(), Mockito.anyBoolean(), Mockito.anyBoolean(), Mockito.any(), Mockito.any(), Mockito.anyBoolean(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.any(), Mockito.anyBoolean());

OpenWireProtocolManager openWireProtocolManager = new OpenWireProtocolManager(null, server, null, null);
openWireProtocolManager.setSecurityDomain("securityDomain");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -486,9 +486,10 @@ StompPostReceiptFunction subscribe(String destination,
String durableSubscriptionName,
boolean noLocal,
RoutingType subscriptionType,
Integer consumerWindowSize) throws ActiveMQStompException {
Integer consumerWindowSize,
boolean temporary) throws ActiveMQStompException {
validateSelector(selector);
checkAutoCreate(destination, subscriptionType);
checkAutoCreate(destination, subscriptionType, temporary);
String subscriptionID = getSubscriptionID(destination, id);

try {
Expand All @@ -507,11 +508,15 @@ StompPostReceiptFunction subscribe(String destination,
}
}

protected void checkAutoCreate(String destination, RoutingType subscriptionType) throws ActiveMQStompException {
protected void checkAutoCreate(String destination, RoutingType subscriptionType, boolean temporary) throws ActiveMQStompException {
AutoCreateResult autoCreateResult;
try {
RoutingType routingType = getSubscriptionRoutingType(destination, subscriptionType);
autoCreateResult = getSession().getCoreSession().checkAutoCreate(QueueConfiguration.of(destination).setRoutingType(routingType));
QueueConfiguration queueConfiguration = QueueConfiguration.of(destination).setRoutingType(routingType);
if (temporary) {
queueConfiguration.setTemporary(true).setDurable(false);
}
autoCreateResult = getSession().getCoreSession().checkAutoCreate(queueConfiguration);
} catch (Exception e) {
logger.debug("Exception while auto-creating destination", e);
throw new ActiveMQStompException(e.getMessage(), e).setHandler(frameHandler);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ private StompSession internalGetSession(StompConnection connection, Map<Object,
stompSession = new StompSession(connection, this, server.getStorageManager().newContext(connection.getTransportConnection().getEventLoop()));
String name = UUIDGenerator.getInstance().generateStringUUID();
final String validatedUser = server.validateUser(connection.getLogin(), connection.getPasscode(), connection, getSecurityDomain());
ServerSession session = server.createSession(name, connection.getLogin(), connection.getPasscode(), ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE, connection, !transacted, false, false, false, null, stompSession, true, server.newOperationContext(), getPrefixes(), getSecurityDomain(), validatedUser, false);
ServerSession session = server.createSession(name, connection.getLogin(), connection.getPasscode(), ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE, connection, !transacted, false, false, false, null, stompSession, true, server.newOperationContext(), getPrefixes(), getTemporaryPrefixes(), getSecurityDomain(), validatedUser, false);
stompSession.setServerSession(session);
sessions.put(id, stompSession);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import org.apache.activemq.artemis.api.core.ActiveMQBuffer;
import org.apache.activemq.artemis.api.core.ActiveMQException;
import org.apache.activemq.artemis.api.core.ActiveMQSecurityException;
import org.apache.activemq.artemis.api.core.ICoreMessage;
import org.apache.activemq.artemis.api.core.Message;
import org.apache.activemq.artemis.api.core.RoutingType;
Expand Down Expand Up @@ -190,7 +191,8 @@ public StompFrame onSend(StompFrame frame) {
connection.validate();
String destination = getDestination(frame);
RoutingType routingType = getRoutingType(frame.getHeader(Headers.Send.DESTINATION_TYPE), frame.getHeader(Headers.Send.DESTINATION));
connection.checkAutoCreate(destination, routingType);
boolean temporary = isTemporaryDestination(frame.getHeader(Headers.Send.DESTINATION));
connection.checkAutoCreate(destination, routingType, temporary);
String txID = frame.getHeader(Stomp.Headers.TRANSACTION);

long timestamp = System.currentTimeMillis();
Expand Down Expand Up @@ -271,6 +273,7 @@ public StompPostReceiptFunction onSubscribe(StompFrame frame) throws Exception {
}
}
RoutingType routingType = getRoutingType(frame.getHeader(Headers.Subscribe.SUBSCRIPTION_TYPE), frame.getHeader(Headers.Subscribe.DESTINATION));
boolean temporary = isTemporaryDestination(frame.getHeader(Headers.Subscribe.DESTINATION));
boolean noLocal = false;
if (frame.hasHeader(Stomp.Headers.Subscribe.NO_LOCAL)) {
noLocal = Boolean.parseBoolean(frame.getHeader(Stomp.Headers.Subscribe.NO_LOCAL));
Expand All @@ -283,7 +286,19 @@ public StompPostReceiptFunction onSubscribe(StompFrame frame) throws Exception {
} else if (frame.hasHeader(Headers.Subscribe.ACTIVEMQ_PREFETCH_SIZE)) {
consumerWindowSize = Integer.parseInt(frame.getHeader(Stomp.Headers.Subscribe.ACTIVEMQ_PREFETCH_SIZE));
}
return connection.subscribe(destination, selector, ack, id, durableSubscriptionName, noLocal, routingType, consumerWindowSize);
return connection.subscribe(destination, selector, ack, id, durableSubscriptionName, noLocal, routingType, consumerWindowSize, temporary);
}

/**
* The address on a SEND/SUBSCRIBE frame may already have had a temporary prefix stripped from it by
* {@link #getDestination(StompFrame)} by the time it reaches most of this class, so this must be checked against
* the raw (un-stripped) destination header, the same way {@link #getRoutingType} is resolved from the raw header.
*/
private boolean isTemporaryDestination(String rawDestination) throws ActiveMQStompException, ActiveMQSecurityException {
if (rawDestination == null) {
return false;
}
return connection.getSession().getCoreSession().getRoutingTypeFromTemporaryPrefix(SimpleString.of(rawDestination)) != null;
}

public String getDestination(StompFrame request) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ protected String sendMessage(SimpleString address,
Integer.MAX_VALUE, fakeConnection,
true, true, false,
false, address.toString(), fakeConnection.callback,
false, new DummyOperationContext(), Collections.emptyMap(), null, validatedUser, false);
false, new DummyOperationContext(), Collections.emptyMap(), Collections.emptyMap(), null, validatedUser, false);
try {
CoreMessage message = new CoreMessage(storageManager.generateID(), 50);
if (headers != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ private void handleCreateSession(final CreateSessionMessage request) {

CoreSessionCallback sessionCallback = new CoreSessionCallback(request.getName(), protocolManager, channel, connection);
boolean isLegacyProducer = request.getVersion() < PacketImpl.ARTEMIS_2_28_0_VERSION;
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, protocolManager.getSecurityDomain(), validatedUser, isLegacyProducer);
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, protocolManager.getTemporaryPrefixes(), protocolManager.getSecurityDomain(), validatedUser, isLegacyProducer);
ServerSessionPacketHandler handler = new ServerSessionPacketHandler(server, session, channel);
channel.setHandler(handler);
sessionCallback.setSessionHandler(handler);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ ServerSession createSession(String name,
boolean autoCreateQueues,
OperationContext context,
Map<SimpleString, RoutingType> prefixes,
Map<SimpleString, RoutingType> temporaryPrefixes,
String securityDomain,
String validatedUser,
boolean isLegacyProducer) throws Exception;
Expand All @@ -402,6 +403,7 @@ ServerSession createInternalSession(String name,
boolean autoCreateQueues,
OperationContext context,
Map<SimpleString, RoutingType> prefixes,
Map<SimpleString, RoutingType> temporaryPrefixes,
String securityDomain,
boolean isLegacyProducer) throws Exception;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,17 @@ void createSharedQueue(SimpleString address,

RoutingType getRoutingTypeFromPrefix(SimpleString address, RoutingType defaultRoutingType);

/**
* Returns the routing type registered for {@code address} under one of this session's temporary prefixes (e.g.
* {@code temporaryAnycastPrefix}/{@code temporaryMulticastPrefix}), or {@code null} if {@code address} doesn't
* match any of them. A non-null result means the resource being created for this address should be forced
* temporary, regardless of what the client requested.
*
* @param address the address to inspect
* @return the {@code RoutingType} registered for the matching temporary prefix, or {@code null} if none match
*/
RoutingType getRoutingTypeFromTemporaryPrefix(SimpleString address);

/**
* Get the canonical (i.e. non-prefixed) address and the corresponding routing-type.
*
Expand Down
Loading