Search in sources :

Example 1 with PasswordManager

use of org.wso2.securevault.PasswordManager in project wso2-synapse by wso2.

the class JmxAdapter method createContextMap.

/**
 * Creates an environment context map containing the configuration used to start the
 * server connector.
 *
 * @return an environment context map containing the configuration used to start the server
 *         connector
 */
private Map<String, Object> createContextMap() {
    Map<String, Object> env = new HashMap<String, Object>();
    if (jmxInformation.isAuthenticate()) {
        if (jmxInformation.getRemotePasswordFile() != null) {
            env.put("jmx.remote.x.password.file", jmxInformation.getRemotePasswordFile());
        } else {
            SecretInformation secretInformation = jmxInformation.getSecretInformation();
            // Get the global secret resolver
            // TODO This should be properly implemented if JMX adapter is going to use out side synapse
            PasswordManager pwManager = PasswordManager.getInstance();
            if (pwManager.isInitialized()) {
                secretInformation.setGlobalSecretResolver(pwManager.getSecretResolver());
            }
            env.put(JMXConnectorServer.AUTHENTICATOR, new JmxSecretAuthenticator(jmxInformation.getSecretInformation()));
        }
        if (jmxInformation.getRemoteAccessFile() != null) {
            env.put("jmx.remote.x.access.file", jmxInformation.getRemoteAccessFile());
        }
    } else {
        log.warn("Using unsecured JMX remote access!");
    }
    if (jmxInformation.isRemoteSSL()) {
        log.info("Activated SSL communication");
        env.put("jmx.remote.rmi.client.socket.factory", new SslRMIClientSocketFactory());
        env.put("jmx.remote.rmi.server.socket.factory", new SslRMIServerSocketFactory());
    }
    return env;
}
Also used : SslRMIClientSocketFactory(javax.rmi.ssl.SslRMIClientSocketFactory) SecretInformation(org.wso2.securevault.secret.SecretInformation) HashMap(java.util.HashMap) PasswordManager(org.wso2.securevault.PasswordManager) JmxSecretAuthenticator(org.apache.synapse.commons.jmx.JmxSecretAuthenticator) SslRMIServerSocketFactory(javax.rmi.ssl.SslRMIServerSocketFactory)

Example 2 with PasswordManager

use of org.wso2.securevault.PasswordManager in project wso2-synapse by wso2.

the class EventSourceFactory method createEventSource.

