Search in sources :

Example 61 with IllegalConfigurationException

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

the class BDBVirtualHostNodeTest method testValidateOnCreateForInvalidStorePath.

public void testValidateOnCreateForInvalidStorePath() throws Exception {
    String nodeName = getTestName();
    File file = new File(_storePath + File.separator + nodeName);
    assertTrue("Empty file is not created", file.createNewFile());
    Map<String, Object> attributes = new HashMap<>();
    attributes.put(BDBVirtualHostNode.ID, UUID.randomUUID());
    attributes.put(BDBVirtualHostNode.TYPE, BDBVirtualHostNodeImpl.VIRTUAL_HOST_NODE_TYPE);
    attributes.put(BDBVirtualHostNode.NAME, nodeName);
    attributes.put(BDBVirtualHostNode.STORE_PATH, file.getAbsolutePath());
    BDBVirtualHostNodeImpl node = new BDBVirtualHostNodeImpl(attributes, _broker);
    try {
        node.create();
        fail("Cannot create DBD node from existing empty file");
    } catch (IllegalConfigurationException e) {
        assertTrue("Unexpected exception " + e.getMessage(), e.getMessage().startsWith("Cannot open node configuration store"));
    }
}
Also used : HashMap(java.util.HashMap) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) File(java.io.File)

Example 62 with IllegalConfigurationException

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

the class ReplicatedEnvironmentFacade method getPermittedHostsFromHelper.

private static Collection<String> getPermittedHostsFromHelper(final String nodeName, final String groupName, final String helperNodeName, final String helperHostPort, final int dbPingSocketTimeout) {
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug(String.format("Requesting state of the node '%s' at '%s'", helperNodeName, helperHostPort));
    }
    if (helperNodeName == null || "".equals(helperNodeName)) {
        throw new IllegalConfigurationException(String.format("A helper node is not specified for node '%s'" + " joining the group '%s'", nodeName, groupName));
    }
    Collection<String> permittedNodes = null;
    try {
        ReplicationNodeImpl node = new ReplicationNodeImpl(helperNodeName, helperHostPort);
        NodeState state = getRemoteNodeState(groupName, node, dbPingSocketTimeout);
        byte[] applicationState = state.getAppState();
        return convertApplicationStateBytesToPermittedNodeList(applicationState);
    } catch (SocketTimeoutException ste) {
        throw new ExternalServiceTimeoutException(String.format("Timed out trying to connect to existing node '%s' at '%s'", helperNodeName, helperHostPort), ste);
    } catch (IOException | ServiceConnectFailedException e) {
        throw new ExternalServiceException(String.format("Cannot connect to existing node '%s' at '%s'", helperNodeName, helperHostPort), e);
    } catch (BinaryProtocol.ProtocolException e) {
        String message = String.format("Unexpected protocol exception '%s' encountered while retrieving state for node '%s' (%s) from group '%s'", e.getUnexpectedMessage(), helperNodeName, helperHostPort, groupName);
        LOGGER.warn(message, e);
        throw new ExternalServiceException(message, e);
    } catch (RuntimeException e) {
        throw new ExternalServiceException(String.format("Cannot retrieve state for node '%s' (%s) from group '%s'", helperNodeName, helperHostPort, groupName), e);
    }
}
Also used : ExternalServiceTimeoutException(org.apache.qpid.server.util.ExternalServiceTimeoutException) BinaryProtocol(com.sleepycat.je.rep.utilint.BinaryProtocol) ExternalServiceException(org.apache.qpid.server.util.ExternalServiceException) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) IOException(java.io.IOException) SocketTimeoutException(java.net.SocketTimeoutException) ServiceConnectFailedException(com.sleepycat.je.rep.utilint.ServiceDispatcher.ServiceConnectFailedException) ConnectionScopedRuntimeException(org.apache.qpid.server.util.ConnectionScopedRuntimeException) ServerScopedRuntimeException(org.apache.qpid.server.util.ServerScopedRuntimeException)

Example 63 with IllegalConfigurationException

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

the class ReplicatedEnvironmentFacade method connectToHelperNodeAndCheckPermittedHosts.

public static Collection<String> connectToHelperNodeAndCheckPermittedHosts(final String nodeName, final String hostPort, final String groupName, final String helperNodeName, final String helperHostPort, final int dbPingSocketTimeout) {
    ExecutorService executor = null;
    Future<Collection<String>> future = null;
    try {
        executor = Executors.newSingleThreadExecutor(new DaemonThreadFactory(String.format("PermittedHostsCheck-%s-%s", groupName, nodeName)));
        future = executor.submit(new Callable<Collection<String>>() {

            @Override
            public Collection<String> call() throws Exception {
                return getPermittedHostsFromHelper(nodeName, groupName, helperNodeName, helperHostPort, dbPingSocketTimeout);
            }
        });
        try {
            final long timeout = (long) (dbPingSocketTimeout * 1.25);
            final Collection<String> permittedNodes = dbPingSocketTimeout <= 0 ? future.get() : future.get(timeout, TimeUnit.MILLISECONDS);
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug(String.format("Node '%s' permits nodes: '%s'", helperNodeName, String.valueOf(permittedNodes)));
            }
            if (permittedNodes == null || !permittedNodes.contains(hostPort)) {
                throw new IllegalConfigurationException(String.format("Node using address '%s' is not permitted to join the group '%s'", hostPort, groupName));
            }
            return permittedNodes;
        } catch (ExecutionException e) {
            final Throwable cause = e.getCause();
            if (cause instanceof RuntimeException) {
                throw (RuntimeException) cause;
            } else {
                throw new RuntimeException(cause);
            }
        } catch (TimeoutException e) {
            future.cancel(true);
            throw new ExternalServiceTimeoutException(String.format("Task timed out trying to connect to existing node '%s' at '%s'", nodeName, hostPort));
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            throw new ExternalServiceException(String.format("Task failed to connect to existing node '%s' at '%s'", nodeName, hostPort));
        }
    } finally {
        executor.shutdown();
    }
}
Also used : ExternalServiceTimeoutException(org.apache.qpid.server.util.ExternalServiceTimeoutException) DaemonThreadFactory(org.apache.qpid.server.util.DaemonThreadFactory) ExternalServiceException(org.apache.qpid.server.util.ExternalServiceException) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) Callable(java.util.concurrent.Callable) ConnectionScopedRuntimeException(org.apache.qpid.server.util.ConnectionScopedRuntimeException) ServerScopedRuntimeException(org.apache.qpid.server.util.ServerScopedRuntimeException) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) ExecutorService(java.util.concurrent.ExecutorService) Collection(java.util.Collection) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException) ExternalServiceTimeoutException(org.apache.qpid.server.util.ExternalServiceTimeoutException) SocketTimeoutException(java.net.SocketTimeoutException)

Example 64 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 65 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)

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