Search in sources :

Example 1 with TransportManager

use of org.eclipse.persistence.sessions.coordination.TransportManager in project eclipselink by eclipse-ee4j.

the class SessionsFactory method buildUserDefinedTransportManagerConfig.

/**
 * INTERNAL:
 */
protected void buildUserDefinedTransportManagerConfig(UserDefinedTransportManagerConfig tmConfig, RemoteCommandManager rcm) {
    TransportManager tm = null;
    // Transport class
    String transportManagerClassName = tmConfig.getTransportClass();
    if (transportManagerClassName != null) {
        try {
            @SuppressWarnings({ "unchecked" }) Class<TransportManager> transportManagerClass = (Class<TransportManager>) m_classLoader.loadClass(transportManagerClassName);
            if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()) {
                tm = AccessController.doPrivileged(new PrivilegedNewInstanceFromClass<>(transportManagerClass));
            } else {
                tm = PrivilegedAccessHelper.newInstanceFromClass(transportManagerClass);
            }
        } catch (Exception exception) {
            throw SessionLoaderException.failedToLoadTag("transport-class", transportManagerClassName, exception);
        }
        // Set the transport manager. This will initialize the DiscoveryManager
        rcm.setTransportManager(tm);
        // Process the common elements in TransportManagerConfig
        processTransportManagerConfig(tmConfig, tm);
    }
}
Also used : PrivilegedNewInstanceFromClass(org.eclipse.persistence.internal.security.PrivilegedNewInstanceFromClass) PrivilegedNewInstanceFromClass(org.eclipse.persistence.internal.security.PrivilegedNewInstanceFromClass) JMSPublishingTransportManager(org.eclipse.persistence.sessions.coordination.jms.JMSPublishingTransportManager) TransportManager(org.eclipse.persistence.sessions.coordination.TransportManager) JMSTopicTransportManager(org.eclipse.persistence.sessions.coordination.jms.JMSTopicTransportManager) RMITransportManager(org.eclipse.persistence.sessions.coordination.rmi.RMITransportManager) ValidationException(org.eclipse.persistence.exceptions.ValidationException) PrivilegedActionException(java.security.PrivilegedActionException) SessionLoaderException(org.eclipse.persistence.exceptions.SessionLoaderException)

Example 2 with TransportManager

use of org.eclipse.persistence.sessions.coordination.TransportManager in project eclipselink by eclipse-ee4j.

the class JGroupsConfigurationTest method test.

@Override
protected void test() throws Throwable {
    AbstractSession session = getAbstractSession();
    RemoteCommandManager rcm = new RemoteCommandManager(session);
    TransportManager transport = (TransportManager) Class.forName("org.eclipse.persistence.sessions.coordination.jgroups.JGroupsTransportManager").getConstructor().newInstance();
    rcm.setTransportManager(transport);
    transport.createLocalConnection();
    RemoteConnection connection = transport.getConnectionToLocalHost();
    try {
        int multicastPort = getMulticastPort(connection);
        Assert.assertEquals("Default multicast port different than expected", 45588, multicastPort);
    } catch (Exception x) {
        Assert.fail("Failed to retrieve multicast port: " + x.getMessage());
    } finally {
        connection.close();
    }
    rcm = new RemoteCommandManager(session);
    transport = (TransportManager) Class.forName("org.eclipse.persistence.sessions.coordination.jgroups.JGroupsTransportManager").getConstructor().newInstance();
    transport.setConfig("org/eclipse/persistence/testing/config/distributedservers/rcm/jgroups/jgroups-udp-config.xml");
    rcm.setTransportManager(transport);
    transport.createLocalConnection();
    connection = transport.getConnectionToLocalHost();
    try {
        int multicastPort = getMulticastPort(connection);
        Assert.assertEquals("Configured multicast port different than expected", 45678, multicastPort);
    } catch (Exception x) {
        Assert.fail("Failed to retrieve multicast port: " + x.getMessage());
    } finally {
        connection.close();
    }
}
Also used : RemoteCommandManager(org.eclipse.persistence.sessions.coordination.RemoteCommandManager) TransportManager(org.eclipse.persistence.sessions.coordination.TransportManager) RemoteConnection(org.eclipse.persistence.internal.sessions.coordination.RemoteConnection) AbstractSession(org.eclipse.persistence.internal.sessions.AbstractSession)

