Search in sources :

Example 91 with IllegalConfigurationException

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

the class NonJavaKeyStoreImpl method updateKeyManagers.

@SuppressWarnings("unused")
private void updateKeyManagers() {
    try {
        if (_privateKeyUrl != null && _certificateUrl != null) {
            PrivateKey privateKey = SSLUtil.readPrivateKey(getUrlFromString(_privateKeyUrl));
            X509Certificate[] certs = SSLUtil.readCertificates(getUrlFromString(_certificateUrl));
            List<X509Certificate> allCerts = new ArrayList<>(Arrays.asList(certs));
            if (_intermediateCertificateUrl != null) {
                allCerts.addAll(Arrays.asList(SSLUtil.readCertificates(getUrlFromString(_intermediateCertificateUrl))));
                certs = allCerts.toArray(new X509Certificate[allCerts.size()]);
            }
            checkCertificateExpiry(certs);
            java.security.KeyStore inMemoryKeyStore = java.security.KeyStore.getInstance(java.security.KeyStore.getDefaultType());
            byte[] bytes = new byte[64];
            char[] chars = "".toCharArray();
            RANDOM.nextBytes(bytes);
            StandardCharsets.US_ASCII.decode(ByteBuffer.wrap(bytes)).get(chars);
            inMemoryKeyStore.load(null, chars);
            inMemoryKeyStore.setKeyEntry("1", privateKey, chars, certs);
            KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
            kmf.init(inMemoryKeyStore, chars);
            _keyManagers = kmf.getKeyManagers();
            _certificate = certs[0];
            _certificates = Collections.unmodifiableCollection(allCerts);
        }
    } catch (IOException | GeneralSecurityException e) {
        throw new IllegalConfigurationException("Cannot load private key or certificate(s): " + e, e);
    }
}
Also used : RSAPrivateKey(java.security.interfaces.RSAPrivateKey) PrivateKey(java.security.PrivateKey) GeneralSecurityException(java.security.GeneralSecurityException) ArrayList(java.util.ArrayList) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) IOException(java.io.IOException) X509Certificate(java.security.cert.X509Certificate) KeyManagerFactory(javax.net.ssl.KeyManagerFactory)

Example 92 with IllegalConfigurationException

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

the class ManagementModeStoreHandlerTest method testRemoveCLIPort.

@Test
public void testRemoveCLIPort() {
    _systemConfigAttributes.put(SystemConfig.MANAGEMENT_MODE_HTTP_PORT_OVERRIDE, 1000);
    _handler = createManagementModeStoreHandler();
    _handler.init(_systemConfig);
    Collection<ConfiguredObjectRecord> records = openAndGetRecords();
    UUID portId = getOptionsPortId(records);
    ConfiguredObjectRecord record = mock(ConfiguredObjectRecord.class);
    when(record.getId()).thenReturn(portId);
    try {
        _handler.remove(record);
        fail("Exception should be thrown on trying to remove CLI port");
    } catch (IllegalConfigurationException e) {
    // pass
    }
}
Also used : IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) ConfiguredObjectRecord(org.apache.qpid.server.store.ConfiguredObjectRecord) UUID(java.util.UUID) Test(org.junit.Test)

Example 93 with IllegalConfigurationException

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

the class ServerSessionDelegate method queueDeclare.

