Search in sources :

Example 11 with IllegalConfigurationException

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

the class AbstractVirtualHostNode method getInitialRecords.

protected final ConfiguredObjectRecord[] getInitialRecords() throws IOException {
    ConfiguredObjectRecordConverter converter = new ConfiguredObjectRecordConverter(getModel());
    Collection<ConfiguredObjectRecord> records = new ArrayList<>(converter.readFromJson(VirtualHost.class, this, getInitialConfigReader()));
    if (!records.isEmpty()) {
        ConfiguredObjectRecord vhostRecord = null;
        for (ConfiguredObjectRecord record : records) {
            if (record.getType().equals(VirtualHost.class.getSimpleName())) {
                vhostRecord = record;
                break;
            }
        }
        if (vhostRecord != null) {
            records.remove(vhostRecord);
            vhostRecord = enrichInitialVirtualHostRootRecord(vhostRecord);
            records.add(vhostRecord);
        } else {
            // this should be impossible as the converter should always generate a parent record
            throw new IllegalConfigurationException("Somehow the initial configuration has records but " + "not a VirtualHost. This must be a coding error in Qpid");
        }
        addStandardExchangesIfNecessary(records, vhostRecord);
        enrichWithAuditInformation(records);
    }
    return records.toArray(new ConfiguredObjectRecord[records.size()]);
}
Also used : ConfiguredObjectRecordConverter(org.apache.qpid.server.store.ConfiguredObjectRecordConverter) ArrayList(java.util.ArrayList) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) ConfiguredObjectRecord(org.apache.qpid.server.store.ConfiguredObjectRecord) VirtualHost(org.apache.qpid.server.model.VirtualHost) NonStandardVirtualHost(org.apache.qpid.server.virtualhost.NonStandardVirtualHost)

Example 12 with IllegalConfigurationException

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

the class ManagementModeStoreHandlerTest method testSaveCLIHttpPort.

public void testSaveCLIHttpPort() {
    _systemConfigAttributes.put(SystemConfig.MANAGEMENT_MODE_HTTP_PORT_OVERRIDE, 1000);
    _handler = createManagementModeStoreHandler();
    _handler.init(_systemConfig);
    Collection<ConfiguredObjectRecord> records = openAndGetRecords();
    UUID portId = getOptionsPortId(records);
    Map<String, Object> attributes = new HashMap<String, Object>();
    attributes.put(Port.NAME, "TEST");
    ConfiguredObjectRecord configurationEntry = new ConfiguredObjectRecordImpl(portId, Port.class.getSimpleName(), attributes, Collections.singletonMap(Broker.class.getSimpleName(), getRootEntry(records).getId()));
    try {
        _handler.update(false, configurationEntry);
        fail("Exception should be thrown on trying to save CLI port");
    } catch (IllegalConfigurationException e) {
    // pass
    }
}
Also used : ConfiguredObjectRecordImpl(org.apache.qpid.server.store.ConfiguredObjectRecordImpl) HashMap(java.util.HashMap) Port(org.apache.qpid.server.model.Port) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) ConfiguredObjectRecord(org.apache.qpid.server.store.ConfiguredObjectRecord) UUID(java.util.UUID)

Example 13 with IllegalConfigurationException

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

the class AutoGeneratedSelfSignedKeyStoreImpl method generatePrivateKeyAndCertificate.

