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 @@ -82,6 +82,8 @@ public static String getMirrorAddress(String connectionName) {

private final Map<SimpleString, RoutingType> prefixes = new HashMap<>();

private final Map<SimpleString, RoutingType> temporaryPrefixes = new HashMap<>();

/**
* minLargeMessageSize determines when a message should be considered as large. minLargeMessageSize = -1 basically
* disables large message control over AMQP.
Expand Down Expand Up @@ -391,11 +393,32 @@ public void setMulticastPrefix(String multicastPrefix) {
}
}

@Override
public void setTemporaryAnycastPrefix(String temporaryAnycastPrefix) {
for (String prefix : temporaryAnycastPrefix.split(",")) {
prefixes.put(SimpleString.of(prefix), RoutingType.ANYCAST);
temporaryPrefixes.put(SimpleString.of(prefix), RoutingType.ANYCAST);
}
}

@Override
public void setTemporaryMulticastPrefix(String temporaryMulticastPrefix) {
for (String prefix : temporaryMulticastPrefix.split(",")) {
prefixes.put(SimpleString.of(prefix), RoutingType.MULTICAST);
temporaryPrefixes.put(SimpleString.of(prefix), RoutingType.MULTICAST);
}
}

@Override
public Map<SimpleString, RoutingType> getPrefixes() {
return prefixes;
}

@Override
public Map<SimpleString, RoutingType> getTemporaryPrefixes() {
return temporaryPrefixes;
}

@Override
public AMQPRoutingHandler getRoutingHandler() {
return routingHandler;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,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 @@ -883,7 +883,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 @@ -163,6 +163,8 @@ public OpenWireProtocolManager setOpenwireMaxPacketChunkSize(int openwireMaxPack

private final Map<SimpleString, RoutingType> prefixes = new HashMap<>();

private final Map<SimpleString, RoutingType> temporaryPrefixes = new HashMap<>();

private final List<OpenWireInterceptor> incomingInterceptors = new ArrayList<>();
private final List<OpenWireInterceptor> outgoingInterceptors = new ArrayList<>();

Expand Down Expand Up @@ -686,11 +688,32 @@ public void setMulticastPrefix(String multicastPrefix) {
}
}

@Override
public void setTemporaryAnycastPrefix(String temporaryAnycastPrefix) {
for (String prefix : temporaryAnycastPrefix.split(",")) {
prefixes.put(SimpleString.of(prefix), RoutingType.ANYCAST);
temporaryPrefixes.put(SimpleString.of(prefix), RoutingType.ANYCAST);
}
}

@Override
public void setTemporaryMulticastPrefix(String temporaryMulticastPrefix) {
for (String prefix : temporaryMulticastPrefix.split(",")) {
prefixes.put(SimpleString.of(prefix), RoutingType.MULTICAST);
temporaryPrefixes.put(SimpleString.of(prefix), RoutingType.MULTICAST);
}
}

@Override
public Map<SimpleString, RoutingType> getPrefixes() {
return prefixes;
}

@Override
public Map<SimpleString, RoutingType> getTemporaryPrefixes() {
return temporaryPrefixes;
}

@Override
public void setSecurityDomain(String securityDomain) {
this.securityDomain = securityDomain;
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 @@ -191,7 +191,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 @@ -94,6 +94,8 @@ public class CoreProtocolManager implements ProtocolManager<Interceptor, ActiveM

private final Map<SimpleString, RoutingType> prefixes = new HashMap<>();

private final Map<SimpleString, RoutingType> temporaryPrefixes = new HashMap<>();

private String securityDomain;

private final ActiveMQRoutingHandler routingHandler;
Expand Down Expand Up @@ -227,11 +229,32 @@ public void setMulticastPrefix(String multicastPrefix) {
}
}

@Override
public void setTemporaryAnycastPrefix(String temporaryAnycastPrefix) {
for (String prefix : temporaryAnycastPrefix.split(",")) {
prefixes.put(SimpleString.of(prefix), RoutingType.ANYCAST);
temporaryPrefixes.put(SimpleString.of(prefix), RoutingType.ANYCAST);
}
}

@Override
public void setTemporaryMulticastPrefix(String temporaryMulticastPrefix) {
for (String prefix : temporaryMulticastPrefix.split(",")) {
prefixes.put(SimpleString.of(prefix), RoutingType.MULTICAST);
temporaryPrefixes.put(SimpleString.of(prefix), RoutingType.MULTICAST);
}
}

@Override
public Map<SimpleString, RoutingType> getPrefixes() {
return prefixes;
}

@Override
public Map<SimpleString, RoutingType> getTemporaryPrefixes() {
return temporaryPrefixes;
}

@Override
public void setSecurityDomain(String securityDomain) {
this.securityDomain = securityDomain;
Expand Down
Loading