Example 3 with TransportManager

use of org.eclipse.persistence.sessions.coordination.TransportManager in project eclipselink by eclipse-ee4j.

the class JGroupsSetupHelper method createTransportManager.

@Override
protected void createTransportManager(RemoteCommandManager rcm) {
    try {
        TransportManager transport = (TransportManager) Class.forName("org.eclipse.persistence.sessions.coordination.jgroups.JGroupsTransportManager").getConstructor().newInstance();
        rcm.setTransportManager(transport);
    } catch (Exception exception) {
        throw new RuntimeException(exception);
    }
}
Also used : TransportManager(org.eclipse.persistence.sessions.coordination.TransportManager) JMSTopicTransportManager(org.eclipse.persistence.sessions.coordination.jms.JMSTopicTransportManager) RemoteCommandManagerException(org.eclipse.persistence.exceptions.RemoteCommandManagerException)

Example 4 with TransportManager

use of org.eclipse.persistence.sessions.coordination.TransportManager in project eclipselink by eclipse-ee4j.

the class RcmEncryptedPasswordTest method verify.

@Override
public void verify() {
    TransportManager transportMgr = ((AbstractSession) loadedSession).getCommandManager().getTransportManager();
    String encryptedPassword = transportMgr.getPassword();
    if (!encryptedPassword.equals("do-not-encrypt-me")) {
        throw new TestErrorException("Encrypted password [" + encryptedPassword + "] does not match.");
    }
    // test if encryption-class-name is processed
    transportMgr.setPassword("encrypt-me");
    CustomEncryption encryptionObject = new CustomEncryption();
    if (!encryptionObject.decryptPassword(transportMgr.getPassword()).equals("encrypt-me")) {
        throw new TestErrorException("Custom encryption class is not used.");
    }
}
Also used : TestErrorException(org.eclipse.persistence.testing.framework.TestErrorException) TransportManager(org.eclipse.persistence.sessions.coordination.TransportManager)

Example 5 with TransportManager

use of org.eclipse.persistence.sessions.coordination.TransportManager in project eclipselink by eclipse-ee4j.

the class RcmWithRmiAndJndiTest method verify.