private void generatePrivateKeyAndCertificate() {
    try {
        Set<InetAddress> addresses = new HashSet<>();
        for (NetworkInterface networkInterface : Collections.list(NetworkInterface.getNetworkInterfaces())) {
            for (InterfaceAddress inetAddress : networkInterface.getInterfaceAddresses()) {
                addresses.add(inetAddress.getAddress());
            }
        }
        Set<String> dnsNames = new HashSet<>();
        for (InetAddress address : addresses) {
            String hostName = address.getHostName();
            if (hostName != null) {
                dnsNames.add(hostName);
            }
            String canonicalHostName = address.getCanonicalHostName();
            if (canonicalHostName != null) {
                dnsNames.add(canonicalHostName);
            }
        }
        long startTime = System.currentTimeMillis();
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(startTime);
        calendar.add(Calendar.MONTH, _durationInMonths);
        long duration = (calendar.getTimeInMillis() - startTime) / 1000;
        final SSLUtil.KeyCertPair keyCertPair = SSLUtil.generateSelfSignedCertificate(_keyAlgorithm, _signatureAlgorithm, _keyLength, startTime, duration, "CN=Qpid", dnsNames, addresses);
        _privateKey = keyCertPair.getPrivateKey();
        _certificate = keyCertPair.getCertificate();
        _generated = true;
    } catch (InstantiationException | IllegalAccessException | InvocationTargetException | IOException e) {
        throw new IllegalConfigurationException("Unable to construct keystore", e);
    }
}
Also used : InterfaceAddress(java.net.InterfaceAddress) Calendar(java.util.Calendar) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) NetworkInterface(java.net.NetworkInterface) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) SSLUtil(org.apache.qpid.server.transport.network.security.ssl.SSLUtil) InetAddress(java.net.InetAddress) HashSet(java.util.HashSet)

Example 14 with IllegalConfigurationException

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

the class FileTrustStoreImpl method initialize.

private void initialize() {
    try {
        KeyStore ts = initializeKeyStore(this);
        _trustManagers = createTrustManagers(ts);
        _certificates = createCertificates(ts);
    } catch (Exception e) {
        throw new IllegalConfigurationException(String.format("Cannot instantiate trust store '%s'", getName()), e);
    }
}
Also used : IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) KeyStore(java.security.KeyStore) KeyStoreException(java.security.KeyStoreException) GeneralSecurityException(java.security.GeneralSecurityException) UnrecoverableKeyException(java.security.UnrecoverableKeyException) ServerScopedRuntimeException(org.apache.qpid.server.util.ServerScopedRuntimeException) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Example 15 with IllegalConfigurationException

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

the class FileTrustStoreImpl method validateTrustStore.

private static void validateTrustStore(FileTrustStore trustStore) {
    KeyStore keyStore;
    try {
        keyStore = initializeKeyStore(trustStore);
    } catch (Exception e) {
        final String message;
        if (e instanceof IOException && e.getCause() != null && e.getCause() instanceof UnrecoverableKeyException) {
            message = "Check trust store password. Cannot instantiate trust store from '" + trustStore.getStoreUrl() + "'.";
        } else {
            message = "Cannot instantiate trust store from '" + trustStore.getStoreUrl() + "'.";
        }
        throw new IllegalConfigurationException(message, e);
    }
    try {
        final Enumeration<String> aliasesEnum = keyStore.aliases();
        boolean certificateFound = false;
        while (aliasesEnum.hasMoreElements()) {
            String alias = aliasesEnum.nextElement();
            if (keyStore.isCertificateEntry(alias)) {
                certificateFound = true;
                break;
            }
        }
        if (!certificateFound) {
            throw new IllegalConfigurationException("Trust store must contain at least one certificate.");
        }
    } catch (KeyStoreException e) {
        throw new ServerScopedRuntimeException("Trust store has not been initialized", e);
    }
    try {
        TrustManagerFactory.getInstance(trustStore.getTrustManagerFactoryAlgorithm());
    } catch (NoSuchAlgorithmException e) {
        throw new IllegalConfigurationException("Unknown trustManagerFactoryAlgorithm: " + trustStore.getTrustManagerFactoryAlgorithm());
    }
}
Also used : UnrecoverableKeyException(java.security.UnrecoverableKeyException) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) IOException(java.io.IOException) KeyStoreException(java.security.KeyStoreException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) KeyStore(java.security.KeyStore) KeyStoreException(java.security.KeyStoreException) GeneralSecurityException(java.security.GeneralSecurityException) UnrecoverableKeyException(java.security.UnrecoverableKeyException) ServerScopedRuntimeException(org.apache.qpid.server.util.ServerScopedRuntimeException) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ServerScopedRuntimeException(org.apache.qpid.server.util.ServerScopedRuntimeException)

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