Search in sources :

Example 46 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 {
            final Map<String, Object> arguments = QueueArgumentsConverter.convertWireArgsToModel(queueName, method.getArguments());
            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 exchange '%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 47 with IllegalConfigurationException

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

the class Main method copyInitialConfigFile.

private void copyInitialConfigFile(final String initialConfigLocation, final File destinationFile) {
    URL url = null;
    try {
        url = new URL(initialConfigLocation);
    } catch (MalformedURLException e) {
        File locationFile = new File(initialConfigLocation);
        try {
            url = locationFile.toURI().toURL();
        } catch (MalformedURLException e1) {
            throw new IllegalConfigurationException("Cannot create URL for file " + locationFile, e1);
        }
    }
    InputStream in = null;
    try {
        in = url.openStream();
        FileUtils.copy(in, destinationFile);
    } catch (IOException e) {
        throw new IllegalConfigurationException("Cannot create file " + destinationFile + " by copying initial config from " + initialConfigLocation, e);
    } finally {
        if (in != null) {
            try {
                in.close();
            } catch (IOException e) {
                throw new IllegalConfigurationException("Cannot close initial config input stream: " + initialConfigLocation, e);
            }
        }
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) InputStream(java.io.InputStream) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) IOException(java.io.IOException) File(java.io.File) URL(java.net.URL)

Example 48 with IllegalConfigurationException

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

the class AbstractQueue method validateOrCreateAlternateBinding.

private void validateOrCreateAlternateBinding(final Queue<?> queue, final boolean mayCreate) {
    Object value = queue.getAttribute(ALTERNATE_BINDING);
    if (value instanceof AlternateBinding) {
        AlternateBinding alternateBinding = (AlternateBinding) value;
        String destinationName = alternateBinding.getDestination();
        MessageDestination messageDestination = _virtualHost.getAttainedMessageDestination(destinationName, mayCreate);
        if (messageDestination == null) {
            throw new UnknownAlternateBindingException(destinationName);
        } else if (messageDestination == this) {
            throw new IllegalConfigurationException(String.format("Cannot create alternate binding for '%s' : Alternate binding destination cannot refer to self.", getName()));
        } else if (isDurable() && !messageDestination.isDurable()) {
            throw new IllegalConfigurationException(String.format("Cannot create alternate binding for '%s' : Alternate binding destination '%s' is not durable.", getName(), destinationName));
        }
    }
}
Also used : MessageDestination(org.apache.qpid.server.message.MessageDestination) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) UnknownAlternateBindingException(org.apache.qpid.server.virtualhost.UnknownAlternateBindingException)

Example 49 with IllegalConfigurationException

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

the class AutoGeneratedSelfSignedKeyStoreImpl method generateKeyManagers.

private void generateKeyManagers() {
    try {
        X509Certificate[] certs = new X509Certificate[] { _certificate };
        java.security.KeyStore inMemoryKeyStore = java.security.KeyStore.getInstance(java.security.KeyStore.getDefaultType());
        byte[] bytes = new byte[64];
        char[] chars = new char[64];
        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();
    } catch (IOException | GeneralSecurityException e) {
        throw new IllegalConfigurationException("Cannot load private key or certificate(s): " + e, e);
    }
}
Also used : GeneralSecurityException(java.security.GeneralSecurityException) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) KeyStore(java.security.KeyStore) IOException(java.io.IOException) X509Certificate(java.security.cert.X509Certificate) KeyManagerFactory(javax.net.ssl.KeyManagerFactory)

Example 50 with IllegalConfigurationException

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

the class AutoGeneratedSelfSignedKeyStoreImpl method loadPrivateKeyAndCertificate.

private void loadPrivateKeyAndCertificate() {
    byte[] privateKeyEncoded = Strings.decodeBase64((String) getActualAttributes().get(ENCODED_PRIVATE_KEY));
    byte[] certificateEncoded = Strings.decodeBase64((String) getActualAttributes().get(ENCODED_CERTIFICATE));
    try (ByteArrayInputStream input = new ByteArrayInputStream(certificateEncoded)) {
        CertificateFactory cf = CertificateFactory.getInstance("X.509");
        _certificate = (X509Certificate) cf.generateCertificate(input);
    } catch (CertificateException | IOException e) {
        throw new IllegalConfigurationException("Could not decode certificate", e);
    }
    try {
        _privateKey = SSLUtil.readPrivateKey(privateKeyEncoded, _keyAlgorithm);
    } catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
        throw new IllegalConfigurationException("Could not decode private key", e);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) CertificateException(java.security.cert.CertificateException) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeySpecException(java.security.spec.InvalidKeySpecException) CertificateFactory(java.security.cert.CertificateFactory)

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