Search in sources :

Example 81 with IllegalConfigurationException

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

the class SimpleLDAPAuthenticationManagerImpl method validateInitialDirContext.

private void validateInitialDirContext(Class<? extends SocketFactory> sslSocketFactoryOverrideClass, final String providerUrl, final String searchUsername, final String searchPassword) {
    Hashtable<String, Object> env = createInitialDirContextEnvironment(providerUrl);
    setupSearchContext(env, searchUsername, searchPassword);
    InitialDirContext ctx = null;
    try {
        ctx = createInitialDirContext(env, sslSocketFactoryOverrideClass);
    } catch (NamingException e) {
        LOGGER.error("Failed to establish connectivity to the ldap server for '{}'", providerUrl, e);
        throw new IllegalConfigurationException("Failed to establish connectivity to the ldap server.", e);
    } finally {
        closeSafely(ctx);
    }
}
Also used : IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) NamingException(javax.naming.NamingException) InitialDirContext(javax.naming.directory.InitialDirContext)

Example 82 with IllegalConfigurationException

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

the class SimpleLDAPAuthenticationManagerImpl method createSslSocketFactoryOverrideClass.

private Class<? extends SocketFactory> createSslSocketFactoryOverrideClass(final TrustStore trustStore) {
    String managerName = String.format("%s_%s_%s", getName(), getId(), trustStore == null ? "none" : trustStore.getName());
    String clazzName = new StringUtil().createUniqueJavaName(managerName);
    SSLContext sslContext = null;
    try {
        sslContext = SSLUtil.tryGetSSLContext();
        sslContext.init(null, trustStore == null ? null : trustStore.getTrustManagers(), null);
    } catch (GeneralSecurityException e) {
        LOGGER.error("Exception creating SSLContext", e);
        if (trustStore != null) {
            throw new IllegalConfigurationException("Error creating SSLContext with trust store : " + trustStore.getName(), e);
        } else {
            throw new IllegalConfigurationException("Error creating SSLContext (no trust store)", e);
        }
    }
    SSLSocketFactory sslSocketFactory = new CipherSuiteAndProtocolRestrictingSSLSocketFactory(sslContext.getSocketFactory(), _tlsCipherSuiteWhiteList, _tlsCipherSuiteBlackList, _tlsProtocolWhiteList, _tlsProtocolBlackList);
    Class<? extends AbstractLDAPSSLSocketFactory> clazz = LDAPSSLSocketFactoryGenerator.createSubClass(clazzName, sslSocketFactory);
    LOGGER.debug("Connection to Directory will use custom SSL socket factory : {}", clazz);
    return clazz;
}
Also used : GeneralSecurityException(java.security.GeneralSecurityException) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) CipherSuiteAndProtocolRestrictingSSLSocketFactory(org.apache.qpid.server.util.CipherSuiteAndProtocolRestrictingSSLSocketFactory) SSLContext(javax.net.ssl.SSLContext) StringUtil(org.apache.qpid.server.util.StringUtil) CipherSuiteAndProtocolRestrictingSSLSocketFactory(org.apache.qpid.server.util.CipherSuiteAndProtocolRestrictingSSLSocketFactory) SSLSocketFactory(javax.net.ssl.SSLSocketFactory) AbstractLDAPSSLSocketFactory(org.apache.qpid.server.security.auth.manager.ldap.AbstractLDAPSSLSocketFactory)

Example 83 with IllegalConfigurationException

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

the class AESKeyFileEncrypterFactory method createEncrypter.

@Override
public ConfigurationSecretEncrypter createEncrypter(final ConfiguredObject<?> object) {
    String fileLocation;
    if (object.getContextKeys(false).contains(ENCRYPTER_KEY_FILE)) {
        fileLocation = object.getContextValue(String.class, ENCRYPTER_KEY_FILE);
    } else {
        fileLocation = object.getContextValue(String.class, SystemConfig.QPID_WORK_DIR) + File.separator + DEFAULT_KEYS_SUBDIR_NAME + File.separator + object.getCategoryClass().getSimpleName() + "_" + object.getName() + ".key";
        Map<String, String> context = object.getContext();
        Map<String, String> modifiedContext = new LinkedHashMap<>(context);
        modifiedContext.put(ENCRYPTER_KEY_FILE, fileLocation);
        object.setAttributes(Collections.<String, Object>singletonMap(ConfiguredObject.CONTEXT, modifiedContext));
    }
    File file = new File(fileLocation);
    if (!file.exists()) {
        LOGGER.warn("Configuration encryption is enabled, but no configuration secret was found. A new configuration secret will be created at '{}'.", fileLocation);
        createAndPopulateKeyFile(file);
    }
    if (!file.isFile()) {
        throw new IllegalArgumentException("File '" + fileLocation + "' is not a regular file.");
    }
    try {
        checkFilePermissions(fileLocation, file);
        if (Files.size(file.toPath()) != AES_KEY_SIZE_BYTES) {
            throw new IllegalArgumentException("Key file '" + fileLocation + "' contains an incorrect about of data");
        }
        try (FileInputStream inputStream = new FileInputStream(file)) {
            byte[] key = new byte[AES_KEY_SIZE_BYTES];
            int pos = 0;
            int read;
            while (pos < key.length && -1 != (read = inputStream.read(key, pos, key.length - pos))) {
                pos += read;
            }
            if (pos != key.length) {
                throw new IllegalConfigurationException("Key file '" + fileLocation + "' contained an incorrect about of data");
            }
            SecretKeySpec keySpec = new SecretKeySpec(key, AES_ALGORITHM);
            return new AESKeyFileEncrypter(keySpec);
        }
    } catch (IOException e) {
        throw new IllegalConfigurationException("Unable to get file permissions: " + e.getMessage(), e);
    }
}
Also used : SecretKeySpec(javax.crypto.spec.SecretKeySpec) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) IOException(java.io.IOException) File(java.io.File) FileInputStream(java.io.FileInputStream) LinkedHashMap(java.util.LinkedHashMap)

Example 84 with IllegalConfigurationException

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

the class BrokerStoreUpgraderAndRecoverer method createVirtualHostsRecordsFromBrokerRecordForModel_1_x.

private static ConfiguredObjectRecord createVirtualHostsRecordsFromBrokerRecordForModel_1_x(ConfiguredObjectRecord brokerRecord, StoreUpgraderPhase upgrader) {
    Map<String, Object> attributes = brokerRecord.getAttributes();
    if (attributes.containsKey(VIRTUALHOSTS) && attributes.get(VIRTUALHOSTS) instanceof Collection) {
        Collection<?> virtualHosts = (Collection<?>) attributes.get(VIRTUALHOSTS);
        for (Object virtualHost : virtualHosts) {
            if (virtualHost instanceof Map) {
                Map<String, Object> virtualHostAttributes = (Map) virtualHost;
                if (virtualHostAttributes.containsKey("configPath")) {
                    throw new IllegalConfigurationException("Auto-upgrade of virtual host " + attributes.get("name") + " having XML configuration is not supported. Virtual host configuration file is " + attributes.get("configPath"));
                }
                virtualHostAttributes = new HashMap<>(virtualHostAttributes);
                Object nameAttribute = virtualHostAttributes.get("name");
                Object idAttribute = virtualHostAttributes.remove("id");
                UUID id;
                if (idAttribute == null) {
                    id = UUID.randomUUID();
                } else {
                    if (idAttribute instanceof String) {
                        id = UUID.fromString((String) idAttribute);
                    } else if (idAttribute instanceof UUID) {
                        id = (UUID) idAttribute;
                    } else {
                        throw new IllegalConfigurationException("Illegal ID value '" + idAttribute + "' for virtual host " + nameAttribute);
                    }
                }
                ConfiguredObjectRecord nodeRecord = new ConfiguredObjectRecordImpl(id, "VirtualHost", virtualHostAttributes, Collections.singletonMap("Broker", brokerRecord.getId()));
                upgrader.getUpdateMap().put(nodeRecord.getId(), nodeRecord);
                upgrader.configuredObject(nodeRecord);
            }
        }
        attributes = new HashMap<>(attributes);
        attributes.remove(VIRTUALHOSTS);
        brokerRecord = new ConfiguredObjectRecordImpl(brokerRecord.getId(), brokerRecord.getType(), attributes, brokerRecord.getParents());
        upgrader.getUpdateMap().put(brokerRecord.getId(), brokerRecord);
    }
    return brokerRecord;
}
Also used : IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) Collection(java.util.Collection) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) UUID(java.util.UUID) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 85 with IllegalConfigurationException

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

the class FileKeyStoreTest method testEmptyKeystoreRejected.

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

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