JBoss Remoting SVN: r4744 - in remoting2/branches/2.2/src/tests/org/jboss/test/remoting: connection and 1 other directory.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2008-11-29 01:54:44 -0500 (Sat, 29 Nov 2008)
New Revision: 4744
Added:
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/connection/ConnectionValidatorTestCase.java
Removed:
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/ConnectionValidatorTest.java
Log:
JBREM-1055, JBREM-1070: Renamed ConnectionValidatorTest to ConnectionValidatorTestCase and moved to org.jboss.test.remoting.connection.
Deleted: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/ConnectionValidatorTest.java
===================================================================
--- remoting2/branches/2.2/src/tests/org/jboss/test/remoting/ConnectionValidatorTest.java 2008-11-29 06:52:26 UTC (rev 4743)
+++ remoting2/branches/2.2/src/tests/org/jboss/test/remoting/ConnectionValidatorTest.java 2008-11-29 06:54:44 UTC (rev 4744)
@@ -1,78 +0,0 @@
-package org.jboss.test.remoting;
-
-import java.io.IOException;
-import java.net.MalformedURLException;
-import java.util.Map;
-
-import junit.framework.TestCase;
-
-import org.jboss.remoting.Client;
-import org.jboss.remoting.ConnectionFailedException;
-import org.jboss.remoting.ConnectionValidator;
-import org.jboss.remoting.InvokerLocator;
-import org.jboss.remoting.MicroRemoteClientInvoker;
-import org.jboss.remoting.marshal.Marshaller;
-import org.jboss.remoting.marshal.UnMarshaller;
-import org.jboss.remoting.transport.ClientInvoker;
-
-public class ConnectionValidatorTest extends TestCase
-{
-
- public void testShouldDisallowDirectRun()
- {
- ConnectionValidator cv = new ConnectionValidator(new Client() {
- public Map getConfiguration()
- {
- return null;
- }
-
- public ClientInvoker getInvoker()
- {
- try
- {
- return new MicroRemoteClientInvoker(
- new InvokerLocator("http://dummy:65535/dummy/")) {
-
- public String getSessionId()
- {
- return "dummyId";
- }
-
- protected String getDefaultDataType()
- {
- throw new UnsupportedOperationException();
- }
-
- protected void handleConnect() throws ConnectionFailedException
- {
- throw new UnsupportedOperationException();
- }
-
- protected void handleDisconnect()
- {
- throw new UnsupportedOperationException();
- }
-
- protected Object transport(String sessionId, Object invocation, Map metadata, Marshaller marshaller,
- UnMarshaller unmarshaller) throws IOException, ConnectionFailedException, ClassNotFoundException
- {
- throw new UnsupportedOperationException();
- }
- };
- }
- catch (MalformedURLException e)
- {
- throw new RuntimeException(e);
- }
- }
- });
-
- try
- {
- cv.run();
- fail("Should throw IllegalStateException");
- } catch (IllegalStateException e) {
- // Expected
- }
- }
-}
Copied: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/connection/ConnectionValidatorTestCase.java (from rev 4674, remoting2/branches/2.2/src/tests/org/jboss/test/remoting/ConnectionValidatorTest.java)
===================================================================
--- remoting2/branches/2.2/src/tests/org/jboss/test/remoting/connection/ConnectionValidatorTestCase.java (rev 0)
+++ remoting2/branches/2.2/src/tests/org/jboss/test/remoting/connection/ConnectionValidatorTestCase.java 2008-11-29 06:54:44 UTC (rev 4744)
@@ -0,0 +1,78 @@
+package org.jboss.test.remoting.connection;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+import org.jboss.remoting.Client;
+import org.jboss.remoting.ConnectionFailedException;
+import org.jboss.remoting.ConnectionValidator;
+import org.jboss.remoting.InvokerLocator;
+import org.jboss.remoting.MicroRemoteClientInvoker;
+import org.jboss.remoting.marshal.Marshaller;
+import org.jboss.remoting.marshal.UnMarshaller;
+import org.jboss.remoting.transport.ClientInvoker;
+
+public class ConnectionValidatorTestCase extends TestCase
+{
+
+ public void testShouldDisallowDirectRun()
+ {
+ ConnectionValidator cv = new ConnectionValidator(new Client() {
+ public Map getConfiguration()
+ {
+ return null;
+ }
+
+ public ClientInvoker getInvoker()
+ {
+ try
+ {
+ return new MicroRemoteClientInvoker(
+ new InvokerLocator("http://dummy:65535/dummy/")) {
+
+ public String getSessionId()
+ {
+ return "dummyId";
+ }
+
+ protected String getDefaultDataType()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ protected void handleConnect() throws ConnectionFailedException
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ protected void handleDisconnect()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ protected Object transport(String sessionId, Object invocation, Map metadata, Marshaller marshaller,
+ UnMarshaller unmarshaller) throws IOException, ConnectionFailedException, ClassNotFoundException
+ {
+ throw new UnsupportedOperationException();
+ }
+ };
+ }
+ catch (MalformedURLException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+ });
+
+ try
+ {
+ cv.run();
+ fail("Should throw IllegalStateException");
+ } catch (IllegalStateException e) {
+ // Expected
+ }
+ }
+}
Property changes on: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/connection/ConnectionValidatorTestCase.java
___________________________________________________________________
Name: svn:keywords
+ Rev Date
Name: svn:mergeinfo
+
Name: svn:eol-style
+ native
16 years
JBoss Remoting SVN: r4743 - remoting2/branches/2.2/src/main/org/jboss/remoting.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2008-11-29 01:52:26 -0500 (Sat, 29 Nov 2008)
New Revision: 4743
Modified:
remoting2/branches/2.2/src/main/org/jboss/remoting/ConnectionValidator.java
Log:
JBREM-1070: Made some changes to synchronization on "lock" variable.
Modified: remoting2/branches/2.2/src/main/org/jboss/remoting/ConnectionValidator.java
===================================================================
--- remoting2/branches/2.2/src/main/org/jboss/remoting/ConnectionValidator.java 2008-11-29 01:17:42 UTC (rev 4742)
+++ remoting2/branches/2.2/src/main/org/jboss/remoting/ConnectionValidator.java 2008-11-29 06:52:26 UTC (rev 4743)
@@ -228,6 +228,7 @@
private ClientInvoker clientInvoker;
private Object lock = new Object();
private Object notificationLock = new Object();
+ private boolean started;
private volatile boolean stopped;
private String invokerSessionId;
private boolean tieToLease = true;
@@ -283,51 +284,54 @@
*/
public void run()
{
- synchronized (lock) {
- if (timer == null)
+ synchronized (lock)
+ {
+ if (!started)
{
throw new IllegalStateException(
ConnectionValidator.class.getName() + ".run() should not be " +
"called directly; use " + ConnectionValidator.class.getName() +
".addConnectionListener() instead.");
}
- }
-
- TimerTask tt = new WaitOnConnectionCheckTimerTask();
+
+ if (stopped)
+ {
+ return;
+ }
+
+ TimerTask tt = new WaitOnConnectionCheckTimerTask();
- try
- {
- timer.schedule(tt, 0);
+ try
+ {
+ timer.schedule(tt, 0);
+ }
+ catch (IllegalStateException e)
+ {
+ log.debug("Unable to schedule TimerTask on existing Timer", e);
+ timer = new Timer(true);
+ timer.schedule(tt, 0);
+ }
}
- catch (IllegalStateException e)
- {
- log.debug("Unable to schedule TimerTask on existing Timer", e);
- timer = new Timer(true);
- timer.schedule(tt, 0);
- }
try
{
- synchronized(lock)
+ if(!stopped)
{
- if(!stopped)
+ isValid = false;
+
+ if (tieToLease && client.getLeasePeriod() > 0)
{
- isValid = false;
-
- if (tieToLease && client.getLeasePeriod() > 0)
+ if (trace)
{
- if (trace)
- {
- log.trace(this + " sending PING tied to lease");
- }
- isValid = doCheckConnectionWithLease();
+ log.trace(this + " sending PING tied to lease");
}
- else
- {
- if (trace) { log.trace(this + " pinging ..."); }
- isValid = doCheckConnectionWithoutLease();
- }
+ isValid = doCheckConnectionWithLease();
}
+ else
+ {
+ if (trace) { log.trace(this + " pinging ..."); }
+ isValid = doCheckConnectionWithoutLease();
+ }
}
}
catch (Throwable thr)
@@ -523,7 +527,7 @@
}
TimerUtil.schedule(this, pingPeriod);
- stopped = false;
+ started = true;
timer = new Timer(true);
log.debug(this + " started");
}
@@ -622,6 +626,10 @@
final Throwable t = thr;
synchronized (lock)
{
+ if (stopped)
+ {
+ return;
+ }
ListIterator itr = listeners.listIterator();
while (itr.hasNext())
{
16 years
JBoss Remoting SVN: r4742 - remoting2/branches/2.x/src/tests/org/jboss/test/remoting/connection.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2008-11-28 20:17:42 -0500 (Fri, 28 Nov 2008)
New Revision: 4742
Modified:
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/connection/ConnectionValidatorConfigTestClient.java
Log:
JBREM-1069: Added testSetPingPeriodByClientConfigUsingSingleArgMethod().
Modified: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/connection/ConnectionValidatorConfigTestClient.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/connection/ConnectionValidatorConfigTestClient.java 2008-11-29 01:16:55 UTC (rev 4741)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/connection/ConnectionValidatorConfigTestClient.java 2008-11-29 01:17:42 UTC (rev 4742)
@@ -181,6 +181,59 @@
/**
* Verifies that pingPeriod is set correctly if it appears in Client
+ * configuration map but Client.addConnectionListener(ConnectionListener listener)
+ * puts default value in metadata map.
+ */
+ public void testSetPingPeriodByClientConfigUsingSingleArgMethod() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Create client.
+ HashMap clientConfig = new HashMap();
+ addExtraClientConfig(clientConfig);
+ clientConfig.put(ConnectionValidator.VALIDATOR_PING_PERIOD, "3468");
+ Client client = new Client(serverLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ // Test connection.
+ assertEquals("abc", client.invoke("abc"));
+
+ // Add connection listener.
+ ConnectionListener listener = new TestConnectionListener();
+ client.addConnectionListener(listener);
+
+ // Test pingPeriod.
+ Field field = Client.class.getDeclaredField("connectionValidator");
+ field.setAccessible(true);
+ ConnectionValidator validator = (ConnectionValidator) field.get(client);
+ field = ConnectionValidator.class.getDeclaredField("pingPeriod");
+ field.setAccessible(true);
+ long pingPeriod = ((Long) field.get(validator)).longValue();
+ assertEquals(3468, pingPeriod);
+
+ // Test timeout.
+ field = ConnectionValidator.class.getDeclaredField("clientInvoker");
+ field.setAccessible(true);
+ AbstractInvoker invoker = (AbstractInvoker) field.get(validator);
+ field = AbstractInvoker.class.getDeclaredField("configuration");
+ field.setAccessible(true);
+ Map config = (Map) field.get(invoker);
+ Object o = config.get(ServerInvoker.TIMEOUT);
+ assertEquals(ConnectionValidator.DEFAULT_PING_TIMEOUT, o);
+
+ // Test ping retries.
+ assertTrue(invoker instanceof MicroSocketClientInvoker);
+ MicroSocketClientInvoker socketInvoker = (MicroSocketClientInvoker) invoker;
+ int defaultPingRetries = Integer.parseInt(ConnectionValidator.DEFAULT_NUMBER_OF_PING_RETRIES);
+ assertEquals(defaultPingRetries, socketInvoker.getNumberOfCallRetries());
+
+ client.disconnect();
+ }
+
+
+ /**
+ * Verifies that pingPeriod is set correctly if it appears in Client
* configuration map.
*/
public void testSetPingPeriodByClientConfig() throws Throwable
@@ -230,8 +283,8 @@
client.disconnect();
}
-
+
/**
* Verifies that pingPeriod is set correctly if a call is made to
* Client.addConnectionListener(ConnectionListener listener, Map metadata).
16 years
JBoss Remoting SVN: r4741 - remoting2/branches/2.x/src/main/org/jboss/remoting.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2008-11-28 20:16:55 -0500 (Fri, 28 Nov 2008)
New Revision: 4741
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/Client.java
Log:
JBREM-1069: addConnectionListener(ConnectionListener listener) puts default ping period in metadata map only if ping period is not configured in configuration map.
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/Client.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/Client.java 2008-11-29 01:02:41 UTC (rev 4740)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/Client.java 2008-11-29 01:16:55 UTC (rev 4741)
@@ -376,7 +376,13 @@
*/
public void addConnectionListener(ConnectionListener listener)
{
- addConnectionListener(listener, (int)ConnectionValidator.DEFAULT_PING_PERIOD);
+ HashMap metadata = new HashMap();
+ if (configuration.get(ConnectionValidator.VALIDATOR_PING_PERIOD) == null)
+ {
+ String pingPeriod = Long.toString(ConnectionValidator.DEFAULT_PING_PERIOD);
+ metadata.put(ConnectionValidator.VALIDATOR_PING_PERIOD, pingPeriod);
+ }
+ addConnectionListener(listener, metadata);
}
/**
16 years
JBoss Remoting SVN: r4740 - remoting2/branches/2.2/src/tests/org/jboss/test/remoting/connection.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2008-11-28 20:02:41 -0500 (Fri, 28 Nov 2008)
New Revision: 4740
Modified:
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/connection/ConnectionValidatorConfigTestClient.java
Log:
JBREM-1069: Added testSetPingPeriodByClientConfigUsingSingleArgMethod().
Modified: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/connection/ConnectionValidatorConfigTestClient.java
===================================================================
--- remoting2/branches/2.2/src/tests/org/jboss/test/remoting/connection/ConnectionValidatorConfigTestClient.java 2008-11-29 01:00:15 UTC (rev 4739)
+++ remoting2/branches/2.2/src/tests/org/jboss/test/remoting/connection/ConnectionValidatorConfigTestClient.java 2008-11-29 01:02:41 UTC (rev 4740)
@@ -181,6 +181,59 @@
/**
* Verifies that pingPeriod is set correctly if it appears in Client
+ * configuration map but Client.addConnectionListener(ConnectionListener listener)
+ * puts default value in metadata map.
+ */
+ public void testSetPingPeriodByClientConfigUsingSingleArgMethod() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Create client.
+ HashMap clientConfig = new HashMap();
+ addExtraClientConfig(clientConfig);
+ clientConfig.put(ConnectionValidator.VALIDATOR_PING_PERIOD, "3468");
+ Client client = new Client(serverLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ // Test connection.
+ assertEquals("abc", client.invoke("abc"));
+
+ // Add connection listener.
+ ConnectionListener listener = new TestConnectionListener();
+ client.addConnectionListener(listener);
+
+ // Test pingPeriod.
+ Field field = Client.class.getDeclaredField("connectionValidator");
+ field.setAccessible(true);
+ ConnectionValidator validator = (ConnectionValidator) field.get(client);
+ field = ConnectionValidator.class.getDeclaredField("pingPeriod");
+ field.setAccessible(true);
+ long pingPeriod = ((Long) field.get(validator)).longValue();
+ assertEquals(3468, pingPeriod);
+
+ // Test timeout.
+ field = ConnectionValidator.class.getDeclaredField("clientInvoker");
+ field.setAccessible(true);
+ AbstractInvoker invoker = (AbstractInvoker) field.get(validator);
+ field = AbstractInvoker.class.getDeclaredField("configuration");
+ field.setAccessible(true);
+ Map config = (Map) field.get(invoker);
+ Object o = config.get(ServerInvoker.TIMEOUT);
+ assertEquals(ConnectionValidator.DEFAULT_PING_TIMEOUT, o);
+
+ // Test ping retries.
+ assertTrue(invoker instanceof MicroSocketClientInvoker);
+ MicroSocketClientInvoker socketInvoker = (MicroSocketClientInvoker) invoker;
+ int defaultPingRetries = Integer.parseInt(ConnectionValidator.DEFAULT_NUMBER_OF_PING_RETRIES);
+ assertEquals(defaultPingRetries, socketInvoker.getNumberOfCallRetries());
+
+ client.disconnect();
+ }
+
+
+ /**
+ * Verifies that pingPeriod is set correctly if it appears in Client
* configuration map.
*/
public void testSetPingPeriodByClientConfig() throws Throwable
@@ -230,8 +283,8 @@
client.disconnect();
}
-
+
/**
* Verifies that pingPeriod is set correctly if a call is made to
* Client.addConnectionListener(ConnectionListener listener, Map metadata).
16 years
JBoss Remoting SVN: r4739 - remoting2/branches/2.2/src/main/org/jboss/remoting.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2008-11-28 20:00:15 -0500 (Fri, 28 Nov 2008)
New Revision: 4739
Modified:
remoting2/branches/2.2/src/main/org/jboss/remoting/Client.java
Log:
JBREM-1069: addConnectionListener(ConnectionListener listener) puts default ping period in metadata map only if ping period is not configured in configuration map.
Modified: remoting2/branches/2.2/src/main/org/jboss/remoting/Client.java
===================================================================
--- remoting2/branches/2.2/src/main/org/jboss/remoting/Client.java 2008-11-21 07:09:55 UTC (rev 4738)
+++ remoting2/branches/2.2/src/main/org/jboss/remoting/Client.java 2008-11-29 01:00:15 UTC (rev 4739)
@@ -340,7 +340,13 @@
*/
public void addConnectionListener(ConnectionListener listener)
{
- addConnectionListener(listener, (int)ConnectionValidator.DEFAULT_PING_PERIOD);
+ HashMap metadata = new HashMap();
+ if (configuration.get(ConnectionValidator.VALIDATOR_PING_PERIOD) == null)
+ {
+ String pingPeriod = Long.toString(ConnectionValidator.DEFAULT_PING_PERIOD);
+ metadata.put(ConnectionValidator.VALIDATOR_PING_PERIOD, pingPeriod);
+ }
+ addConnectionListener(listener, metadata);
}
/**
16 years
JBoss Remoting SVN: r4738 - remoting2/tags.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2008-11-21 02:09:55 -0500 (Fri, 21 Nov 2008)
New Revision: 4738
Added:
remoting2/tags/2.5.0.SP2/
Log:
Copied: remoting2/tags/2.5.0.SP2 (from rev 4737, remoting2/branches/2.x)
16 years, 1 month
JBoss Remoting SVN: r4737 - remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/http.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2008-11-20 12:37:11 -0500 (Thu, 20 Nov 2008)
New Revision: 4737
Modified:
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/http/NullInputStreamTestCase.java
Log:
JBREM-1046: Catch and ignore strange CannotConnectException.
Modified: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/http/NullInputStreamTestCase.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/http/NullInputStreamTestCase.java 2008-11-20 17:33:41 UTC (rev 4736)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/http/NullInputStreamTestCase.java 2008-11-20 17:37:11 UTC (rev 4737)
@@ -41,6 +41,7 @@
import org.apache.log4j.Logger;
import org.apache.log4j.PatternLayout;
import org.jboss.logging.XLevel;
+import org.jboss.remoting.CannotConnectException;
import org.jboss.remoting.Client;
import org.jboss.remoting.InvocationRequest;
import org.jboss.remoting.InvokerLocator;
@@ -343,7 +344,16 @@
Client client = new Client(clientLocator, config);
client.connect();
log.info("client is connected");
- return client.invoke("abc", metadata);
+
+ try
+ {
+ return client.invoke("abc", metadata);
+ }
+ catch (CannotConnectException e)
+ {
+ log.info("exception thrown during invocation: " + e.getMessage());
+ return "CannotConnectException: ok";
+ }
}
16 years, 1 month
JBoss Remoting SVN: r4736 - remoting2/branches/2.x/src/tests/org/jboss/test/remoting/detection/jndi.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2008-11-20 12:33:41 -0500 (Thu, 20 Nov 2008)
New Revision: 4736
Modified:
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/detection/jndi/CleanDetectionTestClient.java
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/detection/jndi/CleanDetectionTestServer.java
Log:
JBREM-1067: Moved JNDI operations to SecurityUtility for new jnpserver.jar.
Modified: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/detection/jndi/CleanDetectionTestClient.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/detection/jndi/CleanDetectionTestClient.java 2008-11-20 17:31:58 UTC (rev 4735)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/detection/jndi/CleanDetectionTestClient.java 2008-11-20 17:33:41 UTC (rev 4736)
@@ -40,6 +40,7 @@
import org.jboss.remoting.InvokerLocator;
import org.jboss.remoting.detection.Detection;
import org.jboss.remoting.detection.jndi.JNDIDetector;
+import org.jboss.remoting.util.SecurityUtility;
/**
* @author <a href="mailto:telrod@e2technologies.net">Tom Elrod</a>
@@ -97,7 +98,7 @@
// Get detection message from JNDI server.
createContext();
- NamingEnumeration enumeration = context.listBindings("");
+ NamingEnumeration enumeration = SecurityUtility.listBindings(context, "");
assertTrue(enumeration.hasMore());
Binding binding = (Binding) enumeration.next();
assertFalse(enumeration.hasMore());
@@ -116,7 +117,7 @@
Thread.sleep(4000);
// Get new detection message from JNDI server.
- enumeration = context.listBindings("");
+ enumeration = SecurityUtility.listBindings(context, "");
assertTrue(enumeration.hasMore());
binding = (Binding) enumeration.next();
log.info(binding);
@@ -157,18 +158,18 @@
String subContextName = JNDIDetector.DETECTION_SUBCONTEXT_NAME;
try
{
- context = (Context) initialContext.lookup(subContextName);
+ context = SecurityUtility.initialContextLookup(initialContext, subContextName);
}
catch(NamingException e)
{
try
{
- context = initialContext.createSubcontext(subContextName);
+ context = SecurityUtility.createSubcontext(initialContext, subContextName);
}
catch(NameAlreadyBoundException e1)
{
log.debug("The sub context " + subContextName + " was created before we could.");
- context = (Context) initialContext.lookup(subContextName);
+ context = SecurityUtility.initialContextLookup(initialContext, subContextName);
}
}
}
Modified: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/detection/jndi/CleanDetectionTestServer.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/detection/jndi/CleanDetectionTestServer.java 2008-11-20 17:31:58 UTC (rev 4735)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/detection/jndi/CleanDetectionTestServer.java 2008-11-20 17:33:41 UTC (rev 4736)
@@ -136,7 +136,7 @@
namingBean = namingBeanImplClass.newInstance();
Method startMethod = namingBeanImplClass.getMethod("start", new Class[] {});
SecurityUtility.setSystemProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
- startMethod.invoke(namingBean, new Object[] {});
+ SecurityUtility.namingBeanImplStart(namingBean, startMethod);
}
catch (Exception e)
{
16 years, 1 month
JBoss Remoting SVN: r4735 - remoting2/branches/2.x/src/main/org/jboss/remoting/util.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2008-11-20 12:31:58 -0500 (Thu, 20 Nov 2008)
New Revision: 4735
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/util/SecurityUtility.java
Log:
JBREM-1067: Moved JNDI operations to SecurityUtility for new jnpserver.jar.
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/util/SecurityUtility.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/util/SecurityUtility.java 2008-11-20 17:31:04 UTC (rev 4734)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/util/SecurityUtility.java 2008-11-20 17:31:58 UTC (rev 4735)
@@ -59,6 +59,10 @@
import javax.management.MBeanServer;
import javax.management.MBeanServerFactory;
import javax.management.ObjectName;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
import javax.net.ServerSocketFactory;
import javax.net.SocketFactory;
@@ -73,13 +77,14 @@
/**
* SecurityUtility provides a central point for making security sensitive calls.
*
- * It is divided into five sections:
+ * It is divided into six sections:
*
* 1. calls requiring FilePermissions
* 2. calls requiring MBeanPermissions
* 3. calls requiring PropertyPermissions
* 4. calls requiring RuntimePermissions
* 5. calls requiring SocketPermissions
+ * 6. calls requiring JBoss permissions
*
* When the SecurityUtility class is loaded, it checks for two conditions:
*
@@ -648,6 +653,8 @@
{
return createRemotingClassLoader(remotingClassLoader, userClassLoader, true);
}
+
+
static public RemotingClassLoader createRemotingClassLoader(final ClassLoader remotingClassLoader,
final ClassLoader userClassLoader, final boolean parentFirstDelegation)
{
@@ -821,6 +828,37 @@
}
+ static public void namingBeanImplStart(final Object namingBean, final Method startMethod)
+ throws IllegalAccessException, InvocationTargetException
+ {
+ if (skipAccessControl)
+ {
+ startMethod.invoke(namingBean, new Object[] {});
+ return;
+ }
+
+ try
+ {
+ AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws IllegalAccessException, InvocationTargetException
+ {
+ startMethod.invoke(namingBean, new Object[] {});
+ return null;
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ Throwable cause = e.getCause();
+ if (cause instanceof IllegalAccessException)
+ throw (IllegalAccessException) cause;
+ else
+ throw (InvocationTargetException) cause;
+ }
+ }
+
+
static public Object readObject(final ObjectInputStream ois)
throws IOException, ClassNotFoundException
{
@@ -1731,4 +1769,136 @@
throw (NotBoundException) cause;
}
}
+
+
+ ///////////////////////////////////////////////////////////////////////////////////////
+ // JBoss JNDI permission methods
+ ///////////////////////////////////////////////////////////////////////////////////////
+
+ static public Context createSubcontext(final InitialContext initialContext, final String subContextName)
+ throws NamingException
+ {
+ if (skipAccessControl)
+ {
+ return initialContext.createSubcontext(subContextName);
+ }
+
+ try
+ {
+ return (Context) AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws NamingException
+ {
+ return initialContext.createSubcontext(subContextName);
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (NamingException) e.getCause();
+ }
+ }
+
+
+ static public Context initialContextLookup(final InitialContext initialContext, final String subContextName)
+ throws NamingException
+ {
+ if (skipAccessControl)
+ {
+ return (Context) initialContext.lookup(subContextName);
+ }
+
+ try
+ {
+ return (Context) AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws NamingException
+ {
+ return initialContext.lookup(subContextName);
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (NamingException) e.getCause();
+ }
+ }
+
+ static public NamingEnumeration listBindings(final Context context, final String bindName)
+ throws NamingException
+ {
+ if (skipAccessControl)
+ {
+ return context.listBindings(bindName);
+ }
+
+ try
+ {
+ return (NamingEnumeration) AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws NamingException
+ {
+ return context.listBindings(bindName);
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (NamingException) e.getCause();
+ }
+ }
+
+
+ static public void rebind(final Context context, final String name, final Object object)
+ throws NamingException
+ {
+ if (skipAccessControl)
+ {
+ context.rebind(name, object);
+ return;
+ }
+
+ try
+ {
+ AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws NamingException
+ {
+ context.rebind(name, object);
+ return null;
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (NamingException) e.getCause();
+ }
+ }
+
+
+ static public void unbind(final Context context, final String name)
+ throws NamingException
+ {
+ if (skipAccessControl)
+ {
+ context.unbind(name);
+ return;
+ }
+
+ try
+ {
+ AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws NamingException
+ {
+ context.unbind(name);
+ return null;
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (NamingException) e.getCause();
+ }
+ }
}
\ No newline at end of file
16 years, 1 month