Search in sources :

Example 6 with NamedAddressSpace

use of org.apache.qpid.server.model.NamedAddressSpace in project qpid-broker-j by apache.

the class AMQChannel method receiveQueueUnbind.

@Override
public void receiveQueueUnbind(final AMQShortString queueName, final AMQShortString exchange, final AMQShortString bindingKey, final FieldTable arguments) {
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("RECV[" + _channelId + "] QueueUnbind[" + " queue: " + queueName + " exchange: " + exchange + " bindingKey: " + bindingKey + " arguments: " + arguments + " ]");
    }
    NamedAddressSpace virtualHost = _connection.getAddressSpace();
    final boolean useDefaultQueue = queueName == null;
    final Queue<?> queue = useDefaultQueue ? getDefaultQueue() : getQueue(queueName.toString());
    if (queue == null) {
        String message = useDefaultQueue ? "No default queue defined on channel and queue was null" : "Queue '" + queueName + "' does not exist.";
        closeChannel(ErrorCodes.NOT_FOUND, message);
    } else if (isDefaultExchange(exchange)) {
        _connection.sendConnectionClose(ErrorCodes.NOT_ALLOWED, "Cannot unbind the queue '" + queue.getName() + "' from the default exchange", getChannelId());
    } else {
        final Exchange<?> exch = getExchange(exchange.toString());
        if (exch == null) {
            closeChannel(ErrorCodes.NOT_FOUND, "Exchange '" + exchange + "' does not exist.");
        } else if (!exch.hasBinding(AMQShortString.toString(bindingKey), queue)) {
            closeChannel(ErrorCodes.NOT_FOUND, "No such binding");
        } else {
            try {
                exch.deleteBinding(AMQShortString.toString(bindingKey), queue);
                final AMQMethodBody responseBody = _connection.getMethodRegistry().createQueueUnbindOkBody();
                sync();
                _connection.writeFrame(responseBody.generateFrame(getChannelId()));
            } catch (AccessControlException e) {
                _connection.sendConnectionClose(ErrorCodes.ACCESS_REFUSED, e.getMessage(), getChannelId());
            }
        }
    }
}
Also used : Exchange(org.apache.qpid.server.model.Exchange) NamedAddressSpace(org.apache.qpid.server.model.NamedAddressSpace) AccessControlException(java.security.AccessControlException)

Example 7 with NamedAddressSpace

use of org.apache.qpid.server.model.NamedAddressSpace in project qpid-broker-j by apache.

the class AMQChannel method receiveBasicGet.

@Override
public void receiveBasicGet(final AMQShortString queueName, final boolean noAck) {
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("RECV[" + _channelId + "] BasicGet[" + " queue: " + queueName + " noAck: " + noAck + " ]");
    }
    NamedAddressSpace vHost = _connection.getAddressSpace();
    sync();
    MessageSource queue = queueName == null ? getDefaultQueue() : vHost.getAttainedMessageSource(queueName.toString());
    if (queue == null) {
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("No queue for '" + queueName + "'");
        }
        if (queueName != null) {
            _connection.sendConnectionClose(ErrorCodes.NOT_FOUND, "No such queue, '" + queueName + "'", _channelId);
        } else {
            _connection.sendConnectionClose(ErrorCodes.NOT_ALLOWED, "No queue name provided, no default queue defined.", _channelId);
        }
    } else {
        try {
            if (!performGet(queue, !noAck)) {
                MethodRegistry methodRegistry = _connection.getMethodRegistry();
                BasicGetEmptyBody responseBody = methodRegistry.createBasicGetEmptyBody(null);
                _connection.writeFrame(responseBody.generateFrame(_channelId));
            }
        } catch (AccessControlException e) {
            _connection.sendConnectionClose(ErrorCodes.ACCESS_REFUSED, e.getMessage(), _channelId);
        } catch (MessageSource.ExistingExclusiveConsumer e) {
            _connection.sendConnectionClose(ErrorCodes.NOT_ALLOWED, "Queue has an exclusive consumer", _channelId);
        } catch (MessageSource.ExistingConsumerPreventsExclusive e) {
            _connection.sendConnectionClose(ErrorCodes.INTERNAL_ERROR, "The GET request has been evaluated as an exclusive consumer, " + "this is likely due to a programming error in the Qpid broker", _channelId);
        } catch (MessageSource.ConsumerAccessRefused consumerAccessRefused) {
            _connection.sendConnectionClose(ErrorCodes.NOT_ALLOWED, "Queue has an incompatible exclusivity policy", _channelId);
        } catch (MessageSource.QueueDeleted queueDeleted) {
            _connection.sendConnectionClose(ErrorCodes.NOT_FOUND, "Queue has been deleted", _channelId);
        }
    }
}
Also used : NamedAddressSpace(org.apache.qpid.server.model.NamedAddressSpace) MessageSource(org.apache.qpid.server.message.MessageSource) AccessControlException(java.security.AccessControlException)