@SuppressWarnings({ "UnusedDeclaration" })
public static SynapseEventSource createEventSource(OMElement elem, Properties properties) {
    SynapseEventSource eventSource = null;
    OMAttribute name = elem.getAttribute(new QName(XMLConfigConstants.NULL_NAMESPACE, "name"));
    if (name == null) {
        handleException("The 'name' attribute is required for a event source de");
    } else {
        eventSource = new SynapseEventSource(name.getAttributeValue());
    }
    OMElement subscriptionManagerElem = elem.getFirstChildWithName(SUBSCRIPTION_MANAGER_QNAME);
    if (eventSource != null && subscriptionManagerElem != null) {
        OMAttribute clazz = subscriptionManagerElem.getAttribute(new QName(XMLConfigConstants.NULL_NAMESPACE, "class"));
        if (clazz != null) {
            String className = clazz.getAttributeValue();
            try {
                Class subscriptionManagerClass = Class.forName(className);
                SubscriptionManager manager = (SubscriptionManager) subscriptionManagerClass.newInstance();
                Iterator itr = subscriptionManagerElem.getChildrenWithName(PROPERTIES_QNAME);
                while (itr.hasNext()) {
                    OMElement propElem = (OMElement) itr.next();
                    String propName = propElem.getAttribute(new QName("name")).getAttributeValue();
                    String propValue = propElem.getAttribute(new QName("value")).getAttributeValue();
                    if (propName != null && !"".equals(propName.trim()) && propValue != null && !"".equals(propValue.trim())) {
                        propName = propName.trim();
                        propValue = propValue.trim();
                        PasswordManager passwordManager = PasswordManager.getInstance();
                        String key = eventSource.getName() + "." + propName;
                        if (passwordManager.isInitialized() && passwordManager.isTokenProtected(key)) {
                            eventSource.putConfigurationProperty(propName, propValue);
                            propValue = passwordManager.resolve(propValue);
                        }
                        manager.addProperty(propName, propValue);
                    }
                }
                eventSource.setSubscriptionManager(manager);
                eventSource.getSubscriptionManager().init();
            } catch (ClassNotFoundException e) {
                handleException("SubscriptionManager class not found", e);
            } catch (IllegalAccessException e) {
                handleException("Unable to access the SubscriptionManager object", e);
            } catch (InstantiationException e) {
                handleException("Unable to instantiate the SubscriptionManager object", e);
            }
        } else {
            handleException("SynapseSubscription manager class is a required attribute");
        }
    } else {
        handleException("SynapseSubscription Manager has not been specified for the event source");
    }
    try {
        createStaticSubscriptions(elem, eventSource);
    } catch (EventException e) {
        handleException("Static subscription creation failure", e);
    }
    return eventSource;
}
Also used : SynapseEventSource(org.apache.synapse.eventing.SynapseEventSource) EventException(org.wso2.eventing.exceptions.EventException) QName(javax.xml.namespace.QName) PasswordManager(org.wso2.securevault.PasswordManager) OMElement(org.apache.axiom.om.OMElement) SubscriptionManager(org.wso2.eventing.SubscriptionManager) Iterator(java.util.Iterator) OMAttribute(org.apache.axiom.om.OMAttribute)

Example 3 with PasswordManager

use of org.wso2.securevault.PasswordManager in project wso2-synapse by wso2.

the class ServerManager method doShutdown.

/**
 * Helper method to shutdown the the ServerManager
 */
private void doShutdown() {
    ServerState serverState = ServerStateDetectionStrategy.currentState(serverContextInformation, serverConfigurationInformation);
    if (serverState == ServerState.INITIALIZED || serverState == ServerState.STOPPED) {
        // shutdown debug manager and close TCP connection in the debug interface
        if (serverContextInformation.isServerDebugModeEnabled()) {
            serverContextInformation.getSynapseDebugManager().shutdownDebugManager();
        }
        // Shutdown global PasswordManager instance used in synapse
        PasswordManager passwordManager = PasswordManager.getInstance();
        if (passwordManager.isInitialized()) {
            PasswordManager.getInstance().shutDown();
        }
        // un-register the ServerManager MBean
        unRegisterMBean();
        // destroy the SynapseController
        synapseController.destroy();
        // mark as destroyed
        changeState(ServerState.UNDETERMINED);
    } else {
        // if the server cannot be destroyed just set the current state as the server state
        changeState(serverState);
    }
}
Also used : PasswordManager(org.wso2.securevault.PasswordManager)

Aggregations

PasswordManager (org.wso2.securevault.PasswordManager)3 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 SslRMIClientSocketFactory (javax.rmi.ssl.SslRMIClientSocketFactory)1 SslRMIServerSocketFactory (javax.rmi.ssl.SslRMIServerSocketFactory)1 QName (javax.xml.namespace.QName)1 OMAttribute (org.apache.axiom.om.OMAttribute)1 OMElement (org.apache.axiom.om.OMElement)1 JmxSecretAuthenticator (org.apache.synapse.commons.jmx.JmxSecretAuthenticator)1 SynapseEventSource (org.apache.synapse.eventing.SynapseEventSource)1 SubscriptionManager (org.wso2.eventing.SubscriptionManager)1 EventException (org.wso2.eventing.exceptions.EventException)1 SecretInformation (org.wso2.securevault.secret.SecretInformation)1