Search in sources :

Example 31 with IllegalConfigurationException

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

the class AclFileAccessControlProviderFactoryTest method testCreateInstanceWhenAclFileIsSpecifiedButDoesNotExist.

public void testCreateInstanceWhenAclFileIsSpecifiedButDoesNotExist() {
    File aclFile = new File(TMP_FOLDER, "my-non-existing-acl-" + System.currentTimeMillis());
    assertFalse("ACL file " + aclFile.getAbsolutePath() + " actually exists but should not", aclFile.exists());
    Map<String, Object> attributes = new HashMap<String, Object>();
    attributes.put(AccessControlProvider.ID, UUID.randomUUID());
    attributes.put(AccessControlProvider.NAME, "acl");
    attributes.put(AccessControlProvider.TYPE, AclFileAccessControlProvider.ACL_FILE_PROVIDER_TYPE);
    attributes.put(AclFileAccessControlProvider.PATH, aclFile.getAbsolutePath());
    try {
        AccessControlProvider control = _objectFactory.create(AccessControlProvider.class, attributes, _broker);
        fail("It should not be possible to create and initialise ACL with non existing file");
    } catch (IllegalConfigurationException e) {
        assertTrue("Unexpected exception message: " + e.getMessage(), Pattern.matches("Cannot convert .* to a readable resource", e.getMessage()));
    }
}
Also used : HashMap(java.util.HashMap) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) AccessControlProvider(org.apache.qpid.server.model.AccessControlProvider) File(java.io.File)

Example 32 with IllegalConfigurationException

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

the class AclFileAccessControlProviderImplTest method testValidationOnCreateWithNonExistingACLFile.

public void testValidationOnCreateWithNonExistingACLFile() {
    Map<String, Object> attributes = new HashMap<>();
    String aclFilePath = new File(TMP_FOLDER, "test_" + getTestName() + System.nanoTime() + ".acl").getAbsolutePath();
    attributes.put("path", aclFilePath);
    attributes.put(AclFileAccessControlProvider.NAME, getTestName());
    AclFileAccessControlProviderImpl aclProvider = new AclFileAccessControlProviderImpl(attributes, _broker);
    try {
        aclProvider.create();
        fail("Exception is expected on validation with non-existing ACL file");
    } catch (IllegalConfigurationException e) {
        assertEquals("Unexpected exception message:" + e.getMessage(), String.format("Cannot convert %s to a readable resource", aclFilePath), e.getMessage());
    }
}
Also used : HashMap(java.util.HashMap) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) File(java.io.File)

Example 33 with IllegalConfigurationException

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

the class ServerSessionDelegate method exchangeDeclare.