@Override
public void verify() {
    RemoteCommandManager rcm = (RemoteCommandManager) ((AbstractSession) loadedSession).getCommandManager();
    TransportManager transportMgr = rcm.getTransportManager();
    Vector errors = new Vector();
    if (!rcm.getChannel().equals("new_channel")) {
        errors.add("channel = " + rcm.getChannel());
    }
    if (!((AbstractSession) loadedSession).shouldPropagateChanges()) {
        errors.add("cache sync is not enable");
    }
    if (rcm.getTransportManager().shouldRemoveConnectionOnError()) {
        errors.add("remove connection on error");
    }
    if (rcm.shouldPropagateAsynchronously()) {
        errors.add("send mode is asynchronous");
    }
    // test Discovery Manager settings
    if (!rcm.getDiscoveryManager().getMulticastGroupAddress().equals("new_address")) {
        errors.add("DM multicast address = " + rcm.getDiscoveryManager().getMulticastGroupAddress());
    }
    if (rcm.getDiscoveryManager().getMulticastPort() != 3333) {
        errors.add("DM multicast port = " + rcm.getDiscoveryManager().getMulticastPort());
    }
    if (rcm.getDiscoveryManager().getAnnouncementDelay() != 1111) {
        errors.add("DM announcement delay = " + rcm.getDiscoveryManager().getAnnouncementDelay());
    }
    // naming services
    if (transportMgr.getNamingServiceType() != TransportManager.JNDI_NAMING_SERVICE) {
        errors.add("Naming service type (not JNDI) = " + transportMgr.getNamingServiceType());
    }
    if (!rcm.getUrl().equals("new_jndi_url")) {
        errors.add("Url = " + rcm.getUrl());
    }
    // transport manager
    String userName = (String) transportMgr.getRemoteContextProperties().get(Context.SECURITY_PRINCIPAL);
    if (userName == null || !userName.equals("new_user_name")) {
        errors.add("user name = " + userName);
    }
    String password = (String) transportMgr.getRemoteContextProperties().get(Context.SECURITY_CREDENTIALS);
    // decrypt password using default encryption
    password = new SecurableObjectHolder().getSecurableObject().decryptPassword(password);
    if (password == null || !password.equals("new_password")) {
        errors.add("password = " + password);
    }
    String contextFactory = (String) transportMgr.getRemoteContextProperties().get(Context.INITIAL_CONTEXT_FACTORY);
    if (contextFactory == null || !contextFactory.equals("new_initial_context_factory_name")) {
        errors.add("initial context factory name = " + contextFactory);
    }
    // extra properties
    String propertyValue1 = (String) transportMgr.getRemoteContextProperties().get("name1");
    String propertyValue2 = (String) transportMgr.getRemoteContextProperties().get("name2");
    if (propertyValue1 == null || !propertyValue1.equals("value1")) {
        errors.add("extra property name =  name1, value = " + propertyValue1);
    }
    if (propertyValue2 == null || !propertyValue2.equals("value2")) {
        errors.add("extra property name =  name2, value = " + propertyValue2);
    }
    if (!errors.isEmpty()) {
        String errorString = "The following RCM elements's value do not match their expected values:";
        for (Enumeration enumtr = errors.elements(); enumtr.hasMoreElements(); ) {
            errorString += "\n   " + enumtr.nextElement();
        }
        throw new TestErrorException(errorString);
    }
}
Also used : Enumeration(java.util.Enumeration) SecurableObjectHolder(org.eclipse.persistence.internal.security.SecurableObjectHolder) RemoteCommandManager(org.eclipse.persistence.sessions.coordination.RemoteCommandManager) TestErrorException(org.eclipse.persistence.testing.framework.TestErrorException) TransportManager(org.eclipse.persistence.sessions.coordination.TransportManager) Vector(java.util.Vector)

Aggregations

TransportManager (org.eclipse.persistence.sessions.coordination.TransportManager)8 JMSTopicTransportManager (org.eclipse.persistence.sessions.coordination.jms.JMSTopicTransportManager)5 RemoteCommandManager (org.eclipse.persistence.sessions.coordination.RemoteCommandManager)4 JMSPublishingTransportManager (org.eclipse.persistence.sessions.coordination.jms.JMSPublishingTransportManager)4 RMITransportManager (org.eclipse.persistence.sessions.coordination.rmi.RMITransportManager)4 PrivilegedActionException (java.security.PrivilegedActionException)2 SessionLoaderException (org.eclipse.persistence.exceptions.SessionLoaderException)2 ValidationException (org.eclipse.persistence.exceptions.ValidationException)2 PrivilegedNewInstanceFromClass (org.eclipse.persistence.internal.security.PrivilegedNewInstanceFromClass)2 TestErrorException (org.eclipse.persistence.testing.framework.TestErrorException)2 Enumeration (java.util.Enumeration)1 Vector (java.util.Vector)1 RemoteCommandManagerException (org.eclipse.persistence.exceptions.RemoteCommandManagerException)1 EntityManagerFactoryProvider.getConfigPropertyAsString (org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.getConfigPropertyAsString)1 PrivilegedInvokeConstructor (org.eclipse.persistence.internal.security.PrivilegedInvokeConstructor)1 SecurableObjectHolder (org.eclipse.persistence.internal.security.SecurableObjectHolder)1 AbstractSession (org.eclipse.persistence.internal.sessions.AbstractSession)1 RemoteConnection (org.eclipse.persistence.internal.sessions.coordination.RemoteConnection)1