Example 8 with NamedAddressSpace

use of org.apache.qpid.server.model.NamedAddressSpace in project qpid-broker-j by apache.

the class AMQChannel method receiveBasicConsume.

@Override
public void receiveBasicConsume(final AMQShortString queue, final AMQShortString consumerTag, final boolean noLocal, final boolean noAck, final boolean exclusive, final boolean nowait, final FieldTable arguments) {
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("RECV[" + _channelId + "] BasicConsume[" + " queue: " + queue + " consumerTag: " + consumerTag + " noLocal: " + noLocal + " noAck: " + noAck + " exclusive: " + exclusive + " nowait: " + nowait + " arguments: " + arguments + " ]");
    }
    AMQShortString consumerTag1 = consumerTag;
    NamedAddressSpace vHost = _connection.getAddressSpace();
    sync();
    String queueName = AMQShortString.toString(queue);
    MessageSource queue1 = queueName == null ? getDefaultQueue() : vHost.getAttainedMessageSource(queueName);
    final Collection<MessageSource> sources = new HashSet<>();
    if (arguments != null && arguments.get("x-multiqueue") instanceof Collection) {
        for (Object object : (Collection<Object>) arguments.get("x-multiqueue")) {
            String sourceName = String.valueOf(object);
            sourceName = sourceName.trim();
            if (sourceName.length() != 0) {
                MessageSource source = vHost.getAttainedMessageSource(sourceName);
                if (source == null) {
                    sources.clear();
                    break;
                } else {
                    sources.add(source);
                }
            }
        }
        queueName = arguments.get("x-multiqueue").toString();
    } else if (queue1 != null) {
        sources.add(queue1);
    }
    if (sources.isEmpty()) {
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("No queue for '" + queueName + "'");
        }
        if (queueName != null) {
            closeChannel(ErrorCodes.NOT_FOUND, "No such queue, '" + queueName + "'");
        } else {
            _connection.sendConnectionClose(ErrorCodes.NOT_ALLOWED, "No queue name provided, no default queue defined.", _channelId);
        }
    } else {
        try {
            consumerTag1 = consumeFromSource(consumerTag1, sources, !noAck, arguments, exclusive, noLocal);
            if (!nowait) {
                MethodRegistry methodRegistry = _connection.getMethodRegistry();
                AMQMethodBody responseBody = methodRegistry.createBasicConsumeOkBody(consumerTag1);
                _connection.writeFrame(responseBody.generateFrame(_channelId));
            }
        } catch (ConsumerTagInUseException cte) {
            _connection.sendConnectionClose(ErrorCodes.NOT_ALLOWED, "Non-unique consumer tag, '" + consumerTag1 + "'", _channelId);
        } catch (AMQInvalidArgumentException ise) {
            _connection.sendConnectionClose(ErrorCodes.ARGUMENT_INVALID, ise.getMessage(), _channelId);
        } catch (Queue.ExistingExclusiveConsumer e) {
            _connection.sendConnectionClose(ErrorCodes.ACCESS_REFUSED, "Cannot subscribe to queue '" + queue1.getName() + "' as it already has an existing exclusive consumer", _channelId);
        } catch (Queue.ExistingConsumerPreventsExclusive e) {
            _connection.sendConnectionClose(ErrorCodes.ACCESS_REFUSED, "Cannot subscribe to queue '" + queue1.getName() + "' exclusively as it already has a consumer", _channelId);
        } catch (AccessControlException e) {
            _connection.sendConnectionClose(ErrorCodes.ACCESS_REFUSED, "Cannot subscribe to queue '" + queue1.getName() + "' permission denied", _channelId);
        } catch (MessageSource.ConsumerAccessRefused consumerAccessRefused) {
            _connection.sendConnectionClose(ErrorCodes.ACCESS_REFUSED, "Cannot subscribe to queue '" + queue1.getName() + "' as it already has an incompatible exclusivity policy", _channelId);
        } catch (MessageSource.QueueDeleted queueDeleted) {
            _connection.sendConnectionClose(ErrorCodes.NOT_FOUND, "Cannot subscribe to queue '" + queue1.getName() + "' as it has been deleted", _channelId);
        }
    }
}
Also used : AMQInvalidArgumentException(org.apache.qpid.server.filter.AMQInvalidArgumentException) NamedAddressSpace(org.apache.qpid.server.model.NamedAddressSpace) MessageSource(org.apache.qpid.server.message.MessageSource) AccessControlException(java.security.AccessControlException) Collection(java.util.Collection) AbstractConfiguredObject(org.apache.qpid.server.model.AbstractConfiguredObject) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) Queue(org.apache.qpid.server.model.Queue) HashSet(java.util.HashSet)

Example 9 with NamedAddressSpace

use of org.apache.qpid.server.model.NamedAddressSpace in project qpid-broker-j by apache.

the class OAuth2AuthenticationProviderImplTest method testAuthenticateViaAuthorizationCode.