@Override
public void exchangeDeclare(ServerSession session, ExchangeDeclare method) {
    String exchangeName = method.getExchange();
    NamedAddressSpace addressSpace = getAddressSpace(session);
    // we must check for any unsupported arguments present and throw not-implemented
    if (method.hasArguments()) {
        Map<String, Object> args = method.getArguments();
        // QPID-3392: currently we don't support any!
        if (!args.isEmpty()) {
            exception(session, method, ExecutionErrorCode.NOT_IMPLEMENTED, "Unsupported exchange argument(s) found " + args.keySet().toString());
            return;
        }
    }
    String alternateExchangeName = method.getAlternateExchange();
    if (nameNullOrEmpty(method.getExchange())) {
        // special case handling to fake the existence of the default exchange for 0-10
        if (!ExchangeDefaults.DIRECT_EXCHANGE_CLASS.equals(method.getType())) {
            exception(session, method, ExecutionErrorCode.NOT_ALLOWED, "Attempt to redeclare default exchange " + " of type " + ExchangeDefaults.DIRECT_EXCHANGE_CLASS + " to " + method.getType() + ".");
        }
        if (!nameNullOrEmpty(alternateExchangeName)) {
            exception(session, method, ExecutionErrorCode.NOT_ALLOWED, "Attempt to set alternate exchange of the default exchange " + " to " + alternateExchangeName + ".");
        }
    } else {
        if (method.getPassive()) {
            Exchange<?> exchange = getExchange(session, exchangeName);
            if (exchange == null) {
                exception(session, method, ExecutionErrorCode.NOT_FOUND, "not-found: exchange-name '" + exchangeName + "'");
            } else {
                if (!exchange.getType().equals(method.getType()) && (method.getType() != null && method.getType().length() > 0)) {
                    exception(session, method, ExecutionErrorCode.NOT_ALLOWED, "Attempt to redeclare exchange: " + exchangeName + " of type " + exchange.getType() + " to " + method.getType() + ".");
                }
            }
        } else {
            try {
                Map<String, Object> attributes = new HashMap<String, Object>();
                attributes.put(org.apache.qpid.server.model.Exchange.NAME, method.getExchange());
                attributes.put(org.apache.qpid.server.model.Exchange.TYPE, method.getType());
                attributes.put(org.apache.qpid.server.model.Exchange.DURABLE, method.getDurable());
                attributes.put(org.apache.qpid.server.model.Exchange.LIFETIME_POLICY, method.getAutoDelete() ? LifetimePolicy.DELETE_ON_NO_LINKS : LifetimePolicy.PERMANENT);
                if (method.hasAlternateExchange() && !nameNullOrEmpty(alternateExchangeName)) {
                    validateAlternateExchangeIsNotQueue(addressSpace, alternateExchangeName);
                    attributes.put(org.apache.qpid.server.model.Exchange.ALTERNATE_BINDING, Collections.singletonMap(AlternateBinding.DESTINATION, alternateExchangeName));
                }
                addressSpace.createMessageDestination(Exchange.class, attributes);
                ;
            } catch (ReservedExchangeNameException e) {
                Exchange<?> existingExchange = getExchange(session, exchangeName);
                if (existingExchange == null || !existingExchange.getType().equals(method.getType()) || (method.hasAlternateExchange() && (existingExchange.getAlternateBinding() == null || !alternateExchangeName.equals(existingExchange.getAlternateBinding().getDestination())))) {
                    exception(session, method, ExecutionErrorCode.NOT_ALLOWED, "Attempt to declare exchange: " + exchangeName + " which begins with reserved name or prefix.");
                }
            } catch (UnknownAlternateBindingException e) {
                exception(session, method, ExecutionErrorCode.NOT_FOUND, String.format("Unknown alternate exchange '%s'", e.getAlternateBindingName()));
            } catch (NoFactoryForTypeException e) {
                exception(session, method, ExecutionErrorCode.NOT_FOUND, "Unknown Exchange Type: " + method.getType());
            } catch (AbstractConfiguredObject.DuplicateNameException e) {
                Exchange<?> exchange = (Exchange<?>) e.getExisting();
                if (!exchange.getType().equals(method.getType())) {
                    exception(session, method, ExecutionErrorCode.NOT_ALLOWED, "Attempt to redeclare exchange: " + exchangeName + " of type " + exchange.getType() + " to " + method.getType() + ".");
                } else if (method.hasAlternateExchange() && (exchange.getAlternateBinding() == null || !alternateExchangeName.equals(exchange.getAlternateBinding().getDestination()))) {
                    exception(session, method, ExecutionErrorCode.NOT_ALLOWED, "Attempt to change alternate exchange of: " + exchangeName + " from " + exchange.getAlternateBinding() + " to " + alternateExchangeName + ".");
                }
            } catch (AccessControlException e) {
                exception(session, method, ExecutionErrorCode.UNAUTHORIZED_ACCESS, e.getMessage());
            } catch (IllegalArgumentException | IllegalConfigurationException e) {
                exception(session, method, ExecutionErrorCode.ILLEGAL_ARGUMENT, e.getMessage());
            }
        }
    }
}
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) NoFactoryForTypeException(org.apache.qpid.server.model.NoFactoryForTypeException) AbstractConfiguredObject(org.apache.qpid.server.model.AbstractConfiguredObject) ReservedExchangeNameException(org.apache.qpid.server.virtualhost.ReservedExchangeNameException) AbstractConfiguredObject(org.apache.qpid.server.model.AbstractConfiguredObject) UnknownAlternateBindingException(org.apache.qpid.server.virtualhost.UnknownAlternateBindingException)

Example 34 with IllegalConfigurationException

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

the class FileTrustStoreTest method testEmptyTrustStoreRejected.

public void testEmptyTrustStoreRejected() {
    final URL emptyKeystore = getClass().getResource(EMPTY_KEYSTORE_RESOURCE);
    assertNotNull("Empty keystore not found", emptyKeystore);
    Map<String, Object> attributes = new HashMap<>();
    attributes.put(FileKeyStore.NAME, "myFileTrustStore");
    attributes.put(FileKeyStore.PASSWORD, TestSSLConstants.BROKER_KEYSTORE_PASSWORD);
    attributes.put(FileKeyStore.STORE_URL, emptyKeystore);
    try {
        _factory.create(TrustStore.class, attributes, _broker);
        fail("Exception not thrown");
    } catch (IllegalConfigurationException ice) {
        String message = ice.getMessage();
        assertTrue("Exception text not as unexpected:" + message, message.contains("Trust store must contain at least one certificate."));
    }
}
Also used : HashMap(java.util.HashMap) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) URL(java.net.URL)

Example 35 with IllegalConfigurationException

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

the class NonJavaKeyStoreTest method testCreationOfTrustStoreFromValidPrivateKeyAndInvalidCertificate.

public void testCreationOfTrustStoreFromValidPrivateKeyAndInvalidCertificate() throws Exception {
    File[] resources = extractResourcesFromTestKeyStore(true);
    _testResources.addAll(Arrays.asList(resources));
    File invalidCertificate = TestFileUtils.createTempFile(this, ".invalid.cert", "content");
    _testResources.add(invalidCertificate);
    Map<String, Object> attributes = new HashMap<>();
    attributes.put(NonJavaKeyStore.NAME, "myTestTrustStore");
    attributes.put("privateKeyUrl", resources[0].toURI().toURL().toExternalForm());
    attributes.put("certificateUrl", invalidCertificate.toURI().toURL().toExternalForm());
    attributes.put(NonJavaKeyStore.TYPE, "NonJavaKeyStore");
    try {
        _factory.create(KeyStore.class, attributes, _broker);
        fail("Created key store from invalid certificate");
    } catch (IllegalConfigurationException e) {
    // pass
    }
}
Also used : HashMap(java.util.HashMap) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) File(java.io.File)

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