Search in sources :

Example 1 with ConnectionListener

use of org.jivesoftware.openfire.spi.ConnectionListener in project Openfire by igniterealtime.

the class CertificateStoreManager method replaceTrustStore.

public void replaceTrustStore(ConnectionType type, CertificateStoreConfiguration configuration, boolean createIfAbsent) throws CertificateStoreConfigException {
    if (type == null) {
        throw new IllegalArgumentException("Argument 'type' cannot be null.");
    }
    if (configuration == null) {
        throw new IllegalArgumentException("Argument 'configuration' cannot be null.");
    }
    // can be null if persisted properties are invalid
    final CertificateStoreConfiguration oldConfig = typeToTrustStore.get(type);
    if (oldConfig == null || !oldConfig.equals(configuration)) {
        // If the new store is not already being used by any other type, it'll need to be registered.
        if (!trustStores.containsKey(configuration)) {
            // This constructor can throw an exception. If it does, the state of the manager should not have already changed.
            final TrustStore store = new TrustStore(configuration, createIfAbsent);
            trustStores.put(configuration, store);
            storeWatcher.watch(store);
        }
        typeToTrustStore.put(type, configuration);
        // If the old store is not used by any other type, it can be shut down.
        if (oldConfig != null && !typeToTrustStore.containsValue(oldConfig)) {
            final TrustStore store = trustStores.remove(oldConfig);
            if (store != null) {
                storeWatcher.unwatch(store);
            }
        }
        // Update all connection listeners that were using the old configuration.
        final ConnectionManagerImpl connectionManager = ((ConnectionManagerImpl) XMPPServer.getInstance().getConnectionManager());
        for (ConnectionListener connectionListener : connectionManager.getListeners(type)) {
            try {
                connectionListener.setTrustStoreConfiguration(configuration);
            } catch (RuntimeException e) {
                Log.warn("An exception occurred while trying to update the trust store configuration for connection type '" + type + "'", e);
            }
        }
    }
    // Always store the new configuration in properties, to make sure that we override a potential fallback.
    // FIXME ensure that this is relative to Openfire home!
    JiveGlobals.setProperty(type.getPrefix() + "truststore", configuration.getFile().getPath());
    JiveGlobals.setProperty(type.getPrefix() + "trustpass", new String(configuration.getPassword()), true);
}
Also used : ConnectionManagerImpl(org.jivesoftware.openfire.spi.ConnectionManagerImpl) ConnectionListener(org.jivesoftware.openfire.spi.ConnectionListener)

Example 2 with ConnectionListener

use of org.jivesoftware.openfire.spi.ConnectionListener in project Openfire by igniterealtime.

the class CertificateStoreManager method replaceIdentityStore.

public void replaceIdentityStore(ConnectionType type, CertificateStoreConfiguration configuration, boolean createIfAbsent) throws CertificateStoreConfigException {
    if (type == null) {
        throw new IllegalArgumentException("Argument 'type' cannot be null.");
    }
    if (configuration == null) {
        throw new IllegalArgumentException("Argument 'configuration' cannot be null.");
    }
    // can be null if persisted properties are invalid
    final CertificateStoreConfiguration oldConfig = typeToIdentityStore.get(type);
    if (oldConfig == null || !oldConfig.equals(configuration)) {
        // If the new store is not already being used by any other type, it'll need to be registered.
        if (!identityStores.containsKey(configuration)) {
            // This constructor can throw an exception. If it does, the state of the manager should not have already changed.
            final IdentityStore store = new IdentityStore(configuration, createIfAbsent);
            identityStores.put(configuration, store);
            storeWatcher.watch(store);
        }
        typeToIdentityStore.put(type, configuration);
        // If the old store is not used by any other type, it can be shut down.
        if (oldConfig != null && !typeToIdentityStore.containsValue(oldConfig)) {
            final IdentityStore store = identityStores.remove(oldConfig);
            if (store != null) {
                storeWatcher.unwatch(store);
            }
        }
        // Update all connection listeners that were using the old configuration.
        final ConnectionManagerImpl connectionManager = ((ConnectionManagerImpl) XMPPServer.getInstance().getConnectionManager());
        for (ConnectionListener connectionListener : connectionManager.getListeners(type)) {
            try {
                connectionListener.setIdentityStoreConfiguration(configuration);
            } catch (RuntimeException e) {
                Log.warn("An exception occurred while trying to update the identity store configuration for connection type '" + type + "'", e);
            }
        }
    }
    // Always store the new configuration in properties, to make sure that we override a potential fallback.
    // FIXME ensure that this is relative to Openfire home!
    JiveGlobals.setProperty(type.getPrefix() + "keystore", configuration.getFile().getPath());
    JiveGlobals.setProperty(type.getPrefix() + "keypass", new String(configuration.getPassword()), true);
}
Also used : ConnectionManagerImpl(org.jivesoftware.openfire.spi.ConnectionManagerImpl) ConnectionListener(org.jivesoftware.openfire.spi.ConnectionListener)

Aggregations

ConnectionListener (org.jivesoftware.openfire.spi.ConnectionListener)2 ConnectionManagerImpl (org.jivesoftware.openfire.spi.ConnectionManagerImpl)2