JBoss Remoting SVN: r4138 - remoting2/branches/2.x/src/etc.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2008-05-07 19:49:10 -0400 (Wed, 07 May 2008)
New Revision: 4138
Modified:
remoting2/branches/2.x/src/etc/remoting.security.policy.core
Log:
JBREM-920, JBREM-977: Added documentation about MBean proxies; removed some unnecessary permissions and comment lines.
Modified: remoting2/branches/2.x/src/etc/remoting.security.policy.core
===================================================================
--- remoting2/branches/2.x/src/etc/remoting.security.policy.core 2008-05-07 23:42:08 UTC (rev 4137)
+++ remoting2/branches/2.x/src/etc/remoting.security.policy.core 2008-05-07 23:49:10 UTC (rev 4138)
@@ -27,18 +27,27 @@
//**** with the permissions necessary to run the code in the org.jboss.remoting.*
//**** packages. All security sensitive calls in Remoting are wrapped in a
//**** java.security.AccessController.doPrivileged() call, so that Remoting classes
-//**** can function in the context of a java.lang.SecurityManager, given the permissions
-//**** listed below, even if the calling code runs without these restrictions.
+//**** can function in the context of a java.lang.SecurityManager, given the some
+//**** variation on the permissionslisted below, even if the calling code runs without
+//**** these restrictions.
//****
//**** There are two ways in which it may be necessary or desirable to modify the
//**** the permissions listed below.
//****
//**** 1. It may be necessary to change the java.io.FilePermission permissions, according
-//**** to the configuration of certain files. See the "File permissions" section below.
+//**** to the configuration of certain files. See the "File permissions" section below,
+//**** as well as the accompanying remoting.security.policy.tests file, which is used
+//**** to run the Remoting test suite.
//****
-//**** 2. Some permission may be eliminated, according to which Remoting facilities are used.
+//**** 2. If Remoting is configured to operate with one or more MBeans in place of POJOs,
+//**** it might be necessary to grant additional MBeanPermissions. See the MBean
+//**** permissions section below, as well as the MBeanPermissions granted to the
+//**** org.jboss.test.remoting.security.*ProxyTestCase test classes in the accompanying
+//**** remoting.security.policy.tests file, which is used to run the Remoting test suite
//****
-//**** Other than changes made according to item 1, it should not be necessary to grant
+//**** 3. Some permission may be eliminated, according to which Remoting facilities are used.
+//****
+//**** Other than changes made according to items 1 and 2, it should not be necessary to grant
//**** any additional permissions.
//****
//***************************************************
@@ -68,37 +77,32 @@
permission java.io.FilePermission ".", "read, write";
permission java.io.FilePermission "*", "read, write";
-
-/////////////////////////////////////////////////////////////////////////////////////////////
-// Runtime permissions
+// // Some variation of the following would be needed for SSL transports:
+// permission java.io.FilePermission "${keystore}", "read";
+// permission java.io.FilePermission "${truststore}", "read";
- // Used by remote class loading system
- permission java.lang.RuntimePermission "createClassLoader";
- permission java.lang.RuntimePermission "getClassLoader";
- // Used by:
- // org.jboss.remoting.security.SSLSocketBuilder
- // org.jboss.remoting.transport.coyote.CoyoteInvoker
- // org.jboss.remoting.transport.http.HTTPClientInvoker
- // org.jboss.remoting.transport.servlet.web.ServerInvokerServlet
- // org.jboss.remoting.transporter.TransporterHandler
- // org.jboss.remoting.InvokerRegistry
- permission java.lang.RuntimePermission "accessClassInPackage.*";
-
- // Used by org.jboss.remoting.transport.coyote.CoyoteInvoker
- permission java.lang.RuntimePermission "loadLibrary.tcnative-1";
- permission java.lang.RuntimePermission "loadLibrary.libtcnative-1";
-
-
/////////////////////////////////////////////////////////////////////////////////////////////
// MBean permissions
+// // Some variation of the following might be needed if Remoting gets an MBean in place of an ordinary object.
+// permission javax.management.MBeanPermission "*#MBeanServer[*:*]", "setAttribute";
+//
+// // For example, if a Connector is configured with MBean ServerInvocationHandler:
+// permission javax.management.MBeanPermission "com.bluemonkey.ServerInvocationHandler#MBeanServer[*:*]", "setAttribute";
+//
+// // Some variation of the following might be needed if Remoting gets an MBean in place of an ordinary object.
+// //permission javax.management.MBeanPermission *#*[*:*]", "invoke, registerMBean, unregisterMBean";
+//
+// // For example, if a Connector is configured with an MBean ServerSocketFactory:
+// //permission javax.management.MBeanPermission "com.bluemonkey.ServerSocketFactory#createServerSocket[acme:type=serversocketfactory]", "invoke";
+
permission javax.management.MBeanTrustPermission "register";
- // Used by org.jboss.remoting.callback.ServerInvokerCallbackHandler ?? getClassLoader
+ // Used by org.jboss.remoting.callback.ServerInvokerCallbackHandler
permission javax.management.MBeanPermission "*#SSLSocketBuilder[*:*]", "getAttribute";
- permission javax.management.MBeanPermission "*#-[*:*]", "isInstanceOf";
-
+ permission javax.management.MBeanPermission "*#-[*:*]", "isInstanceOf";
+
// Used by org.jboss.remoting.detection.AbstractDetector
permission javax.management.MBeanPermission "*#addServer[remoting:type=NetworkRegistry]", "invoke";
permission javax.management.MBeanPermission "*#updateServer[remoting:type=NetworkRegistry]", "invoke";
@@ -118,16 +122,10 @@
// Used by org.jboss.remoting.network.NetworkRegistryFinder
permission javax.management.MBeanPermission "*#-[*:*]", "queryMBeans";
- // Used by org.jboss.remoting.network.NetworkRegistryQuery // need getClassloaderFor ??
+ // Used by org.jboss.remoting.network.NetworkRegistryQuery
permission javax.management.MBeanPermission "org.jboss.remoting.network.NetworkRegistry#-[*:*]", "isInstanceOf";
-
- // Used by org.jboss.remoting.security.CustomSSLServerSocketFactory // necessary ??
-// permission javax.management.MBeanPermission "org.jboss.remoting.security.CustomSSLServerSocketFactory#*[*:*]", "invoke";
-
- // Used by org.jboss.remoting.security.ServerSocketFactoryWrapper
- permission javax.management.MBeanPermission "*#createServerSocket[*:*]", "invoke";
-
- // Used by org.jboss.remoting.transport.Connector // isInstanceOf ??
+
+ // Used by org.jboss.remoting.transport.Connector
permission javax.management.MBeanPermission "org.jboss.remoting.transport.*#-[jboss.remoting:service=invoker,*]", "registerMBean, unregisterMBean";
// Used by org.jboss.remoting.transport.servlet.web.ServerInvokerServlet
@@ -141,6 +139,27 @@
/////////////////////////////////////////////////////////////////////////////////////////////
+// Runtime permissions
+
+ // Used by remote class loading system
+ permission java.lang.RuntimePermission "createClassLoader";
+ permission java.lang.RuntimePermission "getClassLoader";
+
+ // Used by:
+ // org.jboss.remoting.security.SSLSocketBuilder
+ // org.jboss.remoting.transport.coyote.CoyoteInvoker
+ // org.jboss.remoting.transport.http.HTTPClientInvoker
+ // org.jboss.remoting.transport.servlet.web.ServerInvokerServlet
+ // org.jboss.remoting.transporter.TransporterHandler
+ // org.jboss.remoting.InvokerRegistry
+ permission java.lang.RuntimePermission "accessClassInPackage.*";
+
+ // Used by org.jboss.remoting.transport.coyote.CoyoteInvoker
+ permission java.lang.RuntimePermission "loadLibrary.tcnative-1";
+ permission java.lang.RuntimePermission "loadLibrary.libtcnative-1";
+
+
+/////////////////////////////////////////////////////////////////////////////////////////////
// Socket permissions. Can't create sockets without it.
permission java.net.SocketPermission "*:*", "accept,connect,listen,resolve";
@@ -198,6 +217,8 @@
// Used by Used by org.jboss.remoting.transport.coyote.CoyoteInvoker
permission java.util.PropertyPermission "java.library.path", "read";
+ permission java.util.PropertyPermission "org.apache.tomcat.util.*", "read";
+ permission java.util.PropertyPermission "tomcat.util.buf.StringCache.*", "read";
// Used by org.jboss.remoting.transport.http.HTTPClientInvoker
permission java.util.PropertyPermission "http.basic.password", "read";
@@ -207,16 +228,11 @@
permission java.util.PropertyPermission "org.jboss.security.ignoreHttpsHost" , "read";
// Used by org.jboss.remoting.util.SecurityUtility
-// permission java.util.PropertyPermission "java.security.manager", "read";
permission java.util.PropertyPermission "skipAccessControl", "read";
// Used by org.jboss.remoting.Version
permission java.util.PropertyPermission "jboss.remoting.pre_2_0_compatible", "read";
permission java.util.PropertyPermission "jboss.remoting.version", "read, write";
-
- // ????
- permission java.util.PropertyPermission "org.apache.tomcat.util.*", "read";
- permission java.util.PropertyPermission "tomcat.util.buf.StringCache.*", "read";
/////////////////////////////////////////////////////////////////////////////////////////////
@@ -237,16 +253,10 @@
// Permissions used by Logging
// [TODO - We should use a version of JBoss logging + log4j that does this stuff in privileged blocks]
-// permission java.io.FilePermission "${build.home}${/}src${/}etc${/}log4j.properties", "read";
-// permission java.io.FilePermission "${build.home}${/}src${/}etc${/}log4j.xml", "read";
-// permission java.io.FilePermission "${build.home}${/}lib${/}apache-log4j${/}lib${/}log4j.jar", "read";
-// permission java.io.FilePermission "file:${build.home}/output/lib/jboss-remoting.jar", "read";
-
permission java.io.FilePermission "${remoting.jar.dir}${/}jboss-remoting.jar", "read";
permission java.io.FilePermission "${log4j.jar.dir}${/}log4j.jar", "read";
permission java.io.FilePermission "${log4j.config.dir}${/}log4j.properties", "read";
permission java.io.FilePermission "${log4j.config.dir}${/}log4j.xml", "read";
-// permission java.io.FilePermission "${build.home}${/}output${/}classes${/}-", "read";
permission java.util.PropertyPermission "org.jboss.logging.Logger.pluginClass", "read";
permission java.util.PropertyPermission "log4j.defaultInitOverride", "read";
@@ -260,6 +270,5 @@
permission java.util.PropertyPermission "log4j.debug", "read";
permission java.util.PropertyPermission "log4j.configuration", "read";
permission java.util.PropertyPermission "org.apache.commons.logging.*", "read";
-// permission java.util.PropertyPermission "org.apache.commons.logging.Log", "read";
};
16 years, 8 months
JBoss Remoting SVN: r4137 - in remoting2/branches/2.x/src/tests/org/jboss/test/remoting: security and 1 other directory.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2008-05-07 19:42:08 -0400 (Wed, 07 May 2008)
New Revision: 4137
Added:
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/security/
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/security/CallbackErrorHandlerProxyTestCase.java
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/security/CallbackStoreProxyTestCase.java
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/security/NetworkRegistryProxyTestCase.java
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/security/ServerInvokerHandlerProxyTestCase.java
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/security/ServerSocketFactoryProxyTestCase.java
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/security/TestCallbackErrorHandler.java
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/security/TestCallbackErrorHandlerMBean.java
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/security/TestCallbackStore.java
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/security/TestCallbackStoreMBean.java
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/security/TestNetworkRegistry.java
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/security/TestNetworkRegistryMBean.java
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/security/TestServerInvocationHandler.java
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/security/TestServerInvocationHandlerMBean.java
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/security/TestServerSocketFactory.java
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/security/TestServerSocketFactoryMBean.java
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/security/keystore
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/security/truststore
Log:
JBREM-977: New unit tests.
Added: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/security/CallbackErrorHandlerProxyTestCase.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/security/CallbackErrorHandlerProxyTestCase.java (rev 0)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/security/CallbackErrorHandlerProxyTestCase.java 2008-05-07 23:42:08 UTC (rev 4137)
@@ -0,0 +1,236 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.remoting.security;
+
+import java.net.InetAddress;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.management.MBeanServer;
+import javax.management.MBeanServerFactory;
+import javax.management.ObjectName;
+
+import junit.framework.TestCase;
+
+import org.apache.log4j.ConsoleAppender;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.apache.log4j.PatternLayout;
+import org.jboss.logging.XLevel;
+import org.jboss.remoting.Client;
+import org.jboss.remoting.InvocationRequest;
+import org.jboss.remoting.InvokerLocator;
+import org.jboss.remoting.ServerInvocationHandler;
+import org.jboss.remoting.ServerInvoker;
+import org.jboss.remoting.callback.Callback;
+import org.jboss.remoting.callback.HandleCallbackException;
+import org.jboss.remoting.callback.InvokerCallbackHandler;
+import org.jboss.remoting.callback.ServerInvokerCallbackHandler;
+import org.jboss.remoting.transport.Connector;
+import org.jboss.remoting.transport.PortUtil;
+
+
+/**
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright May 4, 2008
+ * </p>
+ */
+public class CallbackErrorHandlerProxyTestCase extends TestCase
+{
+ private static Logger log = Logger.getLogger(CallbackErrorHandlerProxyTestCase.class);
+
+ private static boolean firstTime = true;
+ protected String host;
+ protected int port;
+ protected String locatorURI;
+ protected InvokerLocator serverLocator;
+ protected Connector connector;
+ protected TestCallbackErrorHandler errorHandler;
+ protected MBeanServer server;
+ protected ObjectName errorHandlerObjectName;
+
+
+ public void setUp() throws Exception
+ {
+ if (firstTime)
+ {
+ firstTime = false;
+ Logger.getLogger("org.jboss.remoting").setLevel(XLevel.INFO);
+ Logger.getLogger("org.jboss.test.remoting").setLevel(Level.INFO);
+ String pattern = "[%d{ABSOLUTE}] [%t] %5p (%F:%L) - %m%n";
+ PatternLayout layout = new PatternLayout(pattern);
+ ConsoleAppender consoleAppender = new ConsoleAppender(layout);
+ Logger.getRootLogger().addAppender(consoleAppender);
+ }
+ }
+
+
+ public void tearDown()
+ {
+ }
+
+
+ public void testCallbackStoreProxy() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer();
+ log.info("ServerInvocationHandler: " + errorHandler);
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ // Check connection.
+ assertEquals("abc", client.invoke("abc"));
+ log.info("connection is good");
+
+ // Verify callbacks work.
+ TestCallbackHandler callbackHandler = new TestCallbackHandler();
+ client.addListener(callbackHandler, null, null, true);
+ assertEquals(1, callbackHandler.counter);
+
+ // Verify CallbackErrorHandler proxy gets used.
+ client.addListener(callbackHandler, null, null, true);
+ assertEquals(1, callbackHandler.counter);
+ assertEquals(1, errorHandler.counter);
+ int counter = ((Integer) server.getAttribute(errorHandlerObjectName, "Counter")).intValue();
+ assertEquals(errorHandler.counter, counter);
+
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ protected String getTransport()
+ {
+ return "socket";
+ }
+
+
+ protected void addExtraClientConfig(Map config) {}
+ protected void addExtraServerConfig(Map config) {}
+
+
+ protected void setupServer() throws Exception
+ {
+ host = InetAddress.getLocalHost().getHostAddress();
+ port = PortUtil.findFreePort(host);
+ locatorURI = getTransport() + "://" + host + ":" + port;
+ serverLocator = new InvokerLocator(locatorURI);
+ log.info("Starting remoting server with locator uri of: " + locatorURI);
+ HashMap config = new HashMap();
+ config.put(InvokerLocator.FORCE_REMOTE, "true");
+ addExtraServerConfig(config);
+
+ // Create CallbackErrorHandler.
+ server = MBeanServerFactory.createMBeanServer();
+ errorHandler = new TestCallbackErrorHandler();
+ String objectNameString = "test:type=TestCallbackErrorHandler";
+ errorHandlerObjectName = new ObjectName(objectNameString);
+ server.registerMBean(errorHandler, errorHandlerObjectName);
+ config.put(ServerInvokerCallbackHandler.CALLBACK_ERROR_HANDLER_KEY, objectNameString);
+
+ // Create Connector..
+ connector = new Connector(serverLocator, config);
+ server.registerMBean(connector, new ObjectName("test:type=Connector"));
+ connector.create();
+ connector.addInvocationHandler("test", new TestServerInvocationHandler());
+ connector.start();
+ }
+
+
+ protected void shutdownServer() throws Exception
+ {
+ if (connector != null)
+ connector.stop();
+ }
+
+
+ public static class TestServerInvocationHandler implements ServerInvocationHandler
+ {
+ static Logger log = Logger.getLogger(TestServerInvocationHandler.class);
+ private int counter;
+
+ public void addListener(InvokerCallbackHandler callbackHandler)
+ {
+ try
+ {
+ if (counter++ == 0)
+ {
+ // First time, send callback.
+ callbackHandler.handleCallback(new Callback("callback"));
+ }
+ else
+ {
+ // Next, generate callback exception.
+ callbackHandler.handleCallback(new Callback(new NotSerializable()));
+ }
+ }
+ catch (HandleCallbackException e)
+ {
+ if (counter == 0)
+ log.error("Unexpected exception", e);
+ else
+ log.info("Expected exception: " + e.getMessage());
+ }
+ }
+
+ public Object invoke(final InvocationRequest invocation) throws Throwable
+ {
+ return invocation.getParameter();
+ }
+
+ public void removeListener(InvokerCallbackHandler callbackHandler) {}
+ public void setMBeanServer(MBeanServer server) {}
+ public void setInvoker(ServerInvoker invoker) {}
+
+ public int getCounter()
+ {
+ return counter;
+ }
+ }
+
+
+ static class TestCallbackHandler implements InvokerCallbackHandler
+ {
+ int counter;
+
+ public void handleCallback(Callback callback) throws HandleCallbackException
+ {
+ counter++;
+ log.info("received callback");
+ }
+ }
+
+ static class NotSerializable {}
+}
\ No newline at end of file
Added: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/security/CallbackStoreProxyTestCase.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/security/CallbackStoreProxyTestCase.java (rev 0)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/security/CallbackStoreProxyTestCase.java 2008-05-07 23:42:08 UTC (rev 4137)
@@ -0,0 +1,288 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.remoting.security;
+
+import java.net.InetAddress;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.management.MBeanServer;
+import javax.management.MBeanServerFactory;
+import javax.management.ObjectName;
+
+import junit.framework.TestCase;
+
+import org.apache.log4j.ConsoleAppender;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.apache.log4j.PatternLayout;
+import org.jboss.logging.XLevel;
+import org.jboss.remoting.Client;
+import org.jboss.remoting.InvocationRequest;
+import org.jboss.remoting.InvokerLocator;
+import org.jboss.remoting.ServerInvocationHandler;
+import org.jboss.remoting.ServerInvoker;
+import org.jboss.remoting.callback.Callback;
+import org.jboss.remoting.callback.HandleCallbackException;
+import org.jboss.remoting.callback.InvokerCallbackHandler;
+import org.jboss.remoting.callback.ServerInvokerCallbackHandler;
+import org.jboss.remoting.transport.Connector;
+import org.jboss.remoting.transport.PortUtil;
+
+
+/**
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright May 4, 2008
+ * </p>
+ */
+public class CallbackStoreProxyTestCase extends TestCase
+{
+ private static Logger log = Logger.getLogger(CallbackStoreProxyTestCase.class);
+
+ private static boolean firstTime = true;
+ private static boolean done;
+
+ protected String host;
+ protected int port;
+ protected String locatorURI;
+ protected InvokerLocator serverLocator;
+ protected Connector connector;
+ protected TestInvocationHandler invocationHandler;
+ protected TestCallbackStore callbackStore;
+ protected MBeanServer server;
+ protected ObjectName callbackStoreObjectName;
+
+
+ public void setUp() throws Exception
+ {
+ if (firstTime)
+ {
+ firstTime = false;
+ Logger.getLogger("org.jboss.remoting").setLevel(XLevel.INFO);
+ Logger.getLogger("org.jboss.test.remoting").setLevel(Level.INFO);
+ String pattern = "[%d{ABSOLUTE}] [%t] %5p (%F:%L) - %m%n";
+ PatternLayout layout = new PatternLayout(pattern);
+ ConsoleAppender consoleAppender = new ConsoleAppender(layout);
+ Logger.getRootLogger().addAppender(consoleAppender);
+ }
+ }
+
+
+ public void tearDown()
+ {
+ }
+
+
+ public void testCallbackStoreProxy() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer();
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ // Test connections.
+ assertEquals("abc", client.invoke("abc"));
+ log.info("connection is good");
+
+ // Setup pull callbacks.
+ TestCallbackHandler callbackHandler = new TestCallbackHandler();
+ client.addListener(callbackHandler);
+
+ if (!done)
+ {
+ synchronized (CallbackStoreProxyTestCase.class)
+ {
+ long start = System.currentTimeMillis();
+ while (true)
+ {
+ try
+ {
+ log.info("testCallbackStoreProxy() waiting for notification");
+ CallbackStoreProxyTestCase.class.wait(60000 - (System.currentTimeMillis() - start));
+ log.info("testCallbackStoreProxy() received notification");
+ break;
+ }
+ catch (InterruptedException e)
+ {
+ log.info("interrupted", e);
+ }
+ }
+ }
+ }
+
+ // Verify TestCallbackStore got one callback.
+// assertEquals(1, client.getCallbacks(callbackHandler).size());
+ int count = ((Integer)server.invoke(callbackStoreObjectName, "size", new Object[]{}, new String[]{})).intValue();
+ assertEquals(1, count);
+
+ client.removeListener(callbackHandler);
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ protected String getTransport()
+ {
+ return "socket";
+ }
+
+
+ protected void addExtraClientConfig(Map config) {}
+ protected void addExtraServerConfig(Map config) {}
+
+
+ protected void setupServer() throws Exception
+ {
+ host = InetAddress.getLocalHost().getHostAddress();
+ port = PortUtil.findFreePort(host);
+ locatorURI = getTransport() + "://" + host + ":" + port;
+ serverLocator = new InvokerLocator(locatorURI);
+ log.info("Starting remoting server with locator uri of: " + locatorURI);
+ HashMap config = new HashMap();
+ config.put(InvokerLocator.FORCE_REMOTE, "true");
+
+ // Create CallbackStore.
+ server = MBeanServerFactory.createMBeanServer();
+ TestCallbackStore callbackStore = new TestCallbackStore();
+ String objectNameString = "test:type=Callbackstore";
+ callbackStoreObjectName = new ObjectName(objectNameString);
+ server.registerMBean(callbackStore, callbackStoreObjectName);
+ config.put(ServerInvokerCallbackHandler.CALLBACK_STORE_KEY, objectNameString);
+
+ addExtraServerConfig(config);
+ connector = new Connector(serverLocator, config);
+ server.registerMBean(connector, new ObjectName("test:type=Connector"));
+
+ connector.create();
+ invocationHandler = new TestInvocationHandler();
+ connector.addInvocationHandler("test", invocationHandler);
+ connector.start();
+ }
+
+
+ protected void shutdownServer() throws Exception
+ {
+ if (connector != null)
+ connector.stop();
+ }
+
+
+ static class TestInvocationHandler implements ServerInvocationHandler
+ {
+ public void addListener(InvokerCallbackHandler callbackHandler)
+ {
+ TestCallbackThread callbackThread = new TestCallbackThread(callbackHandler);
+ callbackThread.start();
+
+ synchronized (TestCallbackStore.class)
+ {
+ long start = System.currentTimeMillis();
+ while (true)
+ {
+ try
+ {
+ TestCallbackStore.class.wait(60000 - (System.currentTimeMillis() - start));
+ break;
+ }
+ catch (InterruptedException e)
+ {
+ log.info("interrupted", e);
+ }
+ }
+ }
+
+ callbackThread.shutdown();
+ log.info("addListener() received notification");
+ done = true;
+
+ synchronized (CallbackStoreProxyTestCase.class)
+ {
+ CallbackStoreProxyTestCase.class.notifyAll();
+ }
+ }
+
+ public Object invoke(final InvocationRequest invocation) throws Throwable
+ {
+ return invocation.getParameter();
+ }
+
+ public void removeListener(InvokerCallbackHandler callbackHandler) {}
+ public void setMBeanServer(MBeanServer server) {}
+ public void setInvoker(ServerInvoker invoker) {}
+ }
+
+
+ static class TestCallbackHandler implements InvokerCallbackHandler
+ {
+ public void handleCallback(Callback callback) throws HandleCallbackException
+ {
+ log.info("received callback");
+ }
+ }
+
+ static class TestCallbackThread extends Thread
+ {
+ private boolean running = true;
+ private InvokerCallbackHandler callbackHandler;
+ private Callback callback = new Callback(new byte[1000]);
+
+ public TestCallbackThread(InvokerCallbackHandler callbackHandler)
+ {
+ this.callbackHandler = callbackHandler;
+ }
+
+ public void shutdown()
+ {
+ running = false;
+ }
+
+ public void run()
+ {
+ while (running)
+ {
+ try
+ {
+ callbackHandler.handleCallback(callback);
+ }
+ catch (HandleCallbackException e)
+ {
+ log.error("Error", e);
+ return;
+ }
+ }
+ log.info("shutting down");
+ }
+ }
+}
\ No newline at end of file
Added: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/security/NetworkRegistryProxyTestCase.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/security/NetworkRegistryProxyTestCase.java (rev 0)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/security/NetworkRegistryProxyTestCase.java 2008-05-07 23:42:08 UTC (rev 4137)
@@ -0,0 +1,178 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.remoting.security;
+
+import java.io.ByteArrayInputStream;
+import java.net.InetAddress;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.management.MBeanServer;
+import javax.management.MBeanServerFactory;
+import javax.management.ObjectName;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import junit.framework.TestCase;
+
+import org.apache.log4j.ConsoleAppender;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.apache.log4j.PatternLayout;
+import org.jboss.logging.XLevel;
+import org.jboss.remoting.InvocationRequest;
+import org.jboss.remoting.InvokerLocator;
+import org.jboss.remoting.ServerInvocationHandler;
+import org.jboss.remoting.ServerInvoker;
+import org.jboss.remoting.callback.InvokerCallbackHandler;
+import org.jboss.remoting.detection.multicast.MulticastDetector;
+import org.jboss.remoting.transport.Connector;
+import org.jboss.remoting.transport.PortUtil;
+import org.w3c.dom.Document;
+
+
+/**
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright May 4, 2008
+ * </p>
+ */
+public class NetworkRegistryProxyTestCase extends TestCase
+{
+ private static Logger log = Logger.getLogger(NetworkRegistryProxyTestCase.class);
+
+ private static boolean firstTime = true;
+ protected String host;
+ protected int port;
+ protected String locatorURI;
+ protected InvokerLocator serverLocator;
+ protected Connector connector;
+ protected MBeanServer server;
+ protected int numAdded;
+ protected int numUpdated;
+
+
+ public void setUp() throws Exception
+ {
+ if (firstTime)
+ {
+ firstTime = false;
+ Logger.getLogger("org.jboss.remoting").setLevel(XLevel.INFO);
+ Logger.getLogger("org.jboss.test.remoting").setLevel(Level.INFO);
+ String pattern = "[%d{ABSOLUTE}] [%t] %5p (%F:%L) - %m%n";
+ PatternLayout layout = new PatternLayout(pattern);
+ ConsoleAppender consoleAppender = new ConsoleAppender(layout);
+ Logger.getRootLogger().addAppender(consoleAppender);
+ }
+ }
+
+
+ public void tearDown()
+ {
+ }
+
+
+ public void testCallbackStoreProxy() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer();
+
+ // Start registry.
+ MBeanServer server = MBeanServerFactory.createMBeanServer();
+ TestNetworkRegistry networkRegistry = new TestNetworkRegistry();
+ ObjectName name = new ObjectName("test:type=TestNetworkRegistry");
+ server.registerMBean(networkRegistry, name);
+
+ // Create detector and tell it to register local Connectors.
+ MulticastDetector detector = new MulticastDetector();
+ StringBuffer buf = new StringBuffer();
+ buf.append("<?xml version=\"1.0\"?>\n");
+ buf.append("<local/>");
+ ByteArrayInputStream bais = new ByteArrayInputStream(buf.toString().getBytes());
+ Document xml = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(bais);
+ detector.setConfiguration(xml.getDocumentElement());
+ server.registerMBean(detector, new ObjectName("test:type=MulticastDetector"));
+ detector.start();
+
+ // Verify that TestNetworkRegistry proxy gets used.
+ detector.forceDetection();
+ assertEquals(1, networkRegistry.counter);
+ int counter = ((Integer) server.getAttribute(name, "Counter")).intValue();
+ assertEquals(networkRegistry.counter, counter);
+
+ detector.stop();
+ server.unregisterMBean(name);
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ protected String getTransport()
+ {
+ return "socket";
+ }
+
+
+ protected void addExtraClientConfig(Map config) {}
+ protected void addExtraServerConfig(Map config) {}
+
+
+ protected void setupServer() throws Exception
+ {
+ host = InetAddress.getLocalHost().getHostAddress();
+ port = PortUtil.findFreePort(host);
+ locatorURI = getTransport() + "://" + host + ":" + port;
+ serverLocator = new InvokerLocator(locatorURI);
+ log.info("Starting remoting server with locator uri of: " + locatorURI);
+ HashMap config = new HashMap();
+ config.put(InvokerLocator.FORCE_REMOTE, "true");
+ addExtraServerConfig(config);
+ connector = new Connector(serverLocator, config);
+ connector.create();
+ connector.addInvocationHandler("test", new TestServerInvocationHandler());
+ connector.start();
+ }
+
+
+ protected void shutdownServer() throws Exception
+ {
+ if (connector != null)
+ connector.stop();
+ }
+
+
+ public static class TestServerInvocationHandler implements ServerInvocationHandler
+ {
+ public void addListener(InvokerCallbackHandler callbackHandler) {}
+
+ public Object invoke(final InvocationRequest invocation) throws Throwable
+ {
+ return invocation.getParameter();
+ }
+
+ public void removeListener(InvokerCallbackHandler callbackHandler) {}
+ public void setMBeanServer(MBeanServer server) {}
+ public void setInvoker(ServerInvoker invoker) {}
+ }
+}
\ No newline at end of file
Added: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/security/ServerInvokerHandlerProxyTestCase.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/security/ServerInvokerHandlerProxyTestCase.java (rev 0)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/security/ServerInvokerHandlerProxyTestCase.java 2008-05-07 23:42:08 UTC (rev 4137)
@@ -0,0 +1,160 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.remoting.security;
+
+import java.net.InetAddress;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.management.MBeanServer;
+import javax.management.MBeanServerFactory;
+import javax.management.ObjectName;
+
+import junit.framework.TestCase;
+
+import org.apache.log4j.ConsoleAppender;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.apache.log4j.PatternLayout;
+import org.jboss.logging.XLevel;
+import org.jboss.remoting.Client;
+import org.jboss.remoting.InvokerLocator;
+import org.jboss.remoting.transport.Connector;
+import org.jboss.remoting.transport.PortUtil;
+
+
+/**
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright May 4, 2008
+ * </p>
+ */
+public class ServerInvokerHandlerProxyTestCase extends TestCase
+{
+ private static Logger log = Logger.getLogger(ServerInvokerHandlerProxyTestCase.class);
+
+ private static boolean firstTime = true;
+ protected String host;
+ protected int port;
+ protected String locatorURI;
+ protected InvokerLocator serverLocator;
+ protected Connector connector;
+ protected TestServerInvocationHandler handler;
+ protected MBeanServer server;
+ protected ObjectName handlerObjectName;
+
+
+ public void setUp() throws Exception
+ {
+ if (firstTime)
+ {
+ firstTime = false;
+ Logger.getLogger("org.jboss.remoting").setLevel(XLevel.INFO);
+ Logger.getLogger("org.jboss.test.remoting").setLevel(Level.INFO);
+ String pattern = "[%d{ABSOLUTE}] [%t] %5p (%F:%L) - %m%n";
+ PatternLayout layout = new PatternLayout(pattern);
+ ConsoleAppender consoleAppender = new ConsoleAppender(layout);
+ Logger.getRootLogger().addAppender(consoleAppender);
+ }
+ }
+
+
+ public void tearDown()
+ {
+ }
+
+
+ public void testCallbackStoreProxy() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer();
+ log.info("ServerInvocationHandler: " + handler);
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ // Verify handler proxy gets used.
+ assertEquals("abc", client.invoke("abc"));
+ log.info("connection is good");
+ assertEquals(1, handler.counter);
+ int counter = ((Integer) server.getAttribute(handlerObjectName, "Counter")).intValue();
+ assertEquals(handler.counter, counter);
+
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ protected String getTransport()
+ {
+ return "socket";
+ }
+
+
+ protected void addExtraClientConfig(Map config) {}
+ protected void addExtraServerConfig(Map config) {}
+
+
+ protected void setupServer() throws Exception
+ {
+ host = InetAddress.getLocalHost().getHostAddress();
+ port = PortUtil.findFreePort(host);
+ locatorURI = getTransport() + "://" + host + ":" + port;
+ serverLocator = new InvokerLocator(locatorURI);
+ log.info("Starting remoting server with locator uri of: " + locatorURI);
+ HashMap config = new HashMap();
+ config.put(InvokerLocator.FORCE_REMOTE, "true");
+ addExtraServerConfig(config);
+
+ // Create ServerInvocationHandler.
+ server = MBeanServerFactory.createMBeanServer();
+ handler = new TestServerInvocationHandler();
+ String objectNameString = "test:type=TestServerInvocationHandler";
+ handlerObjectName = new ObjectName(objectNameString);
+ server.registerMBean(handler, handlerObjectName);
+
+ // Create Connector and pass in handler ObjectName.
+ connector = new Connector(serverLocator, config);
+ server.registerMBean(connector, new ObjectName("test:type=Connector"));
+ connector.create();
+ connector.addInvocationHandler("test", handlerObjectName);
+ connector.start();
+ }
+
+
+ protected void shutdownServer() throws Exception
+ {
+ if (connector != null)
+ connector.stop();
+ }
+}
\ No newline at end of file
Added: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/security/ServerSocketFactoryProxyTestCase.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/security/ServerSocketFactoryProxyTestCase.java (rev 0)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/security/ServerSocketFactoryProxyTestCase.java 2008-05-07 23:42:08 UTC (rev 4137)
@@ -0,0 +1,199 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.remoting.security;
+
+import java.net.InetAddress;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.management.MBeanServer;
+import javax.management.MBeanServerFactory;
+import javax.management.ObjectName;
+
+import junit.framework.TestCase;
+
+import org.apache.log4j.ConsoleAppender;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.apache.log4j.PatternLayout;
+import org.jboss.logging.XLevel;
+import org.jboss.remoting.Client;
+import org.jboss.remoting.InvocationRequest;
+import org.jboss.remoting.InvokerLocator;
+import org.jboss.remoting.ServerInvocationHandler;
+import org.jboss.remoting.ServerInvoker;
+import org.jboss.remoting.callback.InvokerCallbackHandler;
+import org.jboss.remoting.security.SSLSocketBuilder;
+import org.jboss.remoting.transport.Connector;
+import org.jboss.remoting.transport.PortUtil;
+import org.jboss.remoting.transport.http.ssl.HTTPSClientInvoker;
+
+
+/**
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright May 4, 2008
+ * </p>
+ */
+public class ServerSocketFactoryProxyTestCase extends TestCase
+{
+ private static Logger log = Logger.getLogger(ServerSocketFactoryProxyTestCase.class);
+
+ private static boolean firstTime = true;
+ protected String host;
+ protected int port;
+ protected String locatorURI;
+ protected InvokerLocator serverLocator;
+ protected Connector connector;
+ protected MBeanServer server;
+ protected ObjectName factoryObjectName;
+ protected TestServerSocketFactory ssf;
+
+
+ public void setUp() throws Exception
+ {
+ if (firstTime)
+ {
+ firstTime = false;
+ Logger.getLogger("org.jboss.remoting").setLevel(XLevel.INFO);
+ Logger.getLogger("org.jboss.test.remoting").setLevel(Level.INFO);
+ String pattern = "[%d{ABSOLUTE}] [%t] %5p (%F:%L) - %m%n";
+ PatternLayout layout = new PatternLayout(pattern);
+ ConsoleAppender consoleAppender = new ConsoleAppender(layout);
+ Logger.getRootLogger().addAppender(consoleAppender);
+ }
+ }
+
+
+ public void tearDown()
+ {
+ }
+
+
+ public void testCallbackStoreProxy() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer();
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put(SSLSocketBuilder.REMOTING_TRUST_STORE_TYPE, "JKS");
+ String trustStoreFilePath = this.getClass().getResource("truststore").getFile();
+ clientConfig.put(SSLSocketBuilder.REMOTING_TRUST_STORE_FILE_PATH, trustStoreFilePath);
+ clientConfig.put(SSLSocketBuilder.REMOTING_TRUST_STORE_PASSWORD, "unit-tests-client");
+ clientConfig.put(HTTPSClientInvoker.IGNORE_HTTPS_HOST, "true");
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ // Test connection.
+ assertEquals("abc", client.invoke("abc"));
+ log.info("connection is good");
+
+ // Verify handler proxy gets used.
+ log.info("ssf counter: " + ssf.counter);
+ assertTrue(ssf.counter > 0);
+ int counter = ((Integer) server.getAttribute(factoryObjectName, "Counter")).intValue();
+ assertEquals(ssf.counter, counter);
+
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ protected String getTransport()
+ {
+ return "https";
+ }
+
+
+ protected void addExtraClientConfig(Map config) {}
+ protected void addExtraServerConfig(Map config) {}
+
+
+ protected void setupServer() throws Exception
+ {
+ // Set up SSLServerSocketFactory MBean.
+ HashMap sslConfig = new HashMap();
+ sslConfig.put(SSLSocketBuilder.REMOTING_KEY_STORE_TYPE, "JKS");
+ String keyStoreFilePath = getClass().getResource("keystore").getFile();
+ sslConfig.put(SSLSocketBuilder.REMOTING_KEY_STORE_FILE_PATH, keyStoreFilePath);
+ sslConfig.put(SSLSocketBuilder.REMOTING_KEY_STORE_PASSWORD, "unit-tests-server");
+ sslConfig.put(SSLSocketBuilder.REMOTING_SSL_PROTOCOL, "SSL");
+ SSLSocketBuilder builder = new SSLSocketBuilder(sslConfig);
+ builder.setUseSSLServerSocketFactory(false);
+ ssf = new TestServerSocketFactory();
+ ssf.setSSLSocketBuilder(builder);
+ ssf.start();
+ server = MBeanServerFactory.createMBeanServer();
+ String objectNameString = "test:type=SSLServerSocketFactoryService";
+ factoryObjectName = new ObjectName(objectNameString);
+ server.registerMBean(ssf, factoryObjectName);
+
+ // Create Connector.
+ host = InetAddress.getLocalHost().getHostAddress();
+ port = PortUtil.findFreePort(host);
+ locatorURI = getTransport() + "://" + host + ":" + port;
+ serverLocator = new InvokerLocator(locatorURI);
+ log.info("Starting remoting server with locator uri of: " + locatorURI);
+ HashMap config = new HashMap();
+ config.put(InvokerLocator.FORCE_REMOTE, "true");
+ config.put(ServerInvoker.SERVER_SOCKET_FACTORY, objectNameString);
+ addExtraServerConfig(config);
+ connector = new Connector(serverLocator, config);
+ server.registerMBean(connector, new ObjectName("test:type=Connector"));
+ connector.create();
+ TestServerInvocationHandler invocationHandler = new TestServerInvocationHandler();
+ connector.addInvocationHandler("test", invocationHandler);
+ connector.start();
+ }
+
+
+ protected void shutdownServer() throws Exception
+ {
+ if (connector != null)
+ connector.stop();
+ }
+
+
+ public static class TestServerInvocationHandler implements ServerInvocationHandler
+ {
+ public void addListener(InvokerCallbackHandler callbackHandler) {}
+
+ public Object invoke(final InvocationRequest invocation) throws Throwable
+ {
+ return invocation.getParameter();
+ }
+
+ public void removeListener(InvokerCallbackHandler callbackHandler) {}
+ public void setMBeanServer(MBeanServer server) {}
+ public void setInvoker(ServerInvoker invoker) {}
+ }
+}
\ No newline at end of file
Added: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/security/TestCallbackErrorHandler.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/security/TestCallbackErrorHandler.java (rev 0)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/security/TestCallbackErrorHandler.java 2008-05-07 23:42:08 UTC (rev 4137)
@@ -0,0 +1,60 @@
+
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.remoting.security;
+
+import java.util.Map;
+
+import org.apache.log4j.Logger;
+import org.jboss.remoting.ServerInvoker;
+import org.jboss.remoting.callback.ServerInvokerCallbackHandler;
+
+/**
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright May 5, 2008
+ * </p>
+ */
+public class TestCallbackErrorHandler implements TestCallbackErrorHandlerMBean
+{
+ private static Logger log = Logger.getLogger(TestCallbackErrorHandler.class);
+
+ int counter = 0;
+
+ public void handleError(Throwable ex) throws Throwable
+ {
+ counter++;
+ log.info("handling exception: " + ex.getMessage());
+ throw ex;
+ }
+
+ public void setCallbackHandler(ServerInvokerCallbackHandler serverInvokerCallbackHandler) {}
+ public void setConfig(Map errorHandlerConfig) {}
+ public void setServerInvoker(ServerInvoker owner) {}
+
+ public int getCounter()
+ {
+ return counter;
+ }
+}
+
Added: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/security/TestCallbackErrorHandlerMBean.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/security/TestCallbackErrorHandlerMBean.java (rev 0)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/security/TestCallbackErrorHandlerMBean.java 2008-05-07 23:42:08 UTC (rev 4137)
@@ -0,0 +1,38 @@
+
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.remoting.security;
+
+import org.jboss.remoting.callback.CallbackErrorHandler;
+
+/**
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright May 5, 2008
+ * </p>
+ */
+public interface TestCallbackErrorHandlerMBean extends CallbackErrorHandler
+{
+ public int getCounter();
+}
+
Added: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/security/TestCallbackStore.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/security/TestCallbackStore.java (rev 0)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/security/TestCallbackStore.java 2008-05-07 23:42:08 UTC (rev 4137)
@@ -0,0 +1,75 @@
+
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.remoting.security;
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.util.Map;
+
+import org.apache.log4j.Logger;
+
+public class TestCallbackStore implements TestCallbackStoreMBean
+{
+ private static Logger log = Logger.getLogger(TestCallbackStore.class);
+ private static byte[] memHolder;
+
+ static
+ {
+ long max = Runtime.getRuntime().maxMemory();
+ log.info("max mem: " + max);
+ int memSize = (int) (max * 0.9);
+ memHolder = new byte[memSize];
+ log.info("memHolder.length: " + memHolder.length);
+ }
+
+ private int size;
+
+ public String getStoreFilePath() {return null;}
+ public String getStoreFileSuffix() {return null;}
+ public void setStoreFilePath(String filePath) {}
+ public void setStoreFileSuffix(String fileSuffix) {}
+ public void add(Serializable object) throws IOException
+ {
+ if (size > 0)
+ return;
+
+ size++;
+ log.info("TestCallbackStore received callback");
+
+ synchronized (TestCallbackStore.class)
+ {
+ TestCallbackStore.class.notifyAll();
+ }
+ }
+ public void create() throws Exception {log.info("create()");}
+ public void destroy() {log.info("destroy()");}
+ public Object getNext() throws IOException {log.info("getNext()"); return null;}
+ public boolean getPurgeOnShutdown() {log.info("getPurgeOnShutdown()"); return false;}
+ public void purgeFiles() {log.info("purgeFiles()");}
+ public void setConfig(Map config) {log.info("setConfig()");}
+ public void setPurgeOnShutdown(boolean purgeOnShutdown) {log.info("setPurgeOnShutdown()");}
+ public int size() {log.info("size()"); return size;}
+ public void start() throws Exception {log.info("start()");}
+ public void stop() {log.info("stop()");}
+}
+
Added: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/security/TestCallbackStoreMBean.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/security/TestCallbackStoreMBean.java (rev 0)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/security/TestCallbackStoreMBean.java 2008-05-07 23:42:08 UTC (rev 4137)
@@ -0,0 +1,31 @@
+
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.remoting.security;
+
+import org.jboss.remoting.callback.CallbackStoreMBean;
+
+public interface TestCallbackStoreMBean extends CallbackStoreMBean
+{
+
+}
+
Added: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/security/TestNetworkRegistry.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/security/TestNetworkRegistry.java (rev 0)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/security/TestNetworkRegistry.java 2008-05-07 23:42:08 UTC (rev 4137)
@@ -0,0 +1,54 @@
+
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.remoting.security;
+
+import org.apache.log4j.Logger;
+import org.jboss.remoting.detection.ServerInvokerMetadata;
+import org.jboss.remoting.ident.Identity;
+import org.jboss.remoting.network.NetworkRegistry;
+
+/**
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright May 6, 2008
+ * </p>
+ */
+public class TestNetworkRegistry extends NetworkRegistry implements TestNetworkRegistryMBean
+{
+ static Logger log = Logger.getLogger(TestNetworkRegistry.class);
+
+ int counter;
+
+ public void addServer(Identity identity, ServerInvokerMetadata[] invokers)
+ {
+ counter++;
+ log.info("addServer() called");
+ }
+
+ public int getCounter()
+ {
+ return counter;
+ }
+}
+
Added: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/security/TestNetworkRegistryMBean.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/security/TestNetworkRegistryMBean.java (rev 0)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/security/TestNetworkRegistryMBean.java 2008-05-07 23:42:08 UTC (rev 4137)
@@ -0,0 +1,38 @@
+
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.remoting.security;
+
+import org.jboss.remoting.network.NetworkRegistryMBean;
+
+/**
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright May 6, 2008
+ * </p>
+ */
+public interface TestNetworkRegistryMBean extends NetworkRegistryMBean
+{
+ public int getCounter();
+}
+
Added: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/security/TestServerInvocationHandler.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/security/TestServerInvocationHandler.java (rev 0)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/security/TestServerInvocationHandler.java 2008-05-07 23:42:08 UTC (rev 4137)
@@ -0,0 +1,55 @@
+
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.remoting.security;
+
+import javax.management.MBeanServer;
+
+import org.apache.log4j.Logger;
+import org.jboss.remoting.InvocationRequest;
+import org.jboss.remoting.ServerInvoker;
+import org.jboss.remoting.callback.InvokerCallbackHandler;
+
+public class TestServerInvocationHandler implements TestServerInvocationHandlerMBean
+{
+ static Logger log = Logger.getLogger(TestServerInvocationHandler.class);
+ int counter;
+
+ public void addListener(InvokerCallbackHandler callbackHandler) {}
+
+ public Object invoke(final InvocationRequest invocation) throws Throwable
+ {
+ counter++;
+ log.info("ServerInvocationHandler processing invocation");
+ return invocation.getParameter();
+ }
+
+ public void removeListener(InvokerCallbackHandler callbackHandler) {}
+ public void setMBeanServer(MBeanServer server) {}
+ public void setInvoker(ServerInvoker invoker) {}
+
+ public int getCounter()
+ {
+ return counter;
+ }
+}
+
Added: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/security/TestServerInvocationHandlerMBean.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/security/TestServerInvocationHandlerMBean.java (rev 0)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/security/TestServerInvocationHandlerMBean.java 2008-05-07 23:42:08 UTC (rev 4137)
@@ -0,0 +1,38 @@
+
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.remoting.security;
+
+import org.jboss.remoting.ServerInvocationHandler;
+
+/**
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright May 5, 2008
+ * </p>
+ */
+public interface TestServerInvocationHandlerMBean extends ServerInvocationHandler
+{
+ public int getCounter();
+}
+
Added: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/security/TestServerSocketFactory.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/security/TestServerSocketFactory.java (rev 0)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/security/TestServerSocketFactory.java 2008-05-07 23:42:08 UTC (rev 4137)
@@ -0,0 +1,88 @@
+
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.remoting.security;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.ServerSocket;
+
+import org.apache.log4j.Logger;
+import org.jboss.remoting.security.SSLServerSocketFactoryService;
+
+
+/**
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright May 7, 2008
+ * </p>
+ */
+public class TestServerSocketFactory
+ extends SSLServerSocketFactoryService
+ implements TestServerSocketFactoryMBean
+{
+ private static Logger log = Logger.getLogger(TestServerSocketFactory.class);
+
+ int counter;
+
+ public ServerSocket createServerSocket()
+ throws IOException
+ {
+ counter++;
+ log.info("createServerSocket()");
+ return super.createServerSocket();
+ }
+
+ public ServerSocket createServerSocket( int port )
+ throws IOException
+ {
+ counter++;
+ log.info("createServerSocket(port)");
+ return super.createServerSocket(port);
+ }
+
+ public ServerSocket createServerSocket( int port,
+ int backlog )
+ throws IOException
+ {
+ counter++;
+ log.info("createServerSocket(port, backlog)");
+ return super.createServerSocket(port, backlog);
+ }
+
+ public ServerSocket createServerSocket( int port,
+ int backlog,
+ InetAddress ifAddress )
+ throws IOException
+ {
+ counter++;
+ log.info("createServerSocket(port, backlog, ifAddress)");
+ return super.createServerSocket(port, backlog, ifAddress);
+ }
+
+ public int getCounter()
+ {
+ return counter;
+ }
+}
+
Added: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/security/TestServerSocketFactoryMBean.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/security/TestServerSocketFactoryMBean.java (rev 0)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/security/TestServerSocketFactoryMBean.java 2008-05-07 23:42:08 UTC (rev 4137)
@@ -0,0 +1,38 @@
+
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.remoting.security;
+
+import org.jboss.remoting.security.ServerSocketFactoryMBean;
+
+/**
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright May 7, 2008
+ * </p>
+ */
+public interface TestServerSocketFactoryMBean extends ServerSocketFactoryMBean
+{
+ public int getCounter();
+}
+
Added: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/security/keystore
===================================================================
(Binary files differ)
Property changes on: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/security/keystore
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/security/truststore
===================================================================
(Binary files differ)
Property changes on: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/security/truststore
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
16 years, 8 months
JBoss Remoting SVN: r4136 - remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/bisocket.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2008-05-07 19:41:01 -0400 (Wed, 07 May 2008)
New Revision: 4136
Modified:
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/bisocket/BisocketTestCase.java
Log:
JBREM-930: Cosmetic change.
Modified: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/bisocket/BisocketTestCase.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/bisocket/BisocketTestCase.java 2008-05-07 23:38:09 UTC (rev 4135)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/bisocket/BisocketTestCase.java 2008-05-07 23:41:01 UTC (rev 4136)
@@ -1967,7 +1967,7 @@
{
try
{
- internalSetUp(port);
+ internalSetUp(port);
break;
}
catch (Exception e)
16 years, 8 months
JBoss Remoting SVN: r4135 - 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-05-07 19:38:09 -0400 (Wed, 07 May 2008)
New Revision: 4135
Added:
remoting2/branches/2.x/src/main/org/jboss/remoting/util/SecurityUtility.java
Removed:
remoting2/branches/2.x/src/main/org/jboss/remoting/util/SecurityUtility.java
Log:
JBREM-934: Added methods to support JBossSerialization i/o.
Deleted: 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-05-07 23:36:49 UTC (rev 4134)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/util/SecurityUtility.java 2008-05-07 23:38:09 UTC (rev 4135)
@@ -1,1118 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2005, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.remoting.util;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.lang.reflect.Method;
-import java.net.InetAddress;
-import java.net.InetSocketAddress;
-import java.net.ServerSocket;
-import java.net.Socket;
-import java.net.SocketAddress;
-import java.net.UnknownHostException;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-import java.security.PrivilegedActionException;
-import java.security.PrivilegedExceptionAction;
-
-import javax.management.InstanceNotFoundException;
-import javax.management.MBeanServer;
-import javax.management.MBeanServerFactory;
-import javax.management.ObjectName;
-import javax.net.ServerSocketFactory;
-import javax.net.SocketFactory;
-
-import org.jboss.remoting.Remoting;
-import org.jboss.remoting.security.ServerSocketFactoryMBean;
-
-/**
- * SecurityUtility provides a central point for making security sensitive calls.
- *
- * It is divided into five sections:
- *
- * 1. calls requiring FilePermissions
- * 2. calls requiring MBeanPermissions
- * 3. calls requiring PropertyPermissions
- * 4. calls requiring RuntimePermissions
- * 5. calls requiring SocketPermissions
- *
- * When the SecurityUtility class is loaded, it checks for two conditions:
- *
- * 1. there is no security manager
- * 2. the system property Remoting.SKIP_ACCESS_CONTROL ("skipAccessControl") is
- * set to true.
- *
- * If either condition is true, then every method in SecurityUtility will
- * bypass its call to AccessController.doPrivileged().
- *
- * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
- * @version $Revision: 1.1 $
- * <p>
- * Copyright Mar 31, 2008
- * </p>
- */
-public class SecurityUtility
-{
- static boolean skipAccessControl;
-
- static
- {
- try
- {
- skipAccessControl = ((Boolean)AccessController.doPrivileged( new PrivilegedExceptionAction()
- {
- public Object run() throws Exception
- {
- boolean b1 = System.getSecurityManager() == null;
- boolean b2 = Boolean.getBoolean(Remoting.SKIP_ACCESS_CONTROL);
- return new Boolean(b1 || b2);
- }
- })).booleanValue();
- }
- catch (PrivilegedActionException e)
- {
- e.getCause().printStackTrace();
- }
-// System.out.println("skipAccessControl: " + skipAccessControl);
- }
-
-
- static public boolean skipAccessControl()
- {
- return skipAccessControl;
- }
-
- ///////////////////////////////////////////////////////////////////////////////////////
- // FilePermission methods
- ///////////////////////////////////////////////////////////////////////////////////////
-
- static public boolean fileExists(final File file)
- {
- if (skipAccessControl)
- {
- return file.exists();
- }
-
- return ((Boolean)AccessController.doPrivileged( new PrivilegedAction()
- {
- public Object run()
- {
- return new Boolean(file.exists());
- }
- })).booleanValue();
- }
-
-
- static public boolean mkdirs(final File dir)
- {
- if (skipAccessControl)
- {
- return dir.mkdirs();
- }
-
- return ((Boolean) AccessController.doPrivileged( new PrivilegedAction()
- {
- public Object run()
- {
- return new Boolean(dir.mkdirs());
- }
- })).booleanValue();
- }
-
-
- static public FileInputStream getFileInputStream(final File file) throws FileNotFoundException
- {
- if (skipAccessControl)
- {
- return new FileInputStream(file);
- }
-
- try
- {
- return (FileInputStream)AccessController.doPrivileged( new PrivilegedExceptionAction()
- {
- public Object run() throws FileNotFoundException
- {
- return new FileInputStream(file);
- }
- });
- }
- catch (PrivilegedActionException e)
- {
- throw (FileNotFoundException) e.getCause();
- }
- }
-
-
- static public FileInputStream getFileInputStream(final String path) throws FileNotFoundException
- {
- if (skipAccessControl)
- {
- return new FileInputStream(path);
- }
-
- try
- {
- return (FileInputStream)AccessController.doPrivileged( new PrivilegedExceptionAction()
- {
- public Object run() throws FileNotFoundException
- {
- return new FileInputStream(path);
- }
- });
- }
- catch (PrivilegedActionException e)
- {
- throw (FileNotFoundException) e.getCause();
- }
- }
-
-
- static public FileOutputStream getFileOutputStream(final File file)
- throws FileNotFoundException
- {
- if (skipAccessControl)
- {
- return new FileOutputStream(file);
- }
-
- try
- {
- return (FileOutputStream)AccessController.doPrivileged( new PrivilegedExceptionAction()
- {
- public Object run() throws FileNotFoundException
- {
- return new FileOutputStream(file);
- }
- });
- }
- catch (PrivilegedActionException e)
- {
- throw (FileNotFoundException) e.getCause();
- }
- }
-
-
- static public FileOutputStream getFileOutputStream(final File file, final boolean append)
- throws FileNotFoundException
- {
- if (skipAccessControl)
- {
- return new FileOutputStream(file, append);
- }
-
- try
- {
- return (FileOutputStream)AccessController.doPrivileged( new PrivilegedExceptionAction()
- {
- public Object run() throws FileNotFoundException
- {
- return new FileOutputStream(file, append);
- }
- });
- }
- catch (PrivilegedActionException e)
- {
- throw (FileNotFoundException) e.getCause();
- }
- }
-
-
- static public boolean canRead(final File file)
- {
- if (skipAccessControl)
- {
- return file.canRead();
- }
-
- return ((Boolean)AccessController.doPrivileged( new PrivilegedAction()
- {
- public Object run()
- {
- return new Boolean(file.canRead());
- }
- })).booleanValue();
- }
-
-
- static public boolean createNewFile(final File file) throws IOException
- {
- if (skipAccessControl)
- {
- return file.createNewFile();
- }
-
- try
- {
- return ((Boolean)AccessController.doPrivileged( new PrivilegedExceptionAction()
- {
- public Object run() throws Exception
- {
- return new Boolean(file.createNewFile());
- }
- })).booleanValue();
- }
- catch (Exception e)
- {
- throw (IOException) e.getCause();
- }
- }
-
-
- ///////////////////////////////////////////////////////////////////////////////////////
- // MBeanPermission methods
- ///////////////////////////////////////////////////////////////////////////////////////
-
- static public void connect(final Socket socket, final InetSocketAddress address)
- throws IOException
- {
- if (skipAccessControl)
- {
- socket.connect(address);
- return;
- }
-
- try
- {
- AccessController.doPrivileged( new PrivilegedExceptionAction()
- {
- public Object run() throws Exception
- {
- socket.connect(address);
- return null;
- }
- });
- }
- catch (PrivilegedActionException e)
- {
- throw (IOException) e.getCause();
- }
- }
-
-
- static public void connect(final Socket socket, final InetSocketAddress address, final int timeout)
- throws IOException
- {
- if (skipAccessControl)
- {
- socket.connect(address, timeout);
- return;
- }
-
- try
- {
- AccessController.doPrivileged( new PrivilegedExceptionAction()
- {
- public Object run() throws Exception
- {
- socket.connect(address, timeout);
- return null;
- }
- });
- }
- catch (PrivilegedActionException e)
- {
- throw (IOException) e.getCause();
- }
- }
-
-
- static public MBeanServer createMBeanServer() throws Exception
- {
- if (skipAccessControl)
- {
- return MBeanServerFactory.createMBeanServer();
- }
-
- try
- {
- return (MBeanServer) AccessController.doPrivileged( new PrivilegedExceptionAction()
- {
- public Object run() throws Exception
- {
- return MBeanServerFactory.createMBeanServer();
- }
- });
- }
- catch (PrivilegedActionException e)
- {
- throw (Exception) e.getCause();
- }
- }
-
-
- static public boolean isInstanceOf(final MBeanServer server, final ObjectName objectName, final String className)
- throws InstanceNotFoundException
- {
- if (skipAccessControl)
- {
- return server.isInstanceOf(objectName, className);
- }
-
- try
- {
- return ((Boolean)AccessController.doPrivileged( new PrivilegedExceptionAction()
- {
- public Object run() throws Exception
- {
- return new Boolean(server.isInstanceOf(objectName, className));
- }
- })).booleanValue();
- }
- catch (PrivilegedActionException e)
- {
- throw (InstanceNotFoundException) e.getCause();
- }
- }
-
-
- static public Object getMBeanAttribute(final MBeanServer server, final ObjectName objectName, final String attribute)
- throws Exception
- {
- if (skipAccessControl)
- {
- return server.getAttribute(objectName, attribute);
- }
-
- try
- {
- return AccessController.doPrivileged( new PrivilegedExceptionAction()
- {
- public Object run() throws Exception
- {
- return server.getAttribute(objectName, attribute);
- }
- });
- }
- catch (PrivilegedActionException e)
- {
- throw (Exception) e.getCause();
- }
- }
-
-
- static public void registerMBean(final MBeanServer server, final Object o, final ObjectName name)
- throws Exception
- {
- if (skipAccessControl)
- {
- server.registerMBean(o, name);
- return;
- }
-
- try
- {
- AccessController.doPrivileged( new PrivilegedExceptionAction()
- {
- public Object run() throws Exception
- {
- server.registerMBean(o, name);
- return null;
- }
- });
- }
- catch (PrivilegedActionException e)
- {
- throw (Exception) e.getCause();
- }
- }
-
-
- static public void unregisterMBean(final MBeanServer server, final ObjectName name)
- throws Exception
- {
- if (skipAccessControl)
- {
- server.unregisterMBean(name);
- return;
- }
-
- try
- {
- AccessController.doPrivileged( new PrivilegedExceptionAction()
- {
- public Object run() throws Exception
- {
- server.unregisterMBean(name);
- return null;
- }
- });
- }
- catch (PrivilegedActionException e)
- {
- throw (Exception) e.getCause();
- }
- }
-
-
- ///////////////////////////////////////////////////////////////////////////////////////
- // PropertyPermission methods
- ///////////////////////////////////////////////////////////////////////////////////////
-
- static public String getSystemProperty(final String name, final String defaultValue)
- {
- if (skipAccessControl)
- return System.getProperty(name, defaultValue);
-
- String value = null;
- try
- {
- value = (String)AccessController.doPrivileged( new PrivilegedExceptionAction()
- {
- public Object run() throws Exception
- {
- return System.getProperty(name, defaultValue);
- }
- });
- }
- catch (PrivilegedActionException e)
- {
- throw (RuntimeException) e.getCause();
- }
-
- return value;
- }
-
-
- static public String getSystemProperty(final String name)
- {
- if (skipAccessControl)
- return System.getProperty(name);
-
- String value = null;
- try
- {
- value = (String)AccessController.doPrivileged( new PrivilegedExceptionAction()
- {
- public Object run() throws Exception
- {
- return System.getProperty(name);
- }
- });
- }
- catch (PrivilegedActionException e)
- {
- throw (RuntimeException) e.getCause();
- }
-
- return value;
- }
-
-
- static public void setSystemProperty(final String name, final String value)
- {
- if (skipAccessControl)
- {
- System.setProperty(name, value);
- return;
- }
-
- try
- {
- AccessController.doPrivileged( new PrivilegedExceptionAction()
- {
- public Object run() throws Exception
- {
- return System.setProperty(name, value);
- }
- });
- }
- catch (PrivilegedActionException e)
- {
- throw (RuntimeException) e.getCause();
- }
- }
-
-
- ///////////////////////////////////////////////////////////////////////////////////////
- // RuntimePermission methods
- ///////////////////////////////////////////////////////////////////////////////////////
-
- static public Object forName(final String className) throws ClassNotFoundException
- {
- if (skipAccessControl)
- {
- return Class.forName(className);
- }
-
- try
- {
- return AccessController.doPrivileged( new PrivilegedExceptionAction()
- {
- public Object run() throws Exception
- {
- return Class.forName(className);
- }
- });
- }
- catch (PrivilegedActionException e)
- {
- throw (ClassNotFoundException) e.getCause();
- }
- }
-
-
- static public ClassLoader getClassLoader(final Class c)
- {
- if (skipAccessControl)
- {
- return c.getClassLoader();
- }
-
- return (ClassLoader)AccessController.doPrivileged( new PrivilegedAction()
- {
- public Object run()
- {
- return c.getClassLoader();
- }
- });
- }
-
-
- static public ClassLoader getSystemClassLoader()
- {
- if (skipAccessControl)
- {
- return ClassLoader.getSystemClassLoader();
- }
-
- return (ClassLoader)AccessController.doPrivileged( new PrivilegedAction()
- {
- public Object run()
- {
- return ClassLoader.getSystemClassLoader();
- }
- });
- }
-
-
- static public Method getMethod(final Class c, final String name, final Class[] parameterTypes)
- throws NoSuchMethodException
- {
- if (skipAccessControl)
- {
- return c.getMethod(name, parameterTypes);
- }
-
- try
- {
- return (Method) AccessController.doPrivileged( new PrivilegedExceptionAction()
- {
- public Object run() throws NoSuchMethodException
- {
- return c.getMethod(name, parameterTypes);
- }
- });
- }
- catch (PrivilegedActionException e)
- {
- throw (NoSuchMethodException) e.getCause();
- }
- }
-
-
- static public Method getDeclaredMethod(final Class c, final String name, final Class[] parameterTypes)
- throws NoSuchMethodException
- {
- if (skipAccessControl)
- {
- return c.getDeclaredMethod(name, parameterTypes);
- }
-
- try
- {
- return (Method) AccessController.doPrivileged( new PrivilegedExceptionAction()
- {
- public Object run() throws NoSuchMethodException
- {
- return c.getDeclaredMethod(name, parameterTypes);
- }
- });
- }
- catch (PrivilegedActionException e)
- {
- throw (NoSuchMethodException) e.getCause();
- }
- }
-
-
- ///////////////////////////////////////////////////////////////////////////////////////
- // SocketPermission methods
- ///////////////////////////////////////////////////////////////////////////////////////
-
- static public Socket accept(final ServerSocket ss) throws IOException
- {
- if (skipAccessControl)
- {
- return ss.accept();
- }
-
- try
- {
- return (Socket)AccessController.doPrivileged( new PrivilegedExceptionAction()
- {
- public Object run() throws Exception
- {
- return ss.accept();
- }
- });
- }
- catch (PrivilegedActionException e)
- {
- throw (IOException) e.getCause();
- }
- }
-
-
- static public void bind(final ServerSocket ss, final SocketAddress address)
- throws IOException
- {
- if (skipAccessControl)
- {
- ss.bind(address);
- return;
- }
-
- try
- {
- AccessController.doPrivileged( new PrivilegedExceptionAction()
- {
- public Object run() throws Exception
- {
- ss.bind(address);
- return null;
- }
- });
- }
- catch (PrivilegedActionException e)
- {
- throw (IOException) e.getCause();
- }
- }
-
-
- static public void bind(final ServerSocket ss, final SocketAddress address,
- final int backlog) throws IOException
- {
- if (skipAccessControl)
- {
- ss.bind(address, backlog);
- return;
- }
-
- try
- {
- AccessController.doPrivileged( new PrivilegedExceptionAction()
- {
- public Object run() throws Exception
- {
- ss.bind(address, backlog);
- return null;
- }
- });
- }
- catch (PrivilegedActionException e)
- {
- throw (IOException) e.getCause();
- }
- }
-
-
- static public ServerSocket createServerSocket(final ServerSocketFactoryMBean ssf,
- final int port) throws IOException
- {
- if (skipAccessControl)
- {
- return ssf.createServerSocket(port);
- }
-
- try
- {
- return (ServerSocket)AccessController.doPrivileged( new PrivilegedExceptionAction()
- {
- public Object run() throws Exception
- {
- return ssf.createServerSocket(port);
- }
- });
- }
- catch (PrivilegedActionException e)
- {
- throw (IOException) e.getCause();
- }
- }
-
-
- static public ServerSocket createServerSocket(final ServerSocketFactoryMBean ssf,
- final int port, final int backlog)
- throws IOException
- {
- if (skipAccessControl)
- {
- return ssf.createServerSocket(port, backlog);
- }
-
- try
- {
- return (ServerSocket)AccessController.doPrivileged( new PrivilegedExceptionAction()
- {
- public Object run() throws Exception
- {
- return ssf.createServerSocket(port, backlog);
- }
- });
- }
- catch (PrivilegedActionException e)
- {
- throw (IOException) e.getCause();
- }
- }
-
-
- static public ServerSocket createServerSocket(final ServerSocketFactoryMBean ssf,
- final int port, final int backlog,
- final InetAddress inetAddress)
- throws IOException
- {
- if (skipAccessControl)
- {
- return ssf.createServerSocket(port, backlog, inetAddress);
- }
-
- try
- {
- return (ServerSocket)AccessController.doPrivileged( new PrivilegedExceptionAction()
- {
- public Object run() throws Exception
- {
- return ssf.createServerSocket(port, backlog, inetAddress);
- }
- });
- }
- catch (PrivilegedActionException e)
- {
- throw (IOException) e.getCause();
- }
- }
-
-
- static public ServerSocket createServerSocket(final ServerSocketFactory ssf,
- final int port) throws IOException
- {
- if (skipAccessControl)
- {
- return ssf.createServerSocket(port);
- }
-
- try
- {
- return (ServerSocket)AccessController.doPrivileged( new PrivilegedExceptionAction()
- {
- public Object run() throws Exception
- {
- return ssf.createServerSocket(port);
- }
- });
- }
- catch (PrivilegedActionException e)
- {
- throw (IOException) e.getCause();
- }
- }
-
-
- static public ServerSocket createServerSocket(final ServerSocketFactory ssf,
- final int port, final int backlog)
- throws IOException
- {
- if (skipAccessControl)
- {
- return ssf.createServerSocket(port, backlog);
- }
-
- try
- {
- return (ServerSocket)AccessController.doPrivileged( new PrivilegedExceptionAction()
- {
- public Object run() throws Exception
- {
- return ssf.createServerSocket(port, backlog);
- }
- });
- }
- catch (PrivilegedActionException e)
- {
- throw (IOException) e.getCause();
- }
- }
-
-
- static public ServerSocket createServerSocket(final ServerSocketFactory ssf,
- final int port, final int backlog,
- final InetAddress inetAddress)
- throws IOException
- {
- if (skipAccessControl)
- {
- return ssf.createServerSocket(port, backlog, inetAddress);
- }
-
- try
- {
- return (ServerSocket)AccessController.doPrivileged( new PrivilegedExceptionAction()
- {
- public Object run() throws Exception
- {
- return ssf.createServerSocket(port, backlog, inetAddress);
- }
- });
- }
- catch (PrivilegedActionException e)
- {
- throw (IOException) e.getCause();
- }
- }
-
-
- static public ServerSocket createServerSocket(final int port) throws IOException
- {
- if (skipAccessControl)
- {
- return new ServerSocket(port);
- }
-
- try
- {
- return (ServerSocket)AccessController.doPrivileged( new PrivilegedExceptionAction()
- {
- public Object run() throws Exception
- {
- return new ServerSocket(port);
- }
- });
- }
- catch (PrivilegedActionException e)
- {
- throw (IOException) e.getCause();
- }
- }
-
-
- static public ServerSocket createServerSocket(final int port, final int backlog)
- throws IOException
- {
- if (skipAccessControl)
- {
- return new ServerSocket(port, backlog);
- }
-
- try
- {
- return (ServerSocket)AccessController.doPrivileged( new PrivilegedExceptionAction()
- {
- public Object run() throws Exception
- {
- return new ServerSocket(port, backlog);
- }
- });
- }
- catch (PrivilegedActionException e)
- {
- throw (IOException) e.getCause();
- }
- }
-
-
- static public ServerSocket createServerSocket(final int port, final int backlog,
- final InetAddress inetAddress)
- throws IOException
- {
- if (skipAccessControl)
- {
- return new ServerSocket(port, backlog, inetAddress);
- }
-
- try
- {
- return (ServerSocket)AccessController.doPrivileged( new PrivilegedExceptionAction()
- {
- public Object run() throws Exception
- {
- return new ServerSocket(port, backlog, inetAddress);
- }
- });
- }
- catch (PrivilegedActionException e)
- {
- throw (IOException) e.getCause();
- }
- }
-
-
- static public Socket createSocket(final String host, final int port) throws IOException
- {
- if (skipAccessControl)
- {
- return new Socket(host, port);
- }
-
- try
- {
- return (Socket)AccessController.doPrivileged( new PrivilegedExceptionAction()
- {
- public Object run() throws Exception
- {
- return new Socket(host, port);
- }
- });
- }
- catch (PrivilegedActionException e)
- {
- throw (IOException) e.getCause();
- }
- }
-
-
- static public Socket createSocket(final SocketFactory sf, final String host, final int port)
- throws IOException
- {
- if (skipAccessControl)
- {
- return sf.createSocket(host, port);
- }
-
- try
- {
- return (Socket)AccessController.doPrivileged( new PrivilegedExceptionAction()
- {
- public Object run() throws Exception
- {
- return sf.createSocket(host, port);
- }
- });
- }
- catch (PrivilegedActionException e)
- {
- throw (IOException) e.getCause();
- }
- }
-
-
- static public InetAddress getLocalHost() throws UnknownHostException
- {
- if (skipAccessControl)
- {
- try
- {
- return InetAddress.getLocalHost();
- }
- catch (IOException e)
- {
- return InetAddress.getByName("127.0.0.1");
- }
- }
-
- try
- {
- return (InetAddress) AccessController.doPrivileged( new PrivilegedExceptionAction()
- {
- public Object run() throws IOException
- {
- try
- {
- return InetAddress.getLocalHost();
- }
- catch (IOException e)
- {
- return InetAddress.getByName("127.0.0.1");
- }
- }
- });
- }
- catch (PrivilegedActionException e)
- {
- throw (UnknownHostException) e.getCause();
- }
- }
-
-
- static public String getLocalHostName() throws UnknownHostException
- {
- if (skipAccessControl)
- {
- return getLocalHost().getHostName();
- }
-
- try
- {
- return (String) AccessController.doPrivileged( new PrivilegedExceptionAction()
- {
- public Object run() throws IOException
- {
- InetAddress address = null;
- try
- {
- address = InetAddress.getLocalHost();
- }
- catch (IOException e)
- {
- address = InetAddress.getByName("127.0.0.1");
- }
-
- return address.getHostName();
- }
- });
- }
- catch (PrivilegedActionException e)
- {
- throw (UnknownHostException) e.getCause();
- }
- }
-
-
- static public InetAddress getAddressByName(final String host) throws UnknownHostException
- {
- if (skipAccessControl)
- {
- return InetAddress.getByName(host);
- }
-
- try
- {
- return (InetAddress)AccessController.doPrivileged( new PrivilegedExceptionAction()
- {
- public Object run() throws IOException
- {
- return InetAddress.getByName(host);
- }
- });
- }
- catch (PrivilegedActionException e)
- {
- throw (UnknownHostException) e.getCause();
- }
- }
-}
\ No newline at end of file
Added: remoting2/branches/2.x/src/main/org/jboss/remoting/util/SecurityUtility.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/util/SecurityUtility.java (rev 0)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/util/SecurityUtility.java 2008-05-07 23:38:09 UTC (rev 4135)
@@ -0,0 +1,1181 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.remoting.util;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.lang.reflect.Method;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.net.SocketAddress;
+import java.net.UnknownHostException;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+
+import javax.management.InstanceNotFoundException;
+import javax.management.MBeanServer;
+import javax.management.MBeanServerFactory;
+import javax.management.ObjectName;
+import javax.net.ServerSocketFactory;
+import javax.net.SocketFactory;
+
+import org.jboss.remoting.Remoting;
+import org.jboss.remoting.security.ServerSocketFactoryMBean;
+import org.jboss.serial.io.JBossObjectInputStream;
+import org.jboss.serial.io.JBossObjectOutputStream;
+
+/**
+ * SecurityUtility provides a central point for making security sensitive calls.
+ *
+ * It is divided into five sections:
+ *
+ * 1. calls requiring FilePermissions
+ * 2. calls requiring MBeanPermissions
+ * 3. calls requiring PropertyPermissions
+ * 4. calls requiring RuntimePermissions
+ * 5. calls requiring SocketPermissions
+ *
+ * When the SecurityUtility class is loaded, it checks for two conditions:
+ *
+ * 1. there is no security manager
+ * 2. the system property Remoting.SKIP_ACCESS_CONTROL ("skipAccessControl") is
+ * set to true.
+ *
+ * If either condition is true, then every method in SecurityUtility will
+ * bypass its call to AccessController.doPrivileged().
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright Mar 31, 2008
+ * </p>
+ */
+public class SecurityUtility
+{
+ static boolean skipAccessControl;
+
+ static
+ {
+ try
+ {
+ skipAccessControl = ((Boolean)AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws Exception
+ {
+ boolean b1 = System.getSecurityManager() == null;
+ boolean b2 = Boolean.getBoolean(Remoting.SKIP_ACCESS_CONTROL);
+ System.out.println("security manager: " + System.getSecurityManager());
+ return new Boolean(b1 || b2);
+ }
+ })).booleanValue();
+ }
+ catch (PrivilegedActionException e)
+ {
+ e.getCause().printStackTrace();
+ }
+ }
+
+
+ static public boolean skipAccessControl()
+ {
+ return skipAccessControl;
+ }
+
+ ///////////////////////////////////////////////////////////////////////////////////////
+ // FilePermission methods
+ ///////////////////////////////////////////////////////////////////////////////////////
+
+ static public boolean fileExists(final File file)
+ {
+ if (skipAccessControl)
+ {
+ return file.exists();
+ }
+
+ return ((Boolean)AccessController.doPrivileged( new PrivilegedAction()
+ {
+ public Object run()
+ {
+ return new Boolean(file.exists());
+ }
+ })).booleanValue();
+ }
+
+
+ static public boolean mkdirs(final File dir)
+ {
+ if (skipAccessControl)
+ {
+ return dir.mkdirs();
+ }
+
+ return ((Boolean) AccessController.doPrivileged( new PrivilegedAction()
+ {
+ public Object run()
+ {
+ return new Boolean(dir.mkdirs());
+ }
+ })).booleanValue();
+ }
+
+
+ static public FileInputStream getFileInputStream(final File file) throws FileNotFoundException
+ {
+ if (skipAccessControl)
+ {
+ return new FileInputStream(file);
+ }
+
+ try
+ {
+ return (FileInputStream)AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws FileNotFoundException
+ {
+ return new FileInputStream(file);
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (FileNotFoundException) e.getCause();
+ }
+ }
+
+
+ static public FileInputStream getFileInputStream(final String path) throws FileNotFoundException
+ {
+ if (skipAccessControl)
+ {
+ return new FileInputStream(path);
+ }
+
+ try
+ {
+ return (FileInputStream)AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws FileNotFoundException
+ {
+ return new FileInputStream(path);
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (FileNotFoundException) e.getCause();
+ }
+ }
+
+
+ static public FileOutputStream getFileOutputStream(final File file)
+ throws FileNotFoundException
+ {
+ if (skipAccessControl)
+ {
+ return new FileOutputStream(file);
+ }
+
+ try
+ {
+ return (FileOutputStream)AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws FileNotFoundException
+ {
+ return new FileOutputStream(file);
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (FileNotFoundException) e.getCause();
+ }
+ }
+
+
+ static public FileOutputStream getFileOutputStream(final File file, final boolean append)
+ throws FileNotFoundException
+ {
+ if (skipAccessControl)
+ {
+ return new FileOutputStream(file, append);
+ }
+
+ try
+ {
+ return (FileOutputStream)AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws FileNotFoundException
+ {
+ return new FileOutputStream(file, append);
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (FileNotFoundException) e.getCause();
+ }
+ }
+
+
+ static public boolean canRead(final File file)
+ {
+ if (skipAccessControl)
+ {
+ return file.canRead();
+ }
+
+ return ((Boolean)AccessController.doPrivileged( new PrivilegedAction()
+ {
+ public Object run()
+ {
+ return new Boolean(file.canRead());
+ }
+ })).booleanValue();
+ }
+
+
+ static public boolean createNewFile(final File file) throws IOException
+ {
+ if (skipAccessControl)
+ {
+ return file.createNewFile();
+ }
+
+ try
+ {
+ return ((Boolean)AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws Exception
+ {
+ return new Boolean(file.createNewFile());
+ }
+ })).booleanValue();
+ }
+ catch (Exception e)
+ {
+ throw (IOException) e.getCause();
+ }
+ }
+
+
+ ///////////////////////////////////////////////////////////////////////////////////////
+ // MBeanPermission methods
+ ///////////////////////////////////////////////////////////////////////////////////////
+
+ static public void connect(final Socket socket, final InetSocketAddress address)
+ throws IOException
+ {
+ if (skipAccessControl)
+ {
+ socket.connect(address);
+ return;
+ }
+
+ try
+ {
+ AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws Exception
+ {
+ socket.connect(address);
+ return null;
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (IOException) e.getCause();
+ }
+ }
+
+
+ static public void connect(final Socket socket, final InetSocketAddress address, final int timeout)
+ throws IOException
+ {
+ if (skipAccessControl)
+ {
+ socket.connect(address, timeout);
+ return;
+ }
+
+ try
+ {
+ AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws Exception
+ {
+ socket.connect(address, timeout);
+ return null;
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (IOException) e.getCause();
+ }
+ }
+
+
+ static public MBeanServer createMBeanServer() throws Exception
+ {
+ if (skipAccessControl)
+ {
+ return MBeanServerFactory.createMBeanServer();
+ }
+
+ try
+ {
+ return (MBeanServer) AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws Exception
+ {
+ return MBeanServerFactory.createMBeanServer();
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (Exception) e.getCause();
+ }
+ }
+
+
+ static public boolean isInstanceOf(final MBeanServer server, final ObjectName objectName, final String className)
+ throws InstanceNotFoundException
+ {
+ if (skipAccessControl)
+ {
+ return server.isInstanceOf(objectName, className);
+ }
+
+ try
+ {
+ return ((Boolean)AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws Exception
+ {
+ return new Boolean(server.isInstanceOf(objectName, className));
+ }
+ })).booleanValue();
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (InstanceNotFoundException) e.getCause();
+ }
+ }
+
+
+ static public Object getMBeanAttribute(final MBeanServer server, final ObjectName objectName, final String attribute)
+ throws Exception
+ {
+ if (skipAccessControl)
+ {
+ return server.getAttribute(objectName, attribute);
+ }
+
+ try
+ {
+ return AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws Exception
+ {
+ return server.getAttribute(objectName, attribute);
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (Exception) e.getCause();
+ }
+ }
+
+
+ static public void registerMBean(final MBeanServer server, final Object o, final ObjectName name)
+ throws Exception
+ {
+ if (skipAccessControl)
+ {
+ server.registerMBean(o, name);
+ return;
+ }
+
+ try
+ {
+ AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws Exception
+ {
+ server.registerMBean(o, name);
+ return null;
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (Exception) e.getCause();
+ }
+ }
+
+
+ static public void unregisterMBean(final MBeanServer server, final ObjectName name)
+ throws Exception
+ {
+ if (skipAccessControl)
+ {
+ server.unregisterMBean(name);
+ return;
+ }
+
+ try
+ {
+ AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws Exception
+ {
+ server.unregisterMBean(name);
+ return null;
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (Exception) e.getCause();
+ }
+ }
+
+
+ ///////////////////////////////////////////////////////////////////////////////////////
+ // PropertyPermission methods
+ ///////////////////////////////////////////////////////////////////////////////////////
+
+ static public String getSystemProperty(final String name, final String defaultValue)
+ {
+ if (skipAccessControl)
+ return System.getProperty(name, defaultValue);
+
+ String value = null;
+ try
+ {
+ value = (String)AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws Exception
+ {
+ return System.getProperty(name, defaultValue);
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (RuntimeException) e.getCause();
+ }
+
+ return value;
+ }
+
+
+ static public String getSystemProperty(final String name)
+ {
+ if (skipAccessControl)
+ return System.getProperty(name);
+
+ String value = null;
+ try
+ {
+ value = (String)AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws Exception
+ {
+ return System.getProperty(name);
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (RuntimeException) e.getCause();
+ }
+
+ return value;
+ }
+
+
+ static public void setSystemProperty(final String name, final String value)
+ {
+ if (skipAccessControl)
+ {
+ System.setProperty(name, value);
+ return;
+ }
+
+ try
+ {
+ AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws Exception
+ {
+ return System.setProperty(name, value);
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (RuntimeException) e.getCause();
+ }
+ }
+
+
+ ///////////////////////////////////////////////////////////////////////////////////////
+ // RuntimePermission methods
+ ///////////////////////////////////////////////////////////////////////////////////////
+
+ static public Object forName(final String className) throws ClassNotFoundException
+ {
+ if (skipAccessControl)
+ {
+ return Class.forName(className);
+ }
+
+ try
+ {
+ return AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws Exception
+ {
+ return Class.forName(className);
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (ClassNotFoundException) e.getCause();
+ }
+ }
+
+
+ static public ClassLoader getClassLoader(final Class c)
+ {
+ if (skipAccessControl)
+ {
+ return c.getClassLoader();
+ }
+
+ return (ClassLoader)AccessController.doPrivileged( new PrivilegedAction()
+ {
+ public Object run()
+ {
+ return c.getClassLoader();
+ }
+ });
+ }
+
+
+ static public ClassLoader getSystemClassLoader()
+ {
+ if (skipAccessControl)
+ {
+ return ClassLoader.getSystemClassLoader();
+ }
+
+ return (ClassLoader)AccessController.doPrivileged( new PrivilegedAction()
+ {
+ public Object run()
+ {
+ return ClassLoader.getSystemClassLoader();
+ }
+ });
+ }
+
+
+ static public Method getMethod(final Class c, final String name, final Class[] parameterTypes)
+ throws NoSuchMethodException
+ {
+ if (skipAccessControl)
+ {
+ return c.getMethod(name, parameterTypes);
+ }
+
+ try
+ {
+ return (Method) AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws NoSuchMethodException
+ {
+ return c.getMethod(name, parameterTypes);
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (NoSuchMethodException) e.getCause();
+ }
+ }
+
+
+ static public Method getDeclaredMethod(final Class c, final String name, final Class[] parameterTypes)
+ throws NoSuchMethodException
+ {
+ if (skipAccessControl)
+ {
+ return c.getDeclaredMethod(name, parameterTypes);
+ }
+
+ try
+ {
+ return (Method) AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws NoSuchMethodException
+ {
+ return c.getDeclaredMethod(name, parameterTypes);
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (NoSuchMethodException) e.getCause();
+ }
+ }
+
+ static public Object readObject(final ObjectInputStream ois)
+ throws IOException, ClassNotFoundException
+ {
+ if (skipAccessControl || !(ois instanceof JBossObjectInputStream))
+ {
+ return ois.readObject();
+ }
+
+ try
+ {
+ return AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws IOException, ClassNotFoundException
+ {
+ return ois.readObject();
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ Throwable cause = e.getCause();
+ if (cause instanceof IOException)
+ throw (IOException) cause;
+ else if (cause instanceof ClassNotFoundException)
+ throw (ClassNotFoundException) cause;
+ else
+ throw (RuntimeException) cause;
+ }
+ }
+
+ static public void writeObject(final ObjectOutputStream oos, final Object o)
+ throws IOException
+ {
+ if (skipAccessControl || !(oos instanceof JBossObjectOutputStream))
+ {
+ oos.writeObject(o);
+ return;
+ }
+
+ try
+ {
+ AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws IOException
+ {
+ oos.writeObject(o);
+ return null;
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ Throwable cause = e.getCause();
+ if (cause instanceof IOException)
+ throw (IOException) cause;
+ else
+ throw (RuntimeException) cause;
+ }
+ }
+
+ ///////////////////////////////////////////////////////////////////////////////////////
+ // SocketPermission methods
+ ///////////////////////////////////////////////////////////////////////////////////////
+
+ static public Socket accept(final ServerSocket ss) throws IOException
+ {
+ if (skipAccessControl)
+ {
+ return ss.accept();
+ }
+
+ try
+ {
+ return (Socket)AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws Exception
+ {
+ return ss.accept();
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (IOException) e.getCause();
+ }
+ }
+
+
+ static public void bind(final ServerSocket ss, final SocketAddress address)
+ throws IOException
+ {
+ if (skipAccessControl)
+ {
+ ss.bind(address);
+ return;
+ }
+
+ try
+ {
+ AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws Exception
+ {
+ ss.bind(address);
+ return null;
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (IOException) e.getCause();
+ }
+ }
+
+
+ static public void bind(final ServerSocket ss, final SocketAddress address,
+ final int backlog) throws IOException
+ {
+ if (skipAccessControl)
+ {
+ ss.bind(address, backlog);
+ return;
+ }
+
+ try
+ {
+ AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws Exception
+ {
+ ss.bind(address, backlog);
+ return null;
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (IOException) e.getCause();
+ }
+ }
+
+
+ static public ServerSocket createServerSocket(final ServerSocketFactoryMBean ssf,
+ final int port) throws IOException
+ {
+ if (skipAccessControl)
+ {
+ return ssf.createServerSocket(port);
+ }
+
+ try
+ {
+ return (ServerSocket)AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws Exception
+ {
+ return ssf.createServerSocket(port);
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (IOException) e.getCause();
+ }
+ }
+
+
+ static public ServerSocket createServerSocket(final ServerSocketFactoryMBean ssf,
+ final int port, final int backlog)
+ throws IOException
+ {
+ if (skipAccessControl)
+ {
+ return ssf.createServerSocket(port, backlog);
+ }
+
+ try
+ {
+ return (ServerSocket)AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws Exception
+ {
+ return ssf.createServerSocket(port, backlog);
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (IOException) e.getCause();
+ }
+ }
+
+
+ static public ServerSocket createServerSocket(final ServerSocketFactoryMBean ssf,
+ final int port, final int backlog,
+ final InetAddress inetAddress)
+ throws IOException
+ {
+ if (skipAccessControl)
+ {
+ return ssf.createServerSocket(port, backlog, inetAddress);
+ }
+
+ try
+ {
+ return (ServerSocket)AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws Exception
+ {
+ return ssf.createServerSocket(port, backlog, inetAddress);
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (IOException) e.getCause();
+ }
+ }
+
+
+ static public ServerSocket createServerSocket(final ServerSocketFactory ssf,
+ final int port) throws IOException
+ {
+ if (skipAccessControl)
+ {
+ return ssf.createServerSocket(port);
+ }
+
+ try
+ {
+ return (ServerSocket)AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws Exception
+ {
+ return ssf.createServerSocket(port);
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (IOException) e.getCause();
+ }
+ }
+
+
+ static public ServerSocket createServerSocket(final ServerSocketFactory ssf,
+ final int port, final int backlog)
+ throws IOException
+ {
+ if (skipAccessControl)
+ {
+ return ssf.createServerSocket(port, backlog);
+ }
+
+ try
+ {
+ return (ServerSocket)AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws Exception
+ {
+ return ssf.createServerSocket(port, backlog);
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (IOException) e.getCause();
+ }
+ }
+
+
+ static public ServerSocket createServerSocket(final ServerSocketFactory ssf,
+ final int port, final int backlog,
+ final InetAddress inetAddress)
+ throws IOException
+ {
+ if (skipAccessControl)
+ {
+ return ssf.createServerSocket(port, backlog, inetAddress);
+ }
+
+ try
+ {
+ return (ServerSocket)AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws Exception
+ {
+ return ssf.createServerSocket(port, backlog, inetAddress);
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (IOException) e.getCause();
+ }
+ }
+
+
+ static public ServerSocket createServerSocket(final int port) throws IOException
+ {
+ if (skipAccessControl)
+ {
+ return new ServerSocket(port);
+ }
+
+ try
+ {
+ return (ServerSocket)AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws Exception
+ {
+ return new ServerSocket(port);
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (IOException) e.getCause();
+ }
+ }
+
+
+ static public ServerSocket createServerSocket(final int port, final int backlog)
+ throws IOException
+ {
+ if (skipAccessControl)
+ {
+ return new ServerSocket(port, backlog);
+ }
+
+ try
+ {
+ return (ServerSocket)AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws Exception
+ {
+ return new ServerSocket(port, backlog);
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (IOException) e.getCause();
+ }
+ }
+
+
+ static public ServerSocket createServerSocket(final int port, final int backlog,
+ final InetAddress inetAddress)
+ throws IOException
+ {
+ if (skipAccessControl)
+ {
+ return new ServerSocket(port, backlog, inetAddress);
+ }
+
+ try
+ {
+ return (ServerSocket)AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws Exception
+ {
+ return new ServerSocket(port, backlog, inetAddress);
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (IOException) e.getCause();
+ }
+ }
+
+
+ static public Socket createSocket(final String host, final int port) throws IOException
+ {
+ if (skipAccessControl)
+ {
+ return new Socket(host, port);
+ }
+
+ try
+ {
+ return (Socket)AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws Exception
+ {
+ return new Socket(host, port);
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (IOException) e.getCause();
+ }
+ }
+
+
+ static public Socket createSocket(final SocketFactory sf, final String host, final int port)
+ throws IOException
+ {
+ if (skipAccessControl)
+ {
+ return sf.createSocket(host, port);
+ }
+
+ try
+ {
+ return (Socket)AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws Exception
+ {
+ return sf.createSocket(host, port);
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (IOException) e.getCause();
+ }
+ }
+
+
+ static public InetAddress getLocalHost() throws UnknownHostException
+ {
+ if (skipAccessControl)
+ {
+ try
+ {
+ return InetAddress.getLocalHost();
+ }
+ catch (IOException e)
+ {
+ return InetAddress.getByName("127.0.0.1");
+ }
+ }
+
+ try
+ {
+ return (InetAddress) AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws IOException
+ {
+ try
+ {
+ return InetAddress.getLocalHost();
+ }
+ catch (IOException e)
+ {
+ return InetAddress.getByName("127.0.0.1");
+ }
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (UnknownHostException) e.getCause();
+ }
+ }
+
+
+ static public String getLocalHostName() throws UnknownHostException
+ {
+ if (skipAccessControl)
+ {
+ return getLocalHost().getHostName();
+ }
+
+ try
+ {
+ return (String) AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws IOException
+ {
+ InetAddress address = null;
+ try
+ {
+ address = InetAddress.getLocalHost();
+ }
+ catch (IOException e)
+ {
+ address = InetAddress.getByName("127.0.0.1");
+ }
+
+ return address.getHostName();
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (UnknownHostException) e.getCause();
+ }
+ }
+
+
+ static public InetAddress getAddressByName(final String host) throws UnknownHostException
+ {
+ if (skipAccessControl)
+ {
+ return InetAddress.getByName(host);
+ }
+
+ try
+ {
+ return (InetAddress)AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws IOException
+ {
+ return InetAddress.getByName(host);
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (UnknownHostException) e.getCause();
+ }
+ }
+}
\ No newline at end of file
16 years, 8 months
JBoss Remoting SVN: r4134 - remoting2/branches/2.x/src/main/org/jboss/remoting/transport/rmi.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2008-05-07 19:36:49 -0400 (Wed, 07 May 2008)
New Revision: 4134
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/rmi/RMIServerInvoker.java
Log:
JBREM-934: Make sure JBossSerialization i/o goes through SecurityUtility.
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/transport/rmi/RMIServerInvoker.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/transport/rmi/RMIServerInvoker.java 2008-05-07 23:36:30 UTC (rev 4133)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/transport/rmi/RMIServerInvoker.java 2008-05-07 23:36:49 UTC (rev 4134)
@@ -370,6 +370,7 @@
SerializationManager manager = SerializationStreamFactory.getManagerInstance(getSerializationType());
ObjectOutputStream oos = manager.createOutput(baos);
oos.writeObject(payload);
+ SecurityUtility.writeObject(oos, payload);
oos.flush();
oos.close();
is = new ByteArrayInputStream(baos.toByteArray());
16 years, 8 months
JBoss Remoting SVN: r4133 - remoting2/branches/2.x/src/main/org/jboss/remoting/transport/rmi.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2008-05-07 19:36:30 -0400 (Wed, 07 May 2008)
New Revision: 4133
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/rmi/RMIClientInvoker.java
Log:
JBREM-934: Make sure JBossSerialization i/o goes through SecurityUtility.
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/transport/rmi/RMIClientInvoker.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/transport/rmi/RMIClientInvoker.java 2008-05-07 23:34:23 UTC (rev 4132)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/transport/rmi/RMIClientInvoker.java 2008-05-07 23:36:30 UTC (rev 4133)
@@ -42,6 +42,7 @@
import org.jboss.remoting.marshal.rmi.RMIUnMarshaller;
import org.jboss.remoting.serialization.SerializationManager;
import org.jboss.remoting.serialization.SerializationStreamFactory;
+import org.jboss.remoting.util.SecurityUtility;
import org.jboss.util.threadpool.BasicThreadPool;
import org.jboss.util.threadpool.BlockingMode;
import org.jboss.util.threadpool.RunnableTaskWrapper;
@@ -375,7 +376,7 @@
try
{
byteOut.close();
- payload = ois.readObject();
+ payload = SecurityUtility.readObject(ois);
ois.close();
}
catch(ClassNotFoundException e)
16 years, 8 months
JBoss Remoting SVN: r4132 - remoting2/branches/2.x/src/main/org/jboss/remoting/transport/coyote/ssl.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2008-05-07 19:34:23 -0400 (Wed, 07 May 2008)
New Revision: 4132
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/coyote/ssl/RemotingServerSocketFactory.java
Log:
JBREM-977: Removed unnecessary imports.
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/transport/coyote/ssl/RemotingServerSocketFactory.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/transport/coyote/ssl/RemotingServerSocketFactory.java 2008-05-07 23:34:02 UTC (rev 4131)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/transport/coyote/ssl/RemotingServerSocketFactory.java 2008-05-07 23:34:23 UTC (rev 4132)
@@ -36,9 +36,6 @@
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
-import java.security.AccessController;
-import java.security.PrivilegedActionException;
-import java.security.PrivilegedExceptionAction;
import java.util.HashMap;
import java.util.Map;
16 years, 8 months
JBoss Remoting SVN: r4131 - remoting2/branches/2.x/src/main/org/jboss/remoting/transport.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2008-05-07 19:34:02 -0400 (Wed, 07 May 2008)
New Revision: 4131
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/Connector.java
Log:
JBREM-977: Removed unnecessary configureHandlers() method.
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/transport/Connector.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/transport/Connector.java 2008-05-07 23:33:00 UTC (rev 4130)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/transport/Connector.java 2008-05-07 23:34:02 UTC (rev 4131)
@@ -310,7 +310,6 @@
// want to have handlers registered before starting, so if someone makes invocation,
// there is something to handle it.
- configureHandlers();
if (serverConfiguration != null)
{
configureHandlersFromServerConfiguration();
@@ -761,11 +760,6 @@
}
}
- private void configureHandlers()
- throws Exception
- {
- }
-
private void configureHandlersFromServerConfiguration() throws Exception
{
Map handlerMap = serverConfiguration.getInvocationHandlers();
16 years, 8 months
JBoss Remoting SVN: r4130 - remoting2/branches/2.x/src/main/org/jboss/remoting/security.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2008-05-07 19:33:00 -0400 (Wed, 07 May 2008)
New Revision: 4130
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/security/ServerSocketFactoryWrapper.java
Log:
JBREM-977: A new wrapper for ServerSocketFactory MBean proxies.
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/security/ServerSocketFactoryWrapper.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/security/ServerSocketFactoryWrapper.java 2008-05-07 23:32:17 UTC (rev 4129)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/security/ServerSocketFactoryWrapper.java 2008-05-07 23:33:00 UTC (rev 4130)
@@ -21,17 +21,14 @@
*/
package org.jboss.remoting.security;
-import javax.net.ServerSocketFactory;
-
-import org.jboss.remoting.util.SecurityUtility;
-
import java.io.IOException;
import java.net.InetAddress;
import java.net.ServerSocket;
-import java.security.AccessController;
-import java.security.PrivilegedActionException;
-import java.security.PrivilegedExceptionAction;
+import javax.net.ServerSocketFactory;
+
+import org.jboss.remoting.util.SecurityUtility;
+
/**
* @author <a href="mailto:tom.elrod@jboss.com">Tom Elrod</a>
*/
16 years, 8 months
JBoss Remoting SVN: r4129 - remoting2/branches/2.x/src/main/org/jboss/remoting/network.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2008-05-07 19:32:17 -0400 (Wed, 07 May 2008)
New Revision: 4129
Added:
remoting2/branches/2.x/src/main/org/jboss/remoting/network/NetworkRegistryWrapper.java
Log:
JBREM-977: A new wrapper for NetworkRegistry MBean proxies.
Added: remoting2/branches/2.x/src/main/org/jboss/remoting/network/NetworkRegistryWrapper.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/network/NetworkRegistryWrapper.java (rev 0)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/network/NetworkRegistryWrapper.java 2008-05-07 23:32:17 UTC (rev 4129)
@@ -0,0 +1,336 @@
+
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.remoting.network;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+
+import javax.management.ListenerNotFoundException;
+import javax.management.MBeanNotificationInfo;
+import javax.management.MBeanServer;
+import javax.management.NotificationFilter;
+import javax.management.NotificationListener;
+import javax.management.ObjectName;
+
+import org.jboss.remoting.detection.ServerInvokerMetadata;
+import org.jboss.remoting.ident.Identity;
+import org.jboss.remoting.util.SecurityUtility;
+
+
+/**
+ * A NetworkRegistryWrapper is used to wrap an MBean proxy that implements
+ * org.jboss.remoting.network.NetworkRegistryWrapper. If necessary, each call
+ * will go through an AccessController.doPrivileged() call.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright May 6, 2008
+ * </p>
+ */
+public class NetworkRegistryWrapper implements NetworkRegistryMBean
+{
+ private NetworkRegistryMBean proxy;
+
+ public NetworkRegistryWrapper(NetworkRegistryMBean proxy)
+ {
+ this.proxy = proxy;
+ }
+
+ public void addServer(final Identity identity, final ServerInvokerMetadata[] invokers)
+ {
+ if (SecurityUtility.skipAccessControl())
+ {
+ proxy.addServer(identity, invokers);
+ return;
+ }
+
+ AccessController.doPrivileged( new PrivilegedAction()
+ {
+ public Object run()
+ {
+ proxy.addServer(identity, invokers);
+ return null;
+ }
+ });
+ }
+
+ public void changeDomain(final String newDomain)
+ {
+ if (SecurityUtility.skipAccessControl())
+ {
+ proxy.changeDomain(newDomain);
+ return;
+ }
+
+ AccessController.doPrivileged( new PrivilegedAction()
+ {
+ public Object run()
+ {
+ proxy.changeDomain(newDomain);
+ return null;
+ }
+ });
+ }
+
+ public NetworkInstance[] getServers()
+ {
+ if (SecurityUtility.skipAccessControl())
+ {
+ return proxy.getServers();
+ }
+
+ return (NetworkInstance[]) AccessController.doPrivileged( new PrivilegedAction()
+ {
+ public Object run()
+ {
+ return proxy.getServers();
+ }
+ });
+ }
+
+ public boolean hasServer(final Identity identity)
+ {
+ if (SecurityUtility.skipAccessControl())
+ {
+ return proxy.hasServer(identity);
+ }
+
+ return ((Boolean) AccessController.doPrivileged( new PrivilegedAction()
+ {
+ public Object run()
+ {
+ return new Boolean(proxy.hasServer(identity));
+ }
+ })).booleanValue();
+ }
+
+ public NetworkInstance[] queryServers(final NetworkFilter filter)
+ {
+ if (SecurityUtility.skipAccessControl())
+ {
+ return proxy.queryServers(filter);
+ }
+
+ return (NetworkInstance[]) AccessController.doPrivileged( new PrivilegedAction()
+ {
+ public Object run()
+ {
+ return proxy.queryServers(filter);
+ }
+ });
+ }
+
+ public void removeServer(final Identity identity)
+ {
+ if (SecurityUtility.skipAccessControl())
+ {
+ proxy.removeServer(identity);
+ return;
+ }
+
+ AccessController.doPrivileged( new PrivilegedAction()
+ {
+ public Object run()
+ {
+ proxy.removeServer(identity);
+ return null;
+ }
+ });
+ }
+
+ public void updateServer(final Identity identity, final ServerInvokerMetadata[] invokers)
+ {
+ if (SecurityUtility.skipAccessControl())
+ {
+ proxy.updateServer(identity, invokers);
+ return;
+ }
+
+ AccessController.doPrivileged( new PrivilegedAction()
+ {
+ public Object run()
+ {
+ proxy.updateServer(identity, invokers);
+ return null;
+ }
+ });
+ }
+
+ public void addNotificationListener(final NotificationListener listener,
+ final NotificationFilter filter,
+ final Object handback)
+ throws IllegalArgumentException
+ {
+ if (SecurityUtility.skipAccessControl())
+ {
+ proxy.addNotificationListener(listener, filter, handback);
+ return;
+ }
+
+ try
+ {
+ AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws IllegalArgumentException
+ {
+ proxy.addNotificationListener(listener, filter, handback);
+ return null;
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (IllegalArgumentException) e.getCause();
+ }
+ }
+
+ public MBeanNotificationInfo[] getNotificationInfo()
+ {
+ if (SecurityUtility.skipAccessControl())
+ {
+ return proxy.getNotificationInfo();
+ }
+
+ return (MBeanNotificationInfo[]) AccessController.doPrivileged( new PrivilegedAction()
+ {
+ public Object run()
+ {
+ return proxy.getNotificationInfo();
+ }
+ });
+ }
+
+ public void removeNotificationListener(final NotificationListener listener)
+ throws ListenerNotFoundException
+ {
+ if (SecurityUtility.skipAccessControl())
+ {
+ proxy.removeNotificationListener(listener);
+ return;
+ }
+
+ try
+ {
+ AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws ListenerNotFoundException
+ {
+ proxy.removeNotificationListener(listener);
+ return null;
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (ListenerNotFoundException) e.getCause();
+ }
+ }
+
+ public void postDeregister()
+ {
+ if (SecurityUtility.skipAccessControl())
+ {
+ proxy.postDeregister();
+ return;
+ }
+
+ AccessController.doPrivileged( new PrivilegedAction()
+ {
+ public Object run()
+ {
+ proxy.postDeregister();
+ return null;
+ }
+ });
+ }
+
+ public void postRegister(final Boolean registrationDone)
+ {
+ if (SecurityUtility.skipAccessControl())
+ {
+ proxy.postRegister(registrationDone);
+ return;
+ }
+
+ AccessController.doPrivileged( new PrivilegedAction()
+ {
+ public Object run()
+ {
+ proxy.postRegister(registrationDone);
+ return null;
+ }
+ });
+ }
+
+ public void preDeregister() throws Exception
+ {
+ if (SecurityUtility.skipAccessControl())
+ {
+ proxy.preDeregister();
+ return;
+ }
+
+ try
+ {
+ AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws Exception
+ {
+ proxy.preDeregister();
+ return null;
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (Exception) e.getCause();
+ }
+ }
+
+ public ObjectName preRegister(final MBeanServer server, final ObjectName name)
+ throws Exception
+ {
+ if (SecurityUtility.skipAccessControl())
+ {
+ return proxy.preRegister(server, name);
+ }
+
+ try
+ {
+ return (ObjectName) AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws Exception
+ {
+ return proxy.preRegister(server, name);
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (Exception) e.getCause();
+ }
+ }
+}
\ No newline at end of file
16 years, 8 months