public void testAuthenticateViaAuthorizationCode() throws Exception {
    Map<String, OAuth2MockEndpoint> mockEndpoints = new HashMap<>();
    mockEndpoints.put(TEST_TOKEN_ENDPOINT_PATH, createMockTokenEndpoint());
    mockEndpoints.put(TEST_IDENTITY_RESOLVER_ENDPOINT_PATH, createMockIdentityResolverEndpoint());
    _server.setEndpoints(mockEndpoints);
    final NamedAddressSpace mockAddressSpace = mock(NamedAddressSpace.class);
    when(mockAddressSpace.getName()).thenReturn("mock");
    AuthenticationResult authenticationResult = _authProvider.authenticateViaAuthorizationCode(TEST_VALID_AUTHORIZATION_CODE, TEST_REDIRECT_URI, mockAddressSpace);
    assertSuccess(authenticationResult);
}
Also used : HashMap(java.util.HashMap) NamedAddressSpace(org.apache.qpid.server.model.NamedAddressSpace) AuthenticationResult(org.apache.qpid.server.security.auth.AuthenticationResult)

Example 10 with NamedAddressSpace

use of org.apache.qpid.server.model.NamedAddressSpace in project qpid-broker-j by apache.

the class VirtualHostAliasTest method testPriority.

public void testPriority() {
    NamedAddressSpace addressSpace = _port.getAddressSpace("blue");
    assertNotNull(addressSpace);
    assertEquals(_vhosts.get("blue"), addressSpace);
    addressSpace = _port.getAddressSpace("black");
    assertNotNull(addressSpace);
    assertEquals(_vhosts.get("black"), addressSpace);
    Map<String, Object> attributes = new HashMap<>();
    attributes.put(VirtualHostAlias.NAME, "matcher10");
    attributes.put(VirtualHostAlias.TYPE, PatternMatchingAlias.TYPE_NAME);
    attributes.put(VirtualHostAlias.PRIORITY, 10);
    attributes.put(PatternMatchingAlias.PATTERN, "bl.*");
    attributes.put(PatternMatchingAlias.VIRTUAL_HOST_NODE, _vhosts.get("purple").getParent());
    _port.createChild(VirtualHostAlias.class, attributes);
    addressSpace = _port.getAddressSpace("blue");
    assertNotNull(addressSpace);
    assertEquals(_vhosts.get("purple"), addressSpace);
    addressSpace = _port.getAddressSpace("black");
    assertNotNull(addressSpace);
    assertEquals(_vhosts.get("purple"), addressSpace);
    attributes = new HashMap<>();
    attributes.put(VirtualHostAlias.NAME, "matcher5");
    attributes.put(VirtualHostAlias.TYPE, PatternMatchingAlias.TYPE_NAME);
    attributes.put(VirtualHostAlias.PRIORITY, 5);
    attributes.put(PatternMatchingAlias.PATTERN, ".*u.*");
    attributes.put(PatternMatchingAlias.VIRTUAL_HOST_NODE, _vhosts.get("red").getParent());
    _port.createChild(VirtualHostAlias.class, attributes);
    addressSpace = _port.getAddressSpace("blue");
    assertNotNull(addressSpace);
    assertEquals(_vhosts.get("red"), addressSpace);
    addressSpace = _port.getAddressSpace("black");
    assertNotNull(addressSpace);
    assertEquals(_vhosts.get("purple"), addressSpace);
    addressSpace = _port.getAddressSpace("purple");
    assertNotNull(addressSpace);
    assertEquals(_vhosts.get("red"), addressSpace);
}
Also used : HashMap(java.util.HashMap) NamedAddressSpace(org.apache.qpid.server.model.NamedAddressSpace)

Aggregations

NamedAddressSpace (org.apache.qpid.server.model.NamedAddressSpace)42 AccessControlException (java.security.AccessControlException)22 HashMap (java.util.HashMap)12 MessageSource (org.apache.qpid.server.message.MessageSource)8 AbstractConfiguredObject (org.apache.qpid.server.model.AbstractConfiguredObject)8 Queue (org.apache.qpid.server.model.Queue)6 Collection (java.util.Collection)5 LinkedHashMap (java.util.LinkedHashMap)5 Map (java.util.Map)5 Symbol (org.apache.qpid.server.protocol.v1_0.type.Symbol)5 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)4 IllegalConfigurationException (org.apache.qpid.server.configuration.IllegalConfigurationException)4 MessageDestination (org.apache.qpid.server.message.MessageDestination)4 AmqpPort (org.apache.qpid.server.model.port.AmqpPort)4 ArrayList (java.util.ArrayList)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 Exchange (org.apache.qpid.server.model.Exchange)3 BaseSource (org.apache.qpid.server.protocol.v1_0.type.BaseSource)3 Source (org.apache.qpid.server.protocol.v1_0.type.messaging.Source)3 AmqpError (org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError)3