@Override
public void queueDeclare(ServerSession session, final QueueDeclare method) {
    final NamedAddressSpace addressSpace = getAddressSpace(session);
    String queueName = method.getQueue();
    Queue<?> queue;
    // TODO: do we need to check that the queue already exists with exactly the same "configuration"?
    final boolean exclusive = method.getExclusive();
    final boolean autoDelete = method.getAutoDelete();
    if (method.getPassive()) {
        queue = getQueue(addressSpace, queueName);
        if (queue == null) {
            String description = "Queue: " + queueName + " not found on VirtualHost(" + addressSpace + ").";
            ExecutionErrorCode errorCode = ExecutionErrorCode.NOT_FOUND;
            exception(session, method, errorCode, description);
        } else if (exclusive) {
            if (queue.getExclusive() == ExclusivityPolicy.NONE) {
                String description = "Cannot passively declare queue ('" + queueName + "')" + " as exclusive as queue with same name is" + " already declared as non-exclusive";
                ExecutionErrorCode errorCode = ExecutionErrorCode.RESOURCE_LOCKED;
                exception(session, method, errorCode, description);
            } else if (!verifySessionAccess(session, queue)) {
                String description = "Cannot passively declare queue('" + queueName + "')," + " as exclusive queue with same name " + "declared on another session";
                ExecutionErrorCode errorCode = ExecutionErrorCode.RESOURCE_LOCKED;
                exception(session, method, errorCode, description);
            }
        }
    } else {
        try {
            Queue.BehaviourOnUnknownDeclareArgument unknownArgumentBehaviour = session.getAMQPConnection().getContextValue(Queue.BehaviourOnUnknownDeclareArgument.class, Queue.UNKNOWN_QUEUE_DECLARE_ARGUMENT_BEHAVIOUR_NAME);
            final Map<String, Object> arguments = QueueArgumentsConverter.convertWireArgsToModel(queueName, method.getArguments(), session.getAMQPConnection().getModel(), unknownArgumentBehaviour);
            final String alternateExchangeName = method.getAlternateExchange();
            if (method.hasAlternateExchange() && !nameNullOrEmpty(alternateExchangeName)) {
                validateAlternateExchangeIsNotQueue(addressSpace, alternateExchangeName);
                arguments.put(Queue.ALTERNATE_BINDING, Collections.singletonMap(AlternateBinding.DESTINATION, alternateExchangeName));
            }
            arguments.put(Queue.NAME, queueName);
            if (!arguments.containsKey(Queue.LIFETIME_POLICY)) {
                LifetimePolicy lifetime;
                if (autoDelete) {
                    lifetime = exclusive ? LifetimePolicy.DELETE_ON_SESSION_END : LifetimePolicy.DELETE_ON_NO_OUTBOUND_LINKS;
                } else {
                    lifetime = LifetimePolicy.PERMANENT;
                }
                arguments.put(Queue.LIFETIME_POLICY, lifetime);
            }
            if (!arguments.containsKey(Queue.EXCLUSIVE)) {
                ExclusivityPolicy exclusivityPolicy = exclusive ? ExclusivityPolicy.SESSION : ExclusivityPolicy.NONE;
                arguments.put(Queue.EXCLUSIVE, exclusivityPolicy);
            }
            arguments.put(Queue.DURABLE, method.getDurable());
            queue = addressSpace.createMessageSource(Queue.class, arguments);
        } catch (AbstractConfiguredObject.DuplicateNameException qe) {
            queue = (Queue<?>) qe.getExisting();
            if (!verifySessionAccess(session, queue)) {
                String description = "Cannot declare queue('" + queueName + "')," + " as exclusive queue with same name " + "declared on another session";
                ExecutionErrorCode errorCode = ExecutionErrorCode.RESOURCE_LOCKED;
                exception(session, method, errorCode, description);
            }
        } catch (AccessControlException e) {
            exception(session, method, ExecutionErrorCode.UNAUTHORIZED_ACCESS, e.getMessage());
        } catch (UnknownAlternateBindingException e) {
            exception(session, method, ExecutionErrorCode.NOT_FOUND, String.format("Unknown alternate destination '%s'", e.getAlternateBindingName()));
        } catch (IllegalArgumentException | IllegalConfigurationException e) {
            exception(session, method, ExecutionErrorCode.ILLEGAL_ARGUMENT, e.getMessage());
        }
    }
}
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) Queue(org.apache.qpid.server.model.Queue)

Example 94 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 95 with IllegalConfigurationException

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

the class JDBCLoggerHelper method createAppenderInstance.

Appender<ILoggingEvent> createAppenderInstance(final Context context, final ConfiguredObject<?> logger, final JDBCSettings settings) {
    try {
        final JDBCSettingsDBNameResolver dbNameResolver = new JDBCSettingsDBNameResolver(settings);
        final ConnectionSource connectionSource = createConnectionSource(context, logger, settings);
        final DBAppender appender = new DBAppender();
        appender.setDbNameResolver(dbNameResolver);
        appender.setConnectionSource(connectionSource);
        appender.setContext(context);
        appender.start();
        return appender;
    } catch (Exception e) {
        LOGGER.error("Failed to create appender", e);
        throw new IllegalConfigurationException("Cannot create appender");
    }
}
Also used : ConnectionSource(ch.qos.logback.core.db.ConnectionSource) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) DBAppender(ch.qos.logback.classic.db.DBAppender) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException)

Aggregations

IllegalConfigurationException (org.apache.qpid.server.configuration.IllegalConfigurationException)115 IOException (java.io.IOException)35 HashMap (java.util.HashMap)30 Test (org.junit.Test)29 ConfiguredObject (org.apache.qpid.server.model.ConfiguredObject)22 File (java.io.File)16 GeneralSecurityException (java.security.GeneralSecurityException)12 UUID (java.util.UUID)12 ConfiguredObjectRecord (org.apache.qpid.server.store.ConfiguredObjectRecord)12 AbstractConfiguredObject (org.apache.qpid.server.model.AbstractConfiguredObject)10 X509Certificate (java.security.cert.X509Certificate)9 ArrayList (java.util.ArrayList)9 Reader (java.io.Reader)7 Path (java.nio.file.Path)7 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)7 LinkedHashMap (java.util.LinkedHashMap)7 Map (java.util.Map)7 AccessControlException (java.security.AccessControlException)6 Certificate (java.security.cert.Certificate)6 SSLContext (javax.net.ssl.SSLContext)6