Search in sources :

Example 96 with IllegalConfigurationException

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

the class AbstractConfiguredObject method asObjectRecord.

@Override
public final ConfiguredObjectRecord asObjectRecord() {
    return new ConfiguredObjectRecord() {

        @Override
        public UUID getId() {
            return AbstractConfiguredObject.this.getId();
        }

        @Override
        public String getType() {
            return getCategoryClass().getSimpleName();
        }

        @Override
        public Map<String, Object> getAttributes() {
            return Subject.doAs(getSubjectWithAddedSystemRights(), new PrivilegedAction<Map<String, Object>>() {

                @Override
                public Map<String, Object> run() {
                    Map<String, Object> attributes = new LinkedHashMap<>();
                    Map<String, Object> actualAttributes = getActualAttributes();
                    for (ConfiguredObjectAttribute<?, ?> attr : _attributeTypes.values()) {
                        if (attr.isPersisted() && !ID.equals(attr.getName())) {
                            if (attr.isDerived()) {
                                Object value = getAttribute(attr.getName());
                                attributes.put(attr.getName(), toRecordedForm(attr, value));
                            } else if (actualAttributes.containsKey(attr.getName())) {
                                Object value = actualAttributes.get(attr.getName());
                                attributes.put(attr.getName(), toRecordedForm(attr, value));
                            }
                        }
                    }
                    return attributes;
                }
            });
        }

        public Object toRecordedForm(final ConfiguredObjectAttribute<?, ?> attr, Object value) {
            if (value instanceof ConfiguredObject) {
                value = ((ConfiguredObject) value).getId();
            }
            if (attr.isSecure() && _encrypter != null && value != null) {
                if (value instanceof Collection || value instanceof Map) {
                    ObjectMapper mapper = ConfiguredObjectJacksonModule.newObjectMapper(false);
                    try (StringWriter stringWriter = new StringWriter()) {
                        mapper.writeValue(stringWriter, value);
                        value = _encrypter.encrypt(stringWriter.toString());
                    } catch (IOException e) {
                        throw new IllegalConfigurationException("Failure when encrypting a secret value", e);
                    }
                } else {
                    value = _encrypter.encrypt(value.toString());
                }
            }
            return value;
        }

        @Override
        public Map<String, UUID> getParents() {
            Map<String, UUID> parents = new LinkedHashMap<>();
            Class<? extends ConfiguredObject> parentClass = getModel().getParentType(getCategoryClass());
            ConfiguredObject parent = (ConfiguredObject) getParent();
            if (parent != null) {
                parents.put(parentClass.getSimpleName(), parent.getId());
            }
            return parents;
        }

        @Override
        public String toString() {
            return AbstractConfiguredObject.this.getClass().getSimpleName() + "[name=" + getName() + ", categoryClass=" + getCategoryClass() + ", type=" + getType() + ", id=" + getId() + ", attributes=" + getAttributes() + "]";
        }
    };
}
Also used : IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) IOException(java.io.IOException) LinkedHashMap(java.util.LinkedHashMap) StringWriter(java.io.StringWriter) Collection(java.util.Collection) ConfiguredObjectRecord(org.apache.qpid.server.store.ConfiguredObjectRecord) UUID(java.util.UUID) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) LinkedHashMap(java.util.LinkedHashMap) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 97 with IllegalConfigurationException

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

the class AbstractContainer method updateEncrypter.

private void updateEncrypter(final String encryptionProviderType) {
    if (encryptionProviderType != null && !"".equals(encryptionProviderType.trim())) {
        PluggableFactoryLoader<ConfigurationSecretEncrypterFactory> factoryLoader = new PluggableFactoryLoader<>(ConfigurationSecretEncrypterFactory.class);
        ConfigurationSecretEncrypterFactory factory = factoryLoader.get(encryptionProviderType);
        if (factory == null) {
            throw new IllegalConfigurationException("Unknown Configuration Secret Encryption method " + encryptionProviderType);
        }
        setEncrypter(factory.createEncrypter(this));
    } else {
        setEncrypter(null);
    }
}
Also used : IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) ConfigurationSecretEncrypterFactory(org.apache.qpid.server.plugin.ConfigurationSecretEncrypterFactory) PluggableFactoryLoader(org.apache.qpid.server.plugin.PluggableFactoryLoader)

Example 98 with IllegalConfigurationException

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

the class PrincipalDatabaseAuthenticationManager method validateOnCreate.

@Override
protected void validateOnCreate() {
    super.validateOnCreate();
    File passwordFile = new File(_path);
    if (passwordFile.exists() && !passwordFile.canRead()) {
        throw new IllegalConfigurationException(String.format("Cannot read password file '%s'. Please check permissions.", _path));
    }
}
Also used : IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) File(java.io.File)

Example 99 with IllegalConfigurationException

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

the class PrincipalDatabaseAuthenticationManager method onCreate.

@Override
protected void onCreate() {
    super.onCreate();
    File passwordFile = new File(_path);
    if (!passwordFile.exists()) {
        try {
            Path path = new FileHelper().createNewFile(passwordFile, getContextValue(String.class, SystemConfig.POSIX_FILE_PERMISSIONS));
            if (!Files.exists(path)) {
                throw new IllegalConfigurationException(String.format("Cannot create password file at '%s'", _path));
            }
        } catch (IOException e) {
            throw new IllegalConfigurationException(String.format("Cannot create password file at '%s'", _path), e);
        }
    }
}
Also used : Path(java.nio.file.Path) FileHelper(org.apache.qpid.server.util.FileHelper) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) IOException(java.io.IOException) File(java.io.File)

Example 100 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(final SimpleLDAPAuthenticationManager<?> authenticationProvider) {
    final TrustStore truststore = authenticationProvider.getTrustStore();
    final Class<? extends SocketFactory> sslSocketFactoryOverrideClass = createSslSocketFactoryOverrideClass(truststore);
    final Hashtable<String, Object> env = createInitialDirContextEnvironment(authenticationProvider.getProviderUrl());
    setAuthenticationProperties(env, authenticationProvider.getSearchUsername(), authenticationProvider.getSearchPassword(), authenticationProvider.getAuthenticationMethod());
    InitialDirContext ctx = null;
    try {
        Subject gssapiIdentity = null;
        if (LdapAuthenticationMethod.GSSAPI.equals(authenticationProvider.getAuthenticationMethod())) {
            gssapiIdentity = doGssApiLogin(authenticationProvider.getLoginConfigScope());
        }
        ctx = createInitialDirContext(env, sslSocketFactoryOverrideClass, gssapiIdentity);
    } catch (NamingException e) {
        LOGGER.debug("Failed to establish connectivity to the ldap server for '{}'", authenticationProvider.getProviderUrl(), e);
        throw new IllegalConfigurationException("Failed to establish connectivity to the ldap server.", e);
    } catch (LoginException e) {
        LOGGER.debug("JAAS login failed ", e);
        throw new IllegalConfigurationException("JAAS login failed.", e);
    } finally {
        closeSafely(ctx);
    }
}
Also used : IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) LoginException(javax.security.auth.login.LoginException) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) NamingException(javax.naming.NamingException) TrustStore(org.apache.qpid.server.model.TrustStore) InitialDirContext(javax.naming.directory.InitialDirContext) Subject(javax.security.auth.Subject)

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