Search in sources :

Example 41 with IllegalConfigurationException

use of org.apache.qpid.server.configuration.IllegalConfigurationException in project qpid-broker-j by apache.

the class BoneCPConnectionProvider method createBoneCPConfig.

static BoneCPConfig createBoneCPConfig(final String connectionUrl, final String username, final String password, final Map<String, String> providerAttributes) {
    BoneCPConfig config = new BoneCPConfig();
    config.setJdbcUrl(connectionUrl);
    if (username != null) {
        config.setUsername(username);
        config.setPassword(password);
    }
    Map<String, String> attributes = new HashMap<>(providerAttributes);
    attributes.putIfAbsent(MIN_CONNECTIONS_PER_PARTITION, String.valueOf(DEFAULT_MIN_CONNECTIONS_PER_PARTITION));
    attributes.putIfAbsent(MAX_CONNECTIONS_PER_PARTITION, String.valueOf(DEFAULT_MAX_CONNECTIONS_PER_PARTITION));
    attributes.putIfAbsent(PARTITION_COUNT, String.valueOf(DEFAULT_PARTITION_COUNT));
    Map<String, String> propertiesMap = attributes.entrySet().stream().collect(Collectors.toMap(p -> p.getKey().substring(JDBCSTORE_PREFIX.length()), Map.Entry::getValue));
    Properties properties = new Properties();
    properties.putAll(propertiesMap);
    try {
        config.setProperties(properties);
    } catch (Exception e) {
        throw new IllegalConfigurationException("Unexpected exception on applying BoneCP configuration", e);
    }
    return config;
}
Also used : JDBCSTORE_PREFIX(org.apache.qpid.server.store.jdbc.bonecp.BoneCPConnectionProviderFactory.JDBCSTORE_PREFIX) Connection(java.sql.Connection) Properties(java.util.Properties) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) HashMap(java.util.HashMap) Collectors(java.util.stream.Collectors) MAX_CONNECTIONS_PER_PARTITION(org.apache.qpid.server.store.jdbc.bonecp.BoneCPConnectionProviderFactory.MAX_CONNECTIONS_PER_PARTITION) PARTITION_COUNT(org.apache.qpid.server.store.jdbc.bonecp.BoneCPConnectionProviderFactory.PARTITION_COUNT) SQLException(java.sql.SQLException) BoneCP(com.jolbox.bonecp.BoneCP) Map(java.util.Map) ServerScopedRuntimeException(org.apache.qpid.server.util.ServerScopedRuntimeException) MIN_CONNECTIONS_PER_PARTITION(org.apache.qpid.server.store.jdbc.bonecp.BoneCPConnectionProviderFactory.MIN_CONNECTIONS_PER_PARTITION) ConnectionProvider(org.apache.qpid.server.store.jdbc.ConnectionProvider) BoneCPConfig(com.jolbox.bonecp.BoneCPConfig) HashMap(java.util.HashMap) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) BoneCPConfig(com.jolbox.bonecp.BoneCPConfig) Properties(java.util.Properties) HashMap(java.util.HashMap) Map(java.util.Map) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) SQLException(java.sql.SQLException) ServerScopedRuntimeException(org.apache.qpid.server.util.ServerScopedRuntimeException)

Example 42 with IllegalConfigurationException

use of org.apache.qpid.server.configuration.IllegalConfigurationException in project qpid-broker-j by apache.

the class JDBCSystemConfigTest method testInvalidTableNamePrefix.

public void testInvalidTableNamePrefix() throws Exception {
    final TaskExecutor taskExecutor = new CurrentThreadTaskExecutor();
    final EventLogger eventLogger = mock(EventLogger.class);
    final Principal systemPrincipal = mock(Principal.class);
    JDBCSystemConfig<?> jdbcSystemConfig = new JDBCSystemConfigImpl(taskExecutor, eventLogger, systemPrincipal, Collections.<String, Object>emptyMap());
    // This list is not exhaustive
    List<String> knownInvalidPrefixes = Arrays.asList("with\"dblquote", "with'quote", "with-dash", "with;semicolon", "with space", "with%percent", "with|pipe", "with(paren", "with)paren", "with[bracket", "with]bracket", "with{brace", "with}brace");
    for (String invalidPrefix : knownInvalidPrefixes) {
        try {
            jdbcSystemConfig.setAttributes(Collections.<String, Object>singletonMap("tableNamePrefix", invalidPrefix));
            fail(String.format("Should not be able to set prefix to '%s'", invalidPrefix));
        } catch (IllegalConfigurationException e) {
        // pass
        }
    }
}
Also used : CurrentThreadTaskExecutor(org.apache.qpid.server.configuration.updater.CurrentThreadTaskExecutor) TaskExecutor(org.apache.qpid.server.configuration.updater.TaskExecutor) EventLogger(org.apache.qpid.server.logging.EventLogger) CurrentThreadTaskExecutor(org.apache.qpid.server.configuration.updater.CurrentThreadTaskExecutor) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) Principal(java.security.Principal)

Example 43 with IllegalConfigurationException

use of org.apache.qpid.server.configuration.IllegalConfigurationException in project qpid-broker-j by apache.

the class JDBCVirtualHostTest method testInvalidTableNamePrefix.

public void testInvalidTableNamePrefix() throws Exception {
    final VirtualHostNode vhn = mock(VirtualHostNode.class);
    when(vhn.getCategoryClass()).thenReturn(VirtualHostNode.class);
    when(vhn.getChildExecutor()).thenReturn(_taskExecutor);
    final ConfiguredObjectFactoryImpl factory = new ConfiguredObjectFactoryImpl(BrokerModel.getInstance());
    when(vhn.getObjectFactory()).thenReturn(factory);
    when(vhn.getModel()).thenReturn(factory.getModel());
    EventLogger eventLogger = mock(EventLogger.class);
    SystemConfig systemConfig = mock(SystemConfig.class);
    when(systemConfig.getEventLogger()).thenReturn(eventLogger);
    Broker broker = mock(Broker.class);
    when(broker.getParent()).thenReturn(systemConfig);
    when(vhn.getParent()).thenReturn(broker);
    Map<String, Object> attributes = new HashMap<>();
    attributes.put(ConfiguredObject.NAME, getTestName());
    attributes.put(ConfiguredObject.TYPE, JDBCVirtualHostImpl.VIRTUAL_HOST_TYPE);
    attributes.put("connectionUrl", "jdbc://example.com");
    JDBCVirtualHost<?> jdbcVirtualHost = new JDBCVirtualHostImpl(attributes, vhn);
    // This list is not exhaustive
    List<String> knownInvalidPrefixes = Arrays.asList("with\"dblquote", "with'quote", "with-dash", "with;semicolon", "with space", "with%percent", "with|pipe", "with(paren", "with)paren", "with[bracket", "with]bracket", "with{brace", "with}brace");
    for (String invalidPrefix : knownInvalidPrefixes) {
        try {
            jdbcVirtualHost.setAttributes(Collections.<String, Object>singletonMap("tableNamePrefix", invalidPrefix));
            fail(String.format("Should not be able to set prefix to '%s'", invalidPrefix));
        } catch (IllegalConfigurationException e) {
        // pass
        }
    }
}
Also used : SystemConfig(org.apache.qpid.server.model.SystemConfig) Broker(org.apache.qpid.server.model.Broker) EventLogger(org.apache.qpid.server.logging.EventLogger) HashMap(java.util.HashMap) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) VirtualHostNode(org.apache.qpid.server.model.VirtualHostNode) ConfiguredObjectFactoryImpl(org.apache.qpid.server.model.ConfiguredObjectFactoryImpl)

Example 44 with IllegalConfigurationException

use of org.apache.qpid.server.configuration.IllegalConfigurationException in project qpid-broker-j by apache.

the class AMQChannel method receiveExchangeDeclare.

@Override
public void receiveExchangeDeclare(final AMQShortString exchangeName, final AMQShortString type, final boolean passive, final boolean durable, final boolean autoDelete, final boolean internal, final boolean nowait, final FieldTable arguments) {
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("RECV[" + _channelId + "] ExchangeDeclare[" + " exchange: " + exchangeName + " type: " + type + " passive: " + passive + " durable: " + durable + " autoDelete: " + autoDelete + " internal: " + internal + " nowait: " + nowait + " arguments: " + arguments + " ]");
    }
    final MethodRegistry methodRegistry = _connection.getMethodRegistry();
    final AMQMethodBody declareOkBody = methodRegistry.createExchangeDeclareOkBody();
    Exchange<?> exchange;
    NamedAddressSpace virtualHost = _connection.getAddressSpace();
    if (isDefaultExchange(exchangeName)) {
        if (!new AMQShortString(ExchangeDefaults.DIRECT_EXCHANGE_CLASS).equals(type)) {
            _connection.sendConnectionClose(ErrorCodes.NOT_ALLOWED, "Attempt to redeclare default exchange: " + " of type " + ExchangeDefaults.DIRECT_EXCHANGE_CLASS + " to " + type + ".", getChannelId());
        } else if (!nowait) {
            sync();
            _connection.writeFrame(declareOkBody.generateFrame(getChannelId()));
        }
    } else {
        if (passive) {
            exchange = getExchange(exchangeName.toString());
            if (exchange == null) {
                closeChannel(ErrorCodes.NOT_FOUND, "Unknown exchange: '" + exchangeName + "'");
            } else if (!(type == null || type.length() == 0) && !exchange.getType().equals(type.toString())) {
                _connection.sendConnectionClose(ErrorCodes.NOT_ALLOWED, "Attempt to redeclare exchange: '" + exchangeName + "' of type " + exchange.getType() + " to " + type + ".", getChannelId());
            } else if (!nowait) {
                sync();
                _connection.writeFrame(declareOkBody.generateFrame(getChannelId()));
            }
        } else {
            String name = exchangeName.toString();
            String typeString = type == null ? null : type.toString();
            try {
                Map<String, Object> attributes = new HashMap<String, Object>();
                if (arguments != null) {
                    attributes.putAll(FieldTable.convertToMap(arguments));
                }
                attributes.put(Exchange.NAME, name);
                attributes.put(Exchange.TYPE, typeString);
                attributes.put(Exchange.DURABLE, durable);
                attributes.put(Exchange.LIFETIME_POLICY, autoDelete ? LifetimePolicy.DELETE_ON_NO_LINKS : LifetimePolicy.PERMANENT);
                Object alternateExchange = attributes.remove(ALTERNATE_EXCHANGE);
                if (alternateExchange != null) {
                    String alternateExchangeName = String.valueOf(alternateExchange);
                    validateAlternateExchangeIsNotQueue(virtualHost, alternateExchangeName);
                    attributes.put(Exchange.ALTERNATE_BINDING, Collections.singletonMap(AlternateBinding.DESTINATION, alternateExchangeName));
                }
                exchange = virtualHost.createMessageDestination(Exchange.class, attributes);
                if (!nowait) {
                    sync();
                    _connection.writeFrame(declareOkBody.generateFrame(getChannelId()));
                }
            } catch (ReservedExchangeNameException e) {
                Exchange existing = getExchange(name);
                if (existing == null || !existing.getType().equals(typeString)) {
                    _connection.sendConnectionClose(ErrorCodes.NOT_ALLOWED, "Attempt to declare exchange: '" + exchangeName + "' which begins with reserved prefix.", getChannelId());
                } else if (!nowait) {
                    sync();
                    _connection.writeFrame(declareOkBody.generateFrame(getChannelId()));
                }
            } catch (AbstractConfiguredObject.DuplicateNameException e) {
                exchange = (Exchange<?>) e.getExisting();
                if (!exchange.getType().equals(typeString)) {
                    _connection.sendConnectionClose(ErrorCodes.NOT_ALLOWED, "Attempt to redeclare exchange: '" + exchangeName + "' of type " + exchange.getType() + " to " + type + ".", getChannelId());
                } else {
                    if (!nowait) {
                        sync();
                        _connection.writeFrame(declareOkBody.generateFrame(getChannelId()));
                    }
                }
            } catch (NoFactoryForTypeException e) {
                _connection.sendConnectionClose(ErrorCodes.COMMAND_INVALID, "Unknown exchange type '" + e.getType() + "' for exchange '" + exchangeName + "'", getChannelId());
            } catch (AccessControlException e) {
                _connection.sendConnectionClose(ErrorCodes.ACCESS_REFUSED, e.getMessage(), getChannelId());
            } catch (UnknownAlternateBindingException e) {
                final String message = String.format("Unknown alternate exchange '%s'", e.getAlternateBindingName());
                _connection.sendConnectionClose(ErrorCodes.NOT_FOUND, message, getChannelId());
            } catch (IllegalArgumentException | IllegalConfigurationException e) {
                _connection.sendConnectionClose(ErrorCodes.COMMAND_INVALID, "Error creating exchange '" + exchangeName + "': " + e.getMessage(), getChannelId());
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) NamedAddressSpace(org.apache.qpid.server.model.NamedAddressSpace) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) AccessControlException(java.security.AccessControlException) Exchange(org.apache.qpid.server.model.Exchange) AbstractConfiguredObject(org.apache.qpid.server.model.AbstractConfiguredObject) NoFactoryForTypeException(org.apache.qpid.server.model.NoFactoryForTypeException) ReservedExchangeNameException(org.apache.qpid.server.virtualhost.ReservedExchangeNameException) AbstractConfiguredObject(org.apache.qpid.server.model.AbstractConfiguredObject) UnknownAlternateBindingException(org.apache.qpid.server.virtualhost.UnknownAlternateBindingException)

Example 45 with IllegalConfigurationException

use of org.apache.qpid.server.configuration.IllegalConfigurationException in project qpid-broker-j by apache.

the class AMQChannel method receiveQueueDeclare.

@Override
public void receiveQueueDeclare(final AMQShortString queueStr, final boolean passive, final boolean durable, final boolean exclusive, final boolean autoDelete, final boolean nowait, final FieldTable arguments) {
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("RECV[" + _channelId + "] QueueDeclare[" + " queue: " + queueStr + " passive: " + passive + " durable: " + durable + " exclusive: " + exclusive + " autoDelete: " + autoDelete + " nowait: " + nowait + " arguments: " + arguments + " ]");
    }
    NamedAddressSpace virtualHost = _connection.getAddressSpace();
    final AMQShortString queueName;
    // if we aren't given a queue name, we create one which we return to the client
    if ((queueStr == null) || (queueStr.length() == 0)) {
        queueName = new AMQShortString("tmp_" + UUID.randomUUID());
    } else {
        queueName = queueStr;
    }
    Queue<?> queue;
    if (passive) {
        queue = getQueue(queueName.toString());
        if (queue == null) {
            closeChannel(ErrorCodes.NOT_FOUND, "Queue: '" + queueName + "' not found on VirtualHost '" + virtualHost.getName() + "'.");
        } else {
            if (!queue.verifySessionAccess(this)) {
                _connection.sendConnectionClose(ErrorCodes.NOT_ALLOWED, "Queue '" + queue.getName() + "' is exclusive, but not created on this Connection.", getChannelId());
            } else {
                // set this as the default queue on the channel:
                setDefaultQueue(queue);
                if (!nowait) {
                    sync();
                    MethodRegistry methodRegistry = _connection.getMethodRegistry();
                    QueueDeclareOkBody responseBody = methodRegistry.createQueueDeclareOkBody(queueName, queue.getQueueDepthMessages(), queue.getConsumerCount());
                    _connection.writeFrame(responseBody.generateFrame(getChannelId()));
                    if (LOGGER.isDebugEnabled()) {
                        LOGGER.debug("Queue " + queueName + " declared successfully");
                    }
                }
            }
        }
    } else {
        try {
            final String queueNameString = AMQShortString.toString(queueName);
            Map<String, Object> wireArguments = FieldTable.convertToMap(arguments);
            Object alternateExchange = wireArguments.get(ALTERNATE_EXCHANGE);
            if (alternateExchange != null) {
                String alternateExchangeName = String.valueOf(alternateExchange);
                validateAlternateExchangeIsNotQueue(virtualHost, alternateExchangeName);
            }
            Map<String, Object> attributes = QueueArgumentsConverter.convertWireArgsToModel(queueNameString, wireArguments);
            attributes.put(Queue.NAME, queueNameString);
            attributes.put(Queue.DURABLE, durable);
            LifetimePolicy lifetimePolicy;
            ExclusivityPolicy exclusivityPolicy;
            if (exclusive) {
                lifetimePolicy = autoDelete ? LifetimePolicy.DELETE_ON_NO_OUTBOUND_LINKS : durable ? LifetimePolicy.PERMANENT : LifetimePolicy.DELETE_ON_CONNECTION_CLOSE;
                exclusivityPolicy = durable ? ExclusivityPolicy.CONTAINER : ExclusivityPolicy.CONNECTION;
            } else {
                lifetimePolicy = autoDelete ? LifetimePolicy.DELETE_ON_NO_OUTBOUND_LINKS : LifetimePolicy.PERMANENT;
                exclusivityPolicy = ExclusivityPolicy.NONE;
            }
            if (!attributes.containsKey(Queue.EXCLUSIVE)) {
                attributes.put(Queue.EXCLUSIVE, exclusivityPolicy);
            }
            if (!attributes.containsKey(Queue.LIFETIME_POLICY)) {
                attributes.put(Queue.LIFETIME_POLICY, lifetimePolicy);
            }
            queue = virtualHost.createMessageSource(Queue.class, attributes);
            setDefaultQueue(queue);
            if (!nowait) {
                sync();
                MethodRegistry methodRegistry = _connection.getMethodRegistry();
                QueueDeclareOkBody responseBody = methodRegistry.createQueueDeclareOkBody(queueName, queue.getQueueDepthMessages(), queue.getConsumerCount());
                _connection.writeFrame(responseBody.generateFrame(getChannelId()));
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug("Queue " + queueName + " declared successfully");
                }
            }
        } catch (AbstractConfiguredObject.DuplicateNameException qe) {
            queue = (Queue<?>) qe.getExisting();
            if (!queue.verifySessionAccess(this)) {
                _connection.sendConnectionClose(ErrorCodes.NOT_ALLOWED, "Queue '" + queue.getName() + "' is exclusive, but not created on this Connection.", getChannelId());
            } else if (queue.isExclusive() != exclusive) {
                closeChannel(ErrorCodes.ALREADY_EXISTS, "Cannot re-declare queue '" + queue.getName() + "' with different exclusivity (was: " + queue.isExclusive() + " requested " + exclusive + ")");
            } else if ((autoDelete && queue.getLifetimePolicy() == LifetimePolicy.PERMANENT) || (!autoDelete && queue.getLifetimePolicy() != ((exclusive && !durable) ? LifetimePolicy.DELETE_ON_CONNECTION_CLOSE : LifetimePolicy.PERMANENT))) {
                closeChannel(ErrorCodes.ALREADY_EXISTS, "Cannot re-declare queue '" + queue.getName() + "' with different lifetime policy (was: " + queue.getLifetimePolicy() + " requested autodelete: " + autoDelete + ")");
            } else {
                setDefaultQueue(queue);
                if (!nowait) {
                    sync();
                    MethodRegistry methodRegistry = _connection.getMethodRegistry();
                    QueueDeclareOkBody responseBody = methodRegistry.createQueueDeclareOkBody(queueName, queue.getQueueDepthMessages(), queue.getConsumerCount());
                    _connection.writeFrame(responseBody.generateFrame(getChannelId()));
                    if (LOGGER.isDebugEnabled()) {
                        LOGGER.debug("Queue " + queueName + " declared successfully");
                    }
                }
            }
        } catch (AccessControlException e) {
            _connection.sendConnectionClose(ErrorCodes.ACCESS_REFUSED, e.getMessage(), getChannelId());
        } catch (UnknownAlternateBindingException e) {
            final String message = String.format("Unknown alternate exchange: '%s'", e.getAlternateBindingName());
            _connection.sendConnectionClose(ErrorCodes.NOT_FOUND, message, getChannelId());
        } catch (IllegalArgumentException | IllegalConfigurationException e) {
            String message = String.format("Error creating queue '%s': %s", queueName, e.getMessage());
            _connection.sendConnectionClose(ErrorCodes.COMMAND_INVALID, message, getChannelId());
        }
    }
}
Also used : LifetimePolicy(org.apache.qpid.server.model.LifetimePolicy) NamedAddressSpace(org.apache.qpid.server.model.NamedAddressSpace) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) AccessControlException(java.security.AccessControlException) ExclusivityPolicy(org.apache.qpid.server.model.ExclusivityPolicy) AbstractConfiguredObject(org.apache.qpid.server.model.AbstractConfiguredObject) AbstractConfiguredObject(org.apache.qpid.server.model.AbstractConfiguredObject) UnknownAlternateBindingException(org.apache.qpid.server.virtualhost.UnknownAlternateBindingException) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) Queue(org.apache.qpid.server.model.Queue)

Aggregations

IllegalConfigurationException (org.apache.qpid.server.configuration.IllegalConfigurationException)87 HashMap (java.util.HashMap)31 IOException (java.io.IOException)25 ConfiguredObject (org.apache.qpid.server.model.ConfiguredObject)20 File (java.io.File)15 UUID (java.util.UUID)12 ConfiguredObjectRecord (org.apache.qpid.server.store.ConfiguredObjectRecord)12 GeneralSecurityException (java.security.GeneralSecurityException)10 AbstractConfiguredObject (org.apache.qpid.server.model.AbstractConfiguredObject)9 LinkedHashMap (java.util.LinkedHashMap)7 Map (java.util.Map)7 ServerScopedRuntimeException (org.apache.qpid.server.util.ServerScopedRuntimeException)7 AccessControlException (java.security.AccessControlException)6 ArrayList (java.util.ArrayList)6 Protocol (org.apache.qpid.server.model.Protocol)5 UnknownAlternateBindingException (org.apache.qpid.server.virtualhost.UnknownAlternateBindingException)5 MalformedURLException (java.net.MalformedURLException)4 URL (java.net.URL)4 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)4 HashSet (java.util.HashSet)4