JBoss Remoting SVN: r5025 - remoting2/branches/2.x/src/main/org/jboss/remoting/util.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-04-14 06:27:24 -0400 (Tue, 14 Apr 2009)
New Revision: 5025
Removed:
remoting2/branches/2.x/src/main/org/jboss/remoting/util/ServletSecurityUtility.java
Log:
JBREM-1116: Eliminated ServletSecurityUtility.
Deleted: remoting2/branches/2.x/src/main/org/jboss/remoting/util/ServletSecurityUtility.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/util/ServletSecurityUtility.java 2009-04-14 10:27:01 UTC (rev 5024)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/util/ServletSecurityUtility.java 2009-04-14 10:27:24 UTC (rev 5025)
@@ -1,75 +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.IOException;
-import java.security.AccessController;
-import java.security.PrivilegedActionException;
-import java.security.PrivilegedExceptionAction;
-
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.jboss.remoting.transport.servlet.ServletServerInvokerMBean;
-
-
-/**
- * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
- * @version $Revision: 1.1 $
- * <p>
- * Copyright May 28, 2008
- * </p>
- */
-public class ServletSecurityUtility
-{
- static public byte[] processRequest(final ServletServerInvokerMBean invoker,
- final HttpServletRequest request,
- final byte[] byteArray,
- final HttpServletResponse response)
- throws ServletException, IOException
- {
- if (SecurityUtility.skipAccessControl())
- {
- return invoker.processRequest(request, byteArray, response);
- }
-
- try
- {
- return (byte[]) AccessController.doPrivileged( new PrivilegedExceptionAction()
- {
- public Object run() throws ServletException, IOException
- {
- return invoker.processRequest(request, byteArray, response);
- }
- });
- }
- catch (PrivilegedActionException e)
- {
- Throwable cause = e.getCause();
- if (cause instanceof ServletException)
- throw (ServletException) cause;
- else
- throw (IOException) e.getCause();
- }
- }
-}
15 years, 7 months
JBoss Remoting SVN: r5024 - remoting2/branches/2.x/src/main/org/jboss/remoting/util.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-04-14 06:27:01 -0400 (Tue, 14 Apr 2009)
New Revision: 5024
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/util/SecurityUtility.java
Log:
JBREM-1116: Eliminated all methods except skipAccessControl() from SecurityUtility.
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/util/SecurityUtility.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/util/SecurityUtility.java 2009-04-14 10:26:05 UTC (rev 5023)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/util/SecurityUtility.java 2009-04-14 10:27:01 UTC (rev 5024)
@@ -21,80 +21,13 @@
*/
package org.jboss.remoting.util;
-import java.beans.IntrospectionException;
-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.io.OutputStream;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.net.HttpURLConnection;
-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.rmi.AccessException;
-import java.rmi.NotBoundException;
-import java.rmi.Remote;
-import java.rmi.RemoteException;
-import java.rmi.registry.LocateRegistry;
-import java.rmi.registry.Registry;
-import java.rmi.server.RMIClientSocketFactory;
-import java.rmi.server.RMIServerSocketFactory;
-import java.rmi.server.UnicastRemoteObject;
import java.security.AccessController;
-import java.security.PrivilegedAction;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
-import java.util.ArrayList;
-import java.util.Properties;
-import javax.management.InstanceNotFoundException;
-import javax.management.MBeanServer;
-import javax.management.MBeanServerFactory;
-import javax.management.ObjectName;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingEnumeration;
-import javax.naming.NamingException;
-import javax.net.ServerSocketFactory;
-import javax.net.SocketFactory;
-
import org.jboss.remoting.Remoting;
-import org.jboss.remoting.loading.RemotingClassLoader;
-import org.jboss.remoting.security.ServerSocketFactoryMBean;
-import org.jboss.remoting.transport.rmi.RMIServerInvokerInf;
-import org.jboss.serial.io.JBossObjectInputStream;
-import org.jboss.serial.io.JBossObjectOutputStream;
-import org.jboss.util.propertyeditor.PropertyEditors;
/**
- * SecurityUtility provides a central point for making security sensitive calls.
- *
- * It is divided into six sections:
- *
- * 1. calls requiring FilePermissions
- * 2. calls requiring MBeanPermissions
- * 3. calls requiring PropertyPermissions
- * 4. calls requiring RuntimePermissions
- * 5. calls requiring SocketPermissions
- * 6. calls requiring JBoss permissions
- *
- * When the SecurityUtility class is loaded, it checks for two conditions:
- *
- * 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>
@@ -131,1774 +64,4 @@
{
return skipAccessControl;
}
-
-
- ///////////////////////////////////////////////////////////////////////////////////////
- // FilePermission methods
- ///////////////////////////////////////////////////////////////////////////////////////
-
- static public File createTempFile(final String prefix, final String suffix, final boolean deleteOnExit) throws IOException
- {
- if (skipAccessControl)
- {
- File file = File.createTempFile(prefix, suffix);
- if (deleteOnExit) file.deleteOnExit();
- return file;
- }
-
- try
- {
- return (File)AccessController.doPrivileged( new PrivilegedExceptionAction()
- {
- public Object run() throws IOException
- {
- File file = File.createTempFile(prefix, suffix);
- if (deleteOnExit) file.deleteOnExit();
- return file;
- }
- });
- }
- catch (PrivilegedActionException e)
- {
- throw (IOException) e.getCause();
- }
- }
-
- static public void deleteOnExit(final File file)
- {
- if (file == null)
- return;
-
- if (skipAccessControl)
- {
- file.deleteOnExit();
- return;
- }
-
- AccessController.doPrivileged( new PrivilegedAction()
- {
- public Object run()
- {
- file.deleteOnExit();
- return null;
- }
- });
- }
-
- static public boolean fileExists(final File file)
- {
- if (file == null)
- return false;
-
- 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 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 ArrayList findMBeanServer(final String agentId)
- {
- if (skipAccessControl)
- {
- return MBeanServerFactory.findMBeanServer(agentId);
- }
-
- return (ArrayList)AccessController.doPrivileged( new PrivilegedAction()
- {
- public Object run()
- {
- return MBeanServerFactory.findMBeanServer(agentId);
- }
- });
- }
-
-
- 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 MBeanServer getPlatformMBeanServer()
- throws NoSuchMethodException, IllegalAccessException, InvocationTargetException
- {
- if (skipAccessControl)
- {
- Class c = null;
- try
- {
- c = Class.forName("java.lang.management.ManagementFactory");
- }
- catch (Exception e)
- {
- System.out.println("Unable to access java.lang.management.ManagementFactory: must be using jdk 1.4");
- return null;
- }
- Method m = c.getMethod("getPlatformMBeanServer", new Class[] {});
- MBeanServer s = (MBeanServer) m.invoke(null, new Object[] {});
- return s;
- }
-
- try
- {
- return (MBeanServer) AccessController.doPrivileged( new PrivilegedExceptionAction()
- {
- public Object run()
- throws NoSuchMethodException, IllegalAccessException, InvocationTargetException
- {
- Class c = null;
- try
- {
- c = Class.forName("java.lang.management.ManagementFactory");
- }
- catch (Exception e)
- {
- System.out.println("Unable to access java.lang.management.ManagementFactory: must be using jdk 1.4");
- return null;
- }
- Method m = c.getMethod("getPlatformMBeanServer", new Class[] {});
- MBeanServer s = (MBeanServer) m.invoke(null, new Object[] {});
- return s;
- }
- });
- }
- catch (PrivilegedActionException e)
- {
- Throwable cause = e.getCause();
- if (cause instanceof NoSuchMethodException)
- throw (NoSuchMethodException) cause;
- else if (cause instanceof IllegalAccessException)
- throw (IllegalAccessException) cause;
- else
- throw (InvocationTargetException) cause;
- }
- }
-
-
- 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 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 RemotingClassLoader createRemotingClassLoader(final ClassLoader remotingClassLoader,
- final ClassLoader userClassLoader)
- {
- return createRemotingClassLoader(remotingClassLoader, userClassLoader, true);
- }
-
-
- static public RemotingClassLoader createRemotingClassLoader(final ClassLoader remotingClassLoader,
- final ClassLoader userClassLoader, final boolean parentFirstDelegation)
- {
- if (skipAccessControl)
- {
- return new RemotingClassLoader(remotingClassLoader, userClassLoader, parentFirstDelegation);
- }
-
- return (RemotingClassLoader)AccessController.doPrivileged( new PrivilegedAction()
- {
- public Object run()
- {
- return new RemotingClassLoader(remotingClassLoader, userClassLoader, parentFirstDelegation);
- }
- });
- }
-
-
- 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 getContextClassLoader(final Thread thread)
- {
- if (skipAccessControl)
- {
- return thread.getContextClassLoader();
- }
-
- return (ClassLoader) AccessController.doPrivileged( new PrivilegedAction()
- {
- public Object run()
- {
- return thread.getContextClassLoader();
- }
- });
- }
-
-
- 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)
- {
- Method m = c.getDeclaredMethod(name, parameterTypes);
- m.setAccessible(true);
- return m;
- }
-
- try
- {
- return (Method) AccessController.doPrivileged( new PrivilegedExceptionAction()
- {
- public Object run() throws NoSuchMethodException
- {
- Method m = c.getDeclaredMethod(name, parameterTypes);
- m.setAccessible(true);
- return m;
- }
- });
- }
- catch (PrivilegedActionException e)
- {
- throw (NoSuchMethodException) e.getCause();
- }
- }
-
- static public void mapJavaBeanProperties(final Object o, final Properties props, final boolean isStrict)
- throws IntrospectionException
- {
- if (skipAccessControl)
- {
- PropertyEditors.mapJavaBeanProperties(o, props, isStrict);
- return;
- }
-
- try
- {
- AccessController.doPrivileged( new PrivilegedExceptionAction()
- {
- public Object run() throws IntrospectionException
- {
- PropertyEditors.mapJavaBeanProperties(o, props, isStrict);
- return null;
- }
- });
- }
- catch (PrivilegedActionException e)
- {
- throw (IntrospectionException) e.getCause();
- }
- }
-
-
- static public void namingBeanImplStart(final Object namingBean, final Method startMethod)
- throws IllegalAccessException, InvocationTargetException
- {
- if (skipAccessControl)
- {
- startMethod.invoke(namingBean, new Object[] {});
- return;
- }
-
- try
- {
- AccessController.doPrivileged( new PrivilegedExceptionAction()
- {
- public Object run() throws IllegalAccessException, InvocationTargetException
- {
- startMethod.invoke(namingBean, new Object[] {});
- return null;
- }
- });
- }
- catch (PrivilegedActionException e)
- {
- Throwable cause = e.getCause();
- if (cause instanceof IllegalAccessException)
- throw (IllegalAccessException) cause;
- else
- throw (InvocationTargetException) cause;
- }
- }
-
-
- static public Object readObject(final ObjectInputStream ois)
- throws IOException, ClassNotFoundException
- {
- 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 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 void connect(final HttpURLConnection conn) throws IOException
- {
- if (skipAccessControl)
- {
- conn.connect();
- return;
- }
-
- try
- {
- AccessController.doPrivileged( new PrivilegedExceptionAction()
- {
- public Object run() throws IOException
- {
- conn.connect();
- return null;
- }
- });
- }
- catch (PrivilegedActionException e)
- {
- throw (IOException) e.getCause();
- }
- }
-
-
- static public ServerSocket createServerSocket(final ServerSocketFactoryMBean ssf) throws IOException
- {
- if (skipAccessControl)
- {
- return ssf.createServerSocket();
- }
-
- try
- {
- return (ServerSocket)AccessController.doPrivileged( new PrivilegedExceptionAction()
- {
- public Object run() throws IOException
- {
- return ssf.createServerSocket();
- }
- });
- }
- 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) throws IOException
- {
- if (skipAccessControl)
- {
- return ssf.createServerSocket();
- }
-
- try
- {
- return (ServerSocket)AccessController.doPrivileged( new PrivilegedExceptionAction()
- {
- public Object run() throws IOException
- {
- return ssf.createServerSocket();
- }
- });
- }
- 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 IOException
- {
- 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 IOException
- {
- 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 IOException
- {
- 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 IOException
- {
- 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 IOException
- {
- 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();
- }
- }
-
-
- static public OutputStream getOutputStream(final HttpURLConnection conn)
- throws IOException
- {
- if (skipAccessControl)
- {
- return conn.getOutputStream();
- }
-
- try
- {
- return (OutputStream)AccessController.doPrivileged( new PrivilegedExceptionAction()
- {
- public Object run() throws IOException
- {
- return conn.getOutputStream();
- }
- });
- }
- catch (PrivilegedActionException e)
- {
- throw (IOException) e.getCause();
- }
- }
-
-
- static public int getResponseCode(final HttpURLConnection conn)
- throws IOException
- {
- if (skipAccessControl)
- {
- return conn.getResponseCode();
- }
-
- try
- {
- return ((Integer) AccessController.doPrivileged( new PrivilegedExceptionAction()
- {
- public Object run() throws IOException
- {
- return new Integer(conn.getResponseCode());
- }
- })).intValue();
- }
- catch (PrivilegedActionException e)
- {
- throw (IOException) e.getCause();
- }
- }
-
-
- static public String getResponseMessage(final HttpURLConnection conn)
- throws IOException
- {
- if (skipAccessControl)
- {
- return conn.getResponseMessage();
- }
-
- try
- {
- return (String) AccessController.doPrivileged( new PrivilegedExceptionAction()
- {
- public Object run() throws IOException
- {
- return conn.getResponseMessage();
- }
- });
- }
- catch (PrivilegedActionException e)
- {
- throw (IOException) e.getCause();
- }
- }
-
-
- static public Object callTransport(final RMIServerInvokerInf server, final Object payload)
- throws IOException
- {
- if (skipAccessControl)
- {
- return server.transport(payload);
- }
-
- try
- {
- return AccessController.doPrivileged( new PrivilegedExceptionAction()
- {
- public Object run() throws IOException
- {
- return server.transport(payload);
- }
- });
- }
- catch (PrivilegedActionException e)
- {
- throw (IOException) e.getCause();
- }
- }
-
-
- static public Registry createRegistry(final int port) throws RemoteException
- {
- if (skipAccessControl)
- {
- return LocateRegistry.createRegistry(port);
- }
-
- try
- {
- return (Registry) AccessController.doPrivileged( new PrivilegedExceptionAction()
- {
- public Object run() throws RemoteException
- {
- return LocateRegistry.createRegistry(port);
- }
- });
- }
- catch (PrivilegedActionException e)
- {
- throw (RemoteException) e.getCause();
- }
- }
-
-
- static public Remote exportObject(final Remote object,
- final int port,
- final RMIClientSocketFactory csf,
- final RMIServerSocketFactory ssf)
- throws RemoteException
- {
- if (skipAccessControl)
- {
- return UnicastRemoteObject.exportObject(object, port, csf, ssf);
- }
-
- try
- {
- return (Remote) AccessController.doPrivileged( new PrivilegedExceptionAction()
- {
- public Object run() throws RemoteException
- {
- return UnicastRemoteObject.exportObject(object, port, csf, ssf);
- }
- });
- }
- catch (PrivilegedActionException e)
- {
- throw (RemoteException) e.getCause();
- }
- }
-
-
- static public Registry getRegistry(final int port) throws RemoteException
- {
- if (skipAccessControl)
- {
- return LocateRegistry.getRegistry(port);
- }
-
- try
- {
- return (Registry) AccessController.doPrivileged( new PrivilegedExceptionAction()
- {
- public Object run() throws RemoteException
- {
- return LocateRegistry.getRegistry(port);
- }
- });
- }
- catch (PrivilegedActionException e)
- {
- throw (RemoteException) e.getCause();
- }
- }
-
-
- static public Remote lookup(final Registry registry, final String name)
- throws RemoteException, NotBoundException
- {
- if (skipAccessControl)
- {
- return registry.lookup(name);
- }
-
- try
- {
- return (Remote) AccessController.doPrivileged( new PrivilegedExceptionAction()
- {
- public Object run() throws Exception
- {
- return registry.lookup(name);
- }
- });
- }
- catch (PrivilegedActionException e)
- {
- Throwable cause = e.getCause();
- if (cause instanceof RemoteException)
- throw (RemoteException) cause;
- else
- throw (NotBoundException) cause;
- }
- }
-
-
- static public void rebind(final Registry registry, final String name, final Remote object)
- throws IOException
- {
- if (skipAccessControl)
- {
- registry.rebind(name, object);
- return;
- }
-
- try
- {
- AccessController.doPrivileged( new PrivilegedExceptionAction()
- {
- public Object run() throws IOException
- {
- registry.rebind(name, object);
- return null;
- }
- });
- }
- catch (PrivilegedActionException e)
- {
- throw (IOException) e.getCause();
- }
- }
-
-
- static public void unbind(final Registry registry, final String name)
- throws AccessException, RemoteException, NotBoundException
- {
- if (skipAccessControl)
- {
- registry.unbind(name);
- return;
- }
-
- try
- {
- AccessController.doPrivileged( new PrivilegedExceptionAction()
- {
- public Object run() throws AccessException, RemoteException, NotBoundException
- {
- registry.unbind(name);
- return null;
- }
- });
- }
- catch (PrivilegedActionException e)
- {
- Throwable cause = e.getCause();
- if (cause instanceof AccessException)
- throw (AccessException) cause;
- else if (cause instanceof RemoteException)
- throw (RemoteException) cause;
- else
- throw (NotBoundException) cause;
- }
- }
-
-
- ///////////////////////////////////////////////////////////////////////////////////////
- // JBoss JNDI permission methods
- ///////////////////////////////////////////////////////////////////////////////////////
-
- static public Context createSubcontext(final InitialContext initialContext, final String subContextName)
- throws NamingException
- {
- if (skipAccessControl)
- {
- return initialContext.createSubcontext(subContextName);
- }
-
- try
- {
- return (Context) AccessController.doPrivileged( new PrivilegedExceptionAction()
- {
- public Object run() throws NamingException
- {
- return initialContext.createSubcontext(subContextName);
- }
- });
- }
- catch (PrivilegedActionException e)
- {
- throw (NamingException) e.getCause();
- }
- }
-
-
- static public Context initialContextLookup(final InitialContext initialContext, final String subContextName)
- throws NamingException
- {
- if (skipAccessControl)
- {
- return (Context) initialContext.lookup(subContextName);
- }
-
- try
- {
- return (Context) AccessController.doPrivileged( new PrivilegedExceptionAction()
- {
- public Object run() throws NamingException
- {
- return initialContext.lookup(subContextName);
- }
- });
- }
- catch (PrivilegedActionException e)
- {
- throw (NamingException) e.getCause();
- }
- }
-
- static public NamingEnumeration listBindings(final Context context, final String bindName)
- throws NamingException
- {
- if (skipAccessControl)
- {
- return context.listBindings(bindName);
- }
-
- try
- {
- return (NamingEnumeration) AccessController.doPrivileged( new PrivilegedExceptionAction()
- {
- public Object run() throws NamingException
- {
- return context.listBindings(bindName);
- }
- });
- }
- catch (PrivilegedActionException e)
- {
- throw (NamingException) e.getCause();
- }
- }
-
-
- static public void rebind(final Context context, final String name, final Object object)
- throws NamingException
- {
- if (skipAccessControl)
- {
- context.rebind(name, object);
- return;
- }
-
- try
- {
- AccessController.doPrivileged( new PrivilegedExceptionAction()
- {
- public Object run() throws NamingException
- {
- context.rebind(name, object);
- return null;
- }
- });
- }
- catch (PrivilegedActionException e)
- {
- throw (NamingException) e.getCause();
- }
- }
-
-
- static public void unbind(final Context context, final String name)
- throws NamingException
- {
- if (skipAccessControl)
- {
- context.unbind(name);
- return;
- }
-
- try
- {
- AccessController.doPrivileged( new PrivilegedExceptionAction()
- {
- public Object run() throws NamingException
- {
- context.unbind(name);
- return null;
- }
- });
- }
- catch (PrivilegedActionException e)
- {
- throw (NamingException) e.getCause();
- }
- }
}
\ No newline at end of file
15 years, 7 months
JBoss Remoting SVN: r5023 - remoting2/branches/2.x/src/main/org/jboss/remoting/transporter.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-04-14 06:26:05 -0400 (Tue, 14 Apr 2009)
New Revision: 5023
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/transporter/InternalTransporterServices.java
remoting2/branches/2.x/src/main/org/jboss/remoting/transporter/TransporterClient.java
remoting2/branches/2.x/src/main/org/jboss/remoting/transporter/TransporterHandler.java
remoting2/branches/2.x/src/main/org/jboss/remoting/transporter/TransporterServer.java
Log:
JBREM-1116: Eliminated dependence on SecurityUtility.
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/transporter/InternalTransporterServices.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/transporter/InternalTransporterServices.java 2009-04-14 10:25:23 UTC (rev 5022)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/transporter/InternalTransporterServices.java 2009-04-14 10:26:05 UTC (rev 5023)
@@ -240,7 +240,7 @@
if (registerDetector)
{
- SecurityUtility.registerMBean(m_mBeanServer, m_detector, m_detectorName);
+ registerMBean(m_mBeanServer, m_detector, m_detectorName);
}
}
@@ -299,7 +299,7 @@
if (registerRegistry)
{
- SecurityUtility.registerMBean(m_mBeanServer, m_networkRegistry, m_networkRegistryName);
+ registerMBean(m_mBeanServer, m_networkRegistry, m_networkRegistryName);
}
}
@@ -390,4 +390,30 @@
return;
}
+
+ static private void registerMBean(final MBeanServer server, final Object o, final ObjectName name)
+ throws Exception
+ {
+ if (SecurityUtility.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();
+ }
+ }
}
\ No newline at end of file
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/transporter/TransporterClient.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/transporter/TransporterClient.java 2009-04-14 10:25:23 UTC (rev 5022)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/transporter/TransporterClient.java 2009-04-14 10:26:05 UTC (rev 5023)
@@ -34,6 +34,8 @@
import org.jboss.remoting.util.SecurityUtility;
import javax.management.MBeanServer;
+import javax.management.MBeanServerFactory;
+
import java.io.Serializable;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
@@ -41,6 +43,8 @@
import java.lang.reflect.Proxy;
import java.security.AccessController;
import java.security.PrivilegedAction;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
import java.util.ArrayList;
/**
@@ -133,7 +137,7 @@
if (!services.isSetup())
{
// we need an MBeanServer to store our network registry and multicast detector services
- MBeanServer server = SecurityUtility.createMBeanServer();
+ MBeanServer server = createMBeanServer();
// multicast detector will detect new network registries that come online
MulticastDetector detector = new MulticastDetector();
@@ -427,5 +431,26 @@
return paramSig;
}
-
+ static private MBeanServer createMBeanServer() throws Exception
+ {
+ if (SecurityUtility.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();
+ }
+ }
}
\ No newline at end of file
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/transporter/TransporterHandler.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/transporter/TransporterHandler.java 2009-04-14 10:25:23 UTC (rev 5022)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/transporter/TransporterHandler.java 2009-04-14 10:26:05 UTC (rev 5023)
@@ -83,7 +83,7 @@
}
// use reflection to make the call
- Method method = SecurityUtility.getMethod(targetPOJO.getClass(), methodName, classSig);
+ Method method = getMethod(targetPOJO.getClass(), methodName, classSig);
Object responseObject = method.invoke(targetPOJO, params);
return responseObject;
@@ -146,4 +146,27 @@
//NOOP
}
+ static private Method getMethod(final Class c, final String name, final Class[] parameterTypes)
+ throws NoSuchMethodException
+ {
+ if (SecurityUtility.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();
+ }
+ }
}
\ No newline at end of file
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/transporter/TransporterServer.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/transporter/TransporterServer.java 2009-04-14 10:25:23 UTC (rev 5022)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/transporter/TransporterServer.java 2009-04-14 10:26:05 UTC (rev 5023)
@@ -221,7 +221,7 @@
if (!services.isSetup())
{
// we need an MBeanServer to store our network registry and multicast detector services
- MBeanServer server = SecurityUtility.createMBeanServer();
+ MBeanServer server = createMBeanServer();
// multicast detector will detect new network registries that come online
MulticastDetector detector = new MulticastDetector();
@@ -507,4 +507,26 @@
return createTransporterServer(new InvokerLocator(locatorURI), target, subsystem, false);
}
+ static private MBeanServer createMBeanServer() throws Exception
+ {
+ if (SecurityUtility.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();
+ }
+ }
}
\ No newline at end of file
15 years, 7 months
JBoss Remoting SVN: r5022 - remoting2/branches/2.x/src/main/org/jboss/remoting/transport/web.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-04-14 06:25:23 -0400 (Tue, 14 Apr 2009)
New Revision: 5022
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/web/WebServerInvoker.java
Log:
JBREM-1116: Eliminated dependence on SecurityUtility.
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/transport/web/WebServerInvoker.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/transport/web/WebServerInvoker.java 2009-04-14 10:24:53 UTC (rev 5021)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/transport/web/WebServerInvoker.java 2009-04-14 10:25:23 UTC (rev 5022)
@@ -100,7 +100,7 @@
public UnMarshaller getUnMarshaller()
{
- ClassLoader classLoader = SecurityUtility.getClassLoader(WebServerInvoker.class);
+ ClassLoader classLoader = getClassLoader(WebServerInvoker.class);
UnMarshaller unmarshaller = MarshalFactory.getUnMarshaller(getLocator(), classLoader, configuration);
if(unmarshaller == null)
{
@@ -111,7 +111,7 @@
public Marshaller getMarshaller()
{
- ClassLoader classLoader = SecurityUtility.getClassLoader(WebServerInvoker.class);
+ ClassLoader classLoader = getClassLoader(WebServerInvoker.class);
Marshaller marshaller = MarshalFactory.getMarshaller(getLocator(), classLoader, configuration);
if(marshaller == null)
{
@@ -242,4 +242,20 @@
super(sessionId, subsystem, arg, requestPayload, returnPayload, locator);
}
}
+
+ static private ClassLoader getClassLoader(final Class c)
+ {
+ if (SecurityUtility.skipAccessControl())
+ {
+ return c.getClassLoader();
+ }
+
+ return (ClassLoader)AccessController.doPrivileged( new PrivilegedAction()
+ {
+ public Object run()
+ {
+ return c.getClassLoader();
+ }
+ });
+ }
}
\ No newline at end of file
15 years, 7 months
JBoss Remoting SVN: r5021 - remoting2/branches/2.x/src/main/org/jboss/remoting/transport/sslsocket.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-04-14 06:24:53 -0400 (Tue, 14 Apr 2009)
New Revision: 5021
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/sslsocket/SSLSocketClientInvoker.java
Log:
JBREM-1116: Eliminated dependence on SecurityUtility.
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/transport/sslsocket/SSLSocketClientInvoker.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/transport/sslsocket/SSLSocketClientInvoker.java 2009-04-14 10:24:31 UTC (rev 5020)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/transport/sslsocket/SSLSocketClientInvoker.java 2009-04-14 10:24:53 UTC (rev 5021)
@@ -38,6 +38,9 @@
import java.net.Socket;
import java.net.InetSocketAddress;
import java.net.SocketException;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
import java.util.Map;
/**
@@ -180,7 +183,7 @@
timeout = 0;
}
- SecurityUtility.connect(s, inetAddr, timeout);
+ connect(s, inetAddr, timeout);
if (s instanceof SSLSocket)
{
@@ -231,5 +234,30 @@
sslSocket.getSession();
repeater.waitForHandshake();
}
-
+
+ static private void connect(final Socket socket, final InetSocketAddress address, final int timeout)
+ throws IOException
+ {
+ if (SecurityUtility.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();
+ }
+ }
}
\ No newline at end of file
15 years, 7 months
JBoss Remoting SVN: r5020 - in remoting2/branches/2.x/src/main/org/jboss/remoting/transport: sslbisocket and 1 other directory.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-04-14 06:24:31 -0400 (Tue, 14 Apr 2009)
New Revision: 5020
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/MicroSocketClientInvoker.java
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/ServerThread.java
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/SocketClientInvoker.java
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/SocketServerInvoker.java
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/sslbisocket/SSLBisocketClientInvoker.java
Log:
JBREM-1116: Eliminated dependence on SecurityUtility.
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/MicroSocketClientInvoker.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/MicroSocketClientInvoker.java 2009-04-14 10:23:07 UTC (rev 5019)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/MicroSocketClientInvoker.java 2009-04-14 10:24:31 UTC (rev 5020)
@@ -20,6 +20,7 @@
import org.jboss.remoting.marshal.serializable.SerializableMarshaller;
import org.jboss.util.propertyeditor.PropertyEditors;
+import java.beans.IntrospectionException;
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
@@ -29,6 +30,10 @@
import java.net.Socket;
import java.net.InetSocketAddress;
import java.net.SocketException;
+import java.net.UnknownHostException;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
@@ -488,12 +493,12 @@
{
Properties props = new Properties();
props.putAll(configuration);
- SecurityUtility.mapJavaBeanProperties(MicroSocketClientInvoker.this, props, false);
+ mapJavaBeanProperties(MicroSocketClientInvoker.this, props, false);
configureParameters();
if (!InvokerLocator.MULTIHOME.equals(locator.getHost()))
{
- addr = SecurityUtility.getAddressByName(locator.getHost());
+ addr = getAddressByName(locator.getHost());
port = locator.getPort();
address = createServerAddress(addr, port);
}
@@ -504,7 +509,7 @@
{
// Treat as in non MULTIHOME case.
Home home = (Home) homes.iterator().next();
- addr = SecurityUtility.getAddressByName(home.host);
+ addr = getAddressByName(home.host);
address = createServerAddress(addr, home.port);
}
}
@@ -650,7 +655,7 @@
try
{
home = (Home) it.next();
- addr = SecurityUtility.getAddressByName(home.host);
+ addr = getAddressByName(home.host);
address = createServerAddress(addr, home.port);
invoke(new InvocationRequest(null, null, ServerInvoker.ECHO, null, null, null));
if (trace) log.trace(this + " able to contact server at: " + home);
@@ -1140,7 +1145,7 @@
Socket s = new Socket();
configureSocket(s);
InetSocketAddress inetAddr = new InetSocketAddress(address, port);
- SecurityUtility.connect(s, inetAddr);
+ connect(s, inetAddr);
return s;
}
@@ -1266,7 +1271,81 @@
if (trace) { log.trace(this + " writing version " + version + " on output stream"); }
outputStream.write(version);
}
+
+ static private void mapJavaBeanProperties(final Object o, final Properties props, final boolean isStrict)
+ throws IntrospectionException
+ {
+ if (SecurityUtility.skipAccessControl())
+ {
+ PropertyEditors.mapJavaBeanProperties(o, props, isStrict);
+ return;
+ }
+ try
+ {
+ AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws IntrospectionException
+ {
+ PropertyEditors.mapJavaBeanProperties(o, props, isStrict);
+ return null;
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (IntrospectionException) e.getCause();
+ }
+ }
+
+ static private void connect(final Socket socket, final InetSocketAddress address)
+ throws IOException
+ {
+ if (SecurityUtility.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 private InetAddress getAddressByName(final String host) throws UnknownHostException
+ {
+ if (SecurityUtility.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();
+ }
+ }
// Inner classes --------------------------------------------------------------------------------
}
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/ServerThread.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/ServerThread.java 2009-04-14 10:23:07 UTC (rev 5019)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/ServerThread.java 2009-04-14 10:24:31 UTC (rev 5020)
@@ -52,6 +52,8 @@
import java.net.SocketAddress;
import java.net.SocketException;
import java.net.SocketTimeoutException;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
@@ -99,7 +101,7 @@
return idGenerator++;
}
- private static ClassLoader classLoader = SecurityUtility.getClassLoader(ServerThread.class);
+ private static ClassLoader classLoader = getClassLoader(ServerThread.class);
// Attributes -----------------------------------------------------------------------------------
@@ -1087,4 +1089,20 @@
public static class EvictionException extends Exception
{
}
+
+ static private ClassLoader getClassLoader(final Class c)
+ {
+ if (SecurityUtility.skipAccessControl())
+ {
+ return c.getClassLoader();
+ }
+
+ return (ClassLoader)AccessController.doPrivileged( new PrivilegedAction()
+ {
+ public Object run()
+ {
+ return c.getClassLoader();
+ }
+ });
+ }
}
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/SocketClientInvoker.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/SocketClientInvoker.java 2009-04-14 10:23:07 UTC (rev 5019)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/SocketClientInvoker.java 2009-04-14 10:24:31 UTC (rev 5020)
@@ -36,6 +36,9 @@
import java.net.Socket;
import java.net.SocketTimeoutException;
import java.net.InetSocketAddress;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
import java.util.Map;
/**
@@ -200,7 +203,7 @@
timeout = 0;
}
- SecurityUtility.connect(s, inetAddr, timeout);
+ connect(s, inetAddr, timeout);
return s;
}
@@ -277,4 +280,30 @@
return "SocketClientInvoker[" + Integer.toHexString(System.identityHashCode(this)) + ", " +
locator.getProtocol() + "://" + locator.getHost() + ":" + locator.getPort() + "]";
}
+
+ static private void connect(final Socket socket, final InetSocketAddress address, final int timeout)
+ throws IOException
+ {
+ if (SecurityUtility.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();
+ }
+ }
}
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/SocketServerInvoker.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/SocketServerInvoker.java 2009-04-14 10:23:07 UTC (rev 5019)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/SocketServerInvoker.java 2009-04-14 10:24:31 UTC (rev 5020)
@@ -25,6 +25,7 @@
import org.jboss.remoting.Home;
import org.jboss.remoting.InvokerLocator;
import org.jboss.remoting.ServerInvoker;
+import org.jboss.remoting.security.ServerSocketFactoryMBean;
import org.jboss.remoting.util.SecurityUtility;
import org.jboss.remoting.util.TimerUtil;
import org.jboss.remoting.marshal.serializable.SerializableMarshaller;
@@ -34,12 +35,18 @@
import javax.net.ServerSocketFactory;
import javax.net.ssl.SSLException;
+import java.beans.IntrospectionException;
import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;
+import java.net.SocketAddress;
import java.net.SocketException;
+import java.net.UnknownHostException;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
@@ -201,7 +208,7 @@
protected void setup() throws Exception
{
props.putAll(getConfiguration());
- SecurityUtility.mapJavaBeanProperties(this, props, false);
+ mapJavaBeanProperties(this, props, false);
super.setup();
String ssclass = props.getProperty(SERVER_SOCKET_CLASS_FLAG);
if(ssclass != null)
@@ -321,7 +328,7 @@
ss.setReuseAddress(getReuseAddress());
configureServerSocket(ss);
InetSocketAddress address = new InetSocketAddress(bindAddress, serverBindPort);
- SecurityUtility.bind(ss, address, backlog);
+ bind(ss, address, backlog);
return ss;
}
@@ -333,7 +340,7 @@
while (it.hasNext())
{
Home home = (Home) it.next();
- InetAddress inetAddress = SecurityUtility.getAddressByName(home.host);
+ InetAddress inetAddress = getAddressByName(home.host);
ServerSocket ss = null;
try
@@ -342,7 +349,7 @@
ss.setReuseAddress(getReuseAddress());
configureServerSocket(ss);
InetSocketAddress address = new InetSocketAddress(inetAddress, home.port);
- SecurityUtility.bind(ss, address, backlog);
+ bind(ss, address, backlog);
if (log.isDebugEnabled()) log.debug(this + " created " + ss);
}
catch (SocketException e)
@@ -1010,7 +1017,7 @@
if(trace) { log.trace(this + " is going to wait on serverSocket.accept()"); }
- Socket socket = SecurityUtility.accept(serverSocket);
+ Socket socket = accept(serverSocket);
if(trace) { log.trace(this + " accepted " + socket); }
// the acceptor thread should spend as little time as possbile doing any kind of
@@ -1068,4 +1075,102 @@
this.serverSocket = serverSocket;
}
}
+
+ static private void mapJavaBeanProperties(final Object o, final Properties props, final boolean isStrict)
+ throws IntrospectionException
+ {
+ if (SecurityUtility.skipAccessControl())
+ {
+ PropertyEditors.mapJavaBeanProperties(o, props, isStrict);
+ return;
+ }
+
+ try
+ {
+ AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws IntrospectionException
+ {
+ PropertyEditors.mapJavaBeanProperties(o, props, isStrict);
+ return null;
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (IntrospectionException) e.getCause();
+ }
+ }
+
+ static private Socket accept(final ServerSocket ss) throws IOException
+ {
+ if (SecurityUtility.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 private void bind(final ServerSocket ss, final SocketAddress address,
+ final int backlog) throws IOException
+ {
+ if (SecurityUtility.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 private InetAddress getAddressByName(final String host) throws UnknownHostException
+ {
+ if (SecurityUtility.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();
+ }
+ }
}
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/transport/sslbisocket/SSLBisocketClientInvoker.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/transport/sslbisocket/SSLBisocketClientInvoker.java 2009-04-14 10:23:07 UTC (rev 5019)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/transport/sslbisocket/SSLBisocketClientInvoker.java 2009-04-14 10:24:31 UTC (rev 5020)
@@ -26,6 +26,9 @@
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.SocketException;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
import java.util.Map;
import javax.net.SocketFactory;
@@ -182,7 +185,7 @@
timeout = 0;
}
- SecurityUtility.connect(s, inetAddr, timeout);
+ connect(s, inetAddr, timeout);
if (s instanceof SSLSocket)
{
@@ -233,4 +236,30 @@
sslSocket.getSession();
repeater.waitForHandshake();
}
+
+ static private void connect(final Socket socket, final InetSocketAddress address, final int timeout)
+ throws IOException
+ {
+ if (SecurityUtility.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();
+ }
+ }
}
\ No newline at end of file
15 years, 7 months
JBoss Remoting SVN: r5019 - remoting2/branches/2.x/src/main/org/jboss/remoting/transport/servlet/web.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-04-14 06:23:07 -0400 (Tue, 14 Apr 2009)
New Revision: 5019
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/servlet/web/ServerInvokerServlet.java
Log:
JBREM-1116: Eliminated dependence on SecurityUtility and ServletSecurityUtility.
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/transport/servlet/web/ServerInvokerServlet.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/transport/servlet/web/ServerInvokerServlet.java 2009-04-14 10:22:29 UTC (rev 5018)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/transport/servlet/web/ServerInvokerServlet.java 2009-04-14 10:23:07 UTC (rev 5019)
@@ -28,9 +28,8 @@
import org.jboss.remoting.ServerInvoker;
import org.jboss.remoting.transport.servlet.ServletServerInvokerMBean;
import org.jboss.remoting.util.SecurityUtility;
-import org.jboss.remoting.util.ServletSecurityUtility;
-
import javax.management.MBeanServer;
+import javax.management.MBeanServerFactory;
import javax.management.MBeanServerInvocationHandler;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
@@ -43,7 +42,14 @@
import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
import java.net.MalformedURLException;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+import java.util.ArrayList;
import java.util.Iterator;
/**
@@ -133,7 +139,7 @@
}
byteOutputStream.flush();
byte[] totalByteArray = byteOutputStream.toByteArray();
- byte[] out = ServletSecurityUtility.processRequest(servletInvoker, request, totalByteArray, response);
+ byte[] out = processRequest(servletInvoker, request, totalByteArray, response);
ServletOutputStream outStream = response.getOutputStream();
outStream.write(out);
outStream.flush();
@@ -287,7 +293,7 @@
{
try
{
- MBeanServer s = SecurityUtility.getPlatformMBeanServer();
+ MBeanServer s = getPlatformMBeanServer();
log.debug("Using platform MBeanServer");
return s;
}
@@ -297,7 +303,7 @@
}
}
- Iterator i = SecurityUtility.findMBeanServer(null).iterator();
+ Iterator i = findMBeanServer(null).iterator();
while(i.hasNext())
{
MBeanServer server = (MBeanServer) i.next();
@@ -315,4 +321,106 @@
return null;
}
+
+ static private ArrayList findMBeanServer(final String agentId)
+ {
+ if (SecurityUtility.skipAccessControl())
+ {
+ return MBeanServerFactory.findMBeanServer(agentId);
+ }
+
+ return (ArrayList)AccessController.doPrivileged( new PrivilegedAction()
+ {
+ public Object run()
+ {
+ return MBeanServerFactory.findMBeanServer(agentId);
+ }
+ });
+ }
+
+ static private MBeanServer getPlatformMBeanServer()
+ throws NoSuchMethodException, IllegalAccessException, InvocationTargetException
+ {
+ if (SecurityUtility.skipAccessControl())
+ {
+ Class c = null;
+ try
+ {
+ c = Class.forName("java.lang.management.ManagementFactory");
+ }
+ catch (Exception e)
+ {
+ System.out.println("Unable to access java.lang.management.ManagementFactory: must be using jdk 1.4");
+ return null;
+ }
+ Method m = c.getMethod("getPlatformMBeanServer", new Class[] {});
+ MBeanServer s = (MBeanServer) m.invoke(null, new Object[] {});
+ return s;
+ }
+
+ try
+ {
+ return (MBeanServer) AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run()
+ throws NoSuchMethodException, IllegalAccessException, InvocationTargetException
+ {
+ Class c = null;
+ try
+ {
+ c = Class.forName("java.lang.management.ManagementFactory");
+ }
+ catch (Exception e)
+ {
+ System.out.println("Unable to access java.lang.management.ManagementFactory: must be using jdk 1.4");
+ return null;
+ }
+ Method m = c.getMethod("getPlatformMBeanServer", new Class[] {});
+ MBeanServer s = (MBeanServer) m.invoke(null, new Object[] {});
+ return s;
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ Throwable cause = e.getCause();
+ if (cause instanceof NoSuchMethodException)
+ throw (NoSuchMethodException) cause;
+ else if (cause instanceof IllegalAccessException)
+ throw (IllegalAccessException) cause;
+ else
+ throw (InvocationTargetException) cause;
+ }
+ }
+
+ static private byte[] processRequest(final ServletServerInvokerMBean invoker,
+ final HttpServletRequest request,
+ final byte[] byteArray,
+ final HttpServletResponse response)
+ throws ServletException, IOException
+ {
+ if (SecurityUtility.skipAccessControl())
+ {
+ return invoker.processRequest(request, byteArray, response);
+ }
+
+ try
+ {
+ return (byte[]) AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws ServletException, IOException
+ {
+ return invoker.processRequest(request, byteArray, response);
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ Throwable cause = e.getCause();
+ if (cause instanceof ServletException)
+ throw (ServletException) cause;
+ else
+ throw (IOException) e.getCause();
+ }
+ }
}
\ No newline at end of file
15 years, 7 months
JBoss Remoting SVN: r5018 - remoting2/branches/2.x/src/main/org/jboss/remoting/transport/servlet.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-04-14 06:22:29 -0400 (Tue, 14 Apr 2009)
New Revision: 5018
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/servlet/ServletServerInvoker.java
Log:
JBREM-1116: Eliminated dependence on SecurityUtility.
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/transport/servlet/ServletServerInvoker.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/transport/servlet/ServletServerInvoker.java 2009-04-14 10:22:01 UTC (rev 5017)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/transport/servlet/ServletServerInvoker.java 2009-04-14 10:22:29 UTC (rev 5018)
@@ -48,6 +48,10 @@
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
@@ -199,7 +203,7 @@
}
String remoteAddressString = request.getRemoteAddr();
- InetAddress remoteAddress = SecurityUtility.getAddressByName(remoteAddressString);
+ InetAddress remoteAddress = getAddressByName(remoteAddressString);
Map requestPayload = invocationRequest.getRequestPayload();
if (requestPayload == null)
@@ -366,7 +370,7 @@
}
String remoteAddressString = request.getRemoteAddr();
- InetAddress remoteAddress = SecurityUtility.getAddressByName(remoteAddressString);
+ InetAddress remoteAddress = getAddressByName(remoteAddressString);
Map requestPayload = invocationRequest.getRequestPayload();
if (requestPayload == null)
@@ -502,4 +506,27 @@
return flag;
}
+
+ static private InetAddress getAddressByName(final String host) throws UnknownHostException
+ {
+ if (SecurityUtility.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
15 years, 7 months
JBoss Remoting SVN: r5017 - 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: 2009-04-14 06:22:01 -0400 (Tue, 14 Apr 2009)
New Revision: 5017
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/RMIServerInvoker.java
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/rmi/RemotingRMIClientSocketFactory.java
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/rmi/RemotingRMIServerSocketFactory.java
Log:
JBREM-1116: Eliminated dependence on 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 2009-04-14 10:20:53 UTC (rev 5016)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/transport/rmi/RMIClientInvoker.java 2009-04-14 10:22:01 UTC (rev 5017)
@@ -43,6 +43,7 @@
import org.jboss.remoting.serialization.SerializationManager;
import org.jboss.remoting.serialization.SerializationStreamFactory;
import org.jboss.remoting.util.SecurityUtility;
+import org.jboss.serial.io.JBossObjectInputStream;
import org.jboss.util.threadpool.BasicThreadPool;
import org.jboss.util.threadpool.BlockingMode;
import org.jboss.util.threadpool.RunnableTaskWrapper;
@@ -54,10 +55,14 @@
import java.io.IOException;
import java.io.ObjectInputStream;
import java.net.SocketTimeoutException;
+import java.rmi.NotBoundException;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
@@ -229,7 +234,7 @@
log.debug(this + " looking up registry: " + host + "," + port);
final Registry registry = LocateRegistry.getRegistry(host, registryPort);
log.debug(this + " trying to connect to: " + home);
- Remote remoteObj = SecurityUtility.lookup(registry, "remoting/RMIServerInvoker/" + port);
+ Remote remoteObj = lookup(registry, "remoting/RMIServerInvoker/" + port);
log.debug("Remote RMI Stub: " + remoteObj);
setServerStub((RMIServerInvokerInf) remoteObj);
connected = true;
@@ -358,7 +363,7 @@
try
{
byteOut.close();
- payload = SecurityUtility.readObject(ois);
+ payload = readObject(ois);
ois.close();
}
catch(ClassNotFoundException e)
@@ -377,7 +382,7 @@
int simulatedTimeout = getSimulatedTimeout(configuration, metadata);
if (simulatedTimeout <= 0)
{
- Object result = SecurityUtility.callTransport(server, payload);
+ Object result = callTransport(server, payload);
return unmarshal(result, unmarshaller, metadata);
}
else
@@ -394,7 +399,7 @@
{
try
{
- resultHolder.value = SecurityUtility.callTransport(server, finalPayload);
+ resultHolder.value = callTransport(server, finalPayload);
if (log.isTraceEnabled()) log.trace("result: " + resultHolder.value);
}
catch (Exception e)
@@ -604,4 +609,86 @@
return "WaitingTaskWrapper[" + completeTimeout + "]";
}
}
+
+ static private Object readObject(final ObjectInputStream ois)
+ throws IOException, ClassNotFoundException
+ {
+ if (SecurityUtility.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 private Object callTransport(final RMIServerInvokerInf server, final Object payload)
+ throws IOException
+ {
+ if (SecurityUtility.skipAccessControl())
+ {
+ return server.transport(payload);
+ }
+
+ try
+ {
+ return AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws IOException
+ {
+ return server.transport(payload);
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (IOException) e.getCause();
+ }
+ }
+
+ static private Remote lookup(final Registry registry, final String name)
+ throws RemoteException, NotBoundException
+ {
+ if (SecurityUtility.skipAccessControl())
+ {
+ return registry.lookup(name);
+ }
+
+ try
+ {
+ return (Remote) AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws Exception
+ {
+ return registry.lookup(name);
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ Throwable cause = e.getCause();
+ if (cause instanceof RemoteException)
+ throw (RemoteException) cause;
+ else
+ throw (NotBoundException) cause;
+ }
+ }
}
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 2009-04-14 10:20:53 UTC (rev 5016)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/transport/rmi/RMIServerInvoker.java 2009-04-14 10:22:01 UTC (rev 5017)
@@ -40,24 +40,35 @@
import org.jboss.remoting.serialization.SerializationManager;
import org.jboss.remoting.serialization.SerializationStreamFactory;
import org.jboss.remoting.util.SecurityUtility;
+import org.jboss.serial.io.JBossObjectOutputStream;
import org.jboss.util.propertyeditor.PropertyEditors;
import org.jboss.logging.Logger;
import javax.net.SocketFactory;
+import java.beans.IntrospectionException;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.rmi.AccessException;
+import java.rmi.NotBoundException;
import java.rmi.Remote;
import java.rmi.RemoteException;
+import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.ExportException;
+import java.rmi.server.RMIClientSocketFactory;
import java.rmi.server.RMIServerSocketFactory;
import java.rmi.server.RemoteServer;
import java.rmi.server.ServerNotActiveException;
import java.rmi.server.UnicastRemoteObject;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
@@ -141,7 +152,7 @@
{
Properties props = new Properties();
props.putAll(getConfiguration());
- SecurityUtility.mapJavaBeanProperties(RMIServerInvoker.this, props, false);
+ mapJavaBeanProperties(RMIServerInvoker.this, props, false);
super.setup();
}
@@ -190,11 +201,11 @@
locator.setHomeInUse(bindHome);
RMIServerSocketFactory ssf = new RemotingRMIServerSocketFactory(getServerSocketFactory(), BACKLOG_DEFAULT, bindHost, getTimeout());
csf = getRMIClientSocketFactory(clientConnectHost);
- stub = SecurityUtility.exportObject(this, bindPort, csf, ssf);
+ stub = exportObject(this, bindPort, csf, ssf);
log.debug("Binding server to \"remoting/RMIServerInvoker/" + bindPort + "\" in registry");
- SecurityUtility.rebind(registry, "remoting/RMIServerInvoker/" + bindPort, this);
- ClassLoader classLoader = SecurityUtility.getClassLoader(RMIServerInvoker.class);
+ rebind(registry, "remoting/RMIServerInvoker/" + bindPort, this);
+ ClassLoader classLoader = getClassLoader(RMIServerInvoker.class);
unmarshaller = MarshalFactory.getUnMarshaller(getLocator(), classLoader, configuration);
marshaller = MarshalFactory.getMarshaller(getLocator(), classLoader, configuration);
}
@@ -259,14 +270,14 @@
{
log.debug("Creating registry for " + port);
- registry = SecurityUtility.createRegistry(port);
+ registry = createRegistry(port);
}
catch(ExportException exportEx)
{
log.debug("Locating registry for " + port);
// Probably means that the registry already exists, so just get it.
- registry = SecurityUtility.getRegistry(port);
+ registry = getRegistry(port);
}
if(log.isTraceEnabled())
{
@@ -293,7 +304,7 @@
log.debug("locator: " + locator + ", home: " + locator.getHomeInUse());
log.debug(this + " primary: " + isPrimaryServer + " unbinding " + "remoting/RMIServerInvoker/" + locator.getPort() + " from registry");
Registry registry = getRegistry();
- SecurityUtility.unbind(registry, "remoting/RMIServerInvoker/" + locator.getPort());
+ unbind(registry, "remoting/RMIServerInvoker/" + locator.getPort());
log.debug("unbound " + "remoting/RMIServerInvoker/" + locator.getPort() + " from registry");
}
catch(Exception e)
@@ -368,7 +379,7 @@
ByteArrayOutputStream baos = new ByteArrayOutputStream();
SerializationManager manager = SerializationStreamFactory.getManagerInstance(getSerializationType());
ObjectOutputStream oos = manager.createOutput(baos);
- SecurityUtility.writeObject(oos, payload);
+ writeObject(oos, payload);
oos.flush();
oos.close();
is = new ByteArrayInputStream(baos.toByteArray());
@@ -411,7 +422,7 @@
try
{
String clientHost = RemoteServer.getClientHost();
- InetAddress clientAddress = SecurityUtility.getAddressByName(clientHost);
+ InetAddress clientAddress = getAddressByName(clientHost);
metadata.put(Remoting.CLIENT_ADDRESS, clientAddress);
}
catch (ServerNotActiveException e)
@@ -451,4 +462,230 @@
{
this.rmiOnewayMarshalling = rmiOnewayMarshalling;
}
+
+ static private ClassLoader getClassLoader(final Class c)
+ {
+ if (SecurityUtility.skipAccessControl())
+ {
+ return c.getClassLoader();
+ }
+
+ return (ClassLoader)AccessController.doPrivileged( new PrivilegedAction()
+ {
+ public Object run()
+ {
+ return c.getClassLoader();
+ }
+ });
+ }
+
+ static private void mapJavaBeanProperties(final Object o, final Properties props, final boolean isStrict)
+ throws IntrospectionException
+ {
+ if (SecurityUtility.skipAccessControl())
+ {
+ PropertyEditors.mapJavaBeanProperties(o, props, isStrict);
+ return;
+ }
+
+ try
+ {
+ AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws IntrospectionException
+ {
+ PropertyEditors.mapJavaBeanProperties(o, props, isStrict);
+ return null;
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (IntrospectionException) e.getCause();
+ }
+ }
+
+ static private void writeObject(final ObjectOutputStream oos, final Object o)
+ throws IOException
+ {
+ if (SecurityUtility.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;
+ }
+ }
+
+ static private InetAddress getAddressByName(final String host) throws UnknownHostException
+ {
+ if (SecurityUtility.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();
+ }
+ }
+
+ static private Registry createRegistry(final int port) throws RemoteException
+ {
+ if (SecurityUtility.skipAccessControl())
+ {
+ return LocateRegistry.createRegistry(port);
+ }
+
+ try
+ {
+ return (Registry) AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws RemoteException
+ {
+ return LocateRegistry.createRegistry(port);
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (RemoteException) e.getCause();
+ }
+ }
+
+ static private Remote exportObject(final Remote object,
+ final int port,
+ final RMIClientSocketFactory csf,
+ final RMIServerSocketFactory ssf)
+ throws RemoteException
+ {
+ if (SecurityUtility.skipAccessControl())
+ {
+ return UnicastRemoteObject.exportObject(object, port, csf, ssf);
+ }
+
+ try
+ {
+ return (Remote) AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws RemoteException
+ {
+ return UnicastRemoteObject.exportObject(object, port, csf, ssf);
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (RemoteException) e.getCause();
+ }
+ }
+
+ static private Registry getRegistry(final int port) throws RemoteException
+ {
+ if (SecurityUtility.skipAccessControl())
+ {
+ return LocateRegistry.getRegistry(port);
+ }
+
+ try
+ {
+ return (Registry) AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws RemoteException
+ {
+ return LocateRegistry.getRegistry(port);
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (RemoteException) e.getCause();
+ }
+ }
+
+ static private void rebind(final Registry registry, final String name, final Remote object)
+ throws IOException
+ {
+ if (SecurityUtility.skipAccessControl())
+ {
+ registry.rebind(name, object);
+ return;
+ }
+
+ try
+ {
+ AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws IOException
+ {
+ registry.rebind(name, object);
+ return null;
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (IOException) e.getCause();
+ }
+ }
+
+ static private void unbind(final Registry registry, final String name)
+ throws AccessException, RemoteException, NotBoundException
+ {
+ if (SecurityUtility.skipAccessControl())
+ {
+ registry.unbind(name);
+ return;
+ }
+
+ try
+ {
+ AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws AccessException, RemoteException, NotBoundException
+ {
+ registry.unbind(name);
+ return null;
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ Throwable cause = e.getCause();
+ if (cause instanceof AccessException)
+ throw (AccessException) cause;
+ else if (cause instanceof RemoteException)
+ throw (RemoteException) cause;
+ else
+ throw (NotBoundException) cause;
+ }
+ }
}
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/transport/rmi/RemotingRMIClientSocketFactory.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/transport/rmi/RemotingRMIClientSocketFactory.java 2009-04-14 10:20:53 UTC (rev 5016)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/transport/rmi/RemotingRMIClientSocketFactory.java 2009-04-14 10:22:01 UTC (rev 5017)
@@ -198,7 +198,7 @@
log.warn("unable to retrieve socket factory: returning plain socket");
}
- return SecurityUtility.createSocket(effectiveHost, port);
+ return createSocketPrivate(effectiveHost, port);
}
socketFactory = retrieveSocketFactory(holder);
@@ -207,11 +207,11 @@
Socket socket = null;
if(socketFactory != null)
{
- socket = SecurityUtility.createSocket(socketFactory, effectiveHost, port);
+ socket = createSocketPrivate(socketFactory, effectiveHost, port);
}
else
{
- socket = SecurityUtility.createSocket(effectiveHost, port);
+ socket = createSocketPrivate(effectiveHost, port);
}
socket.setSoTimeout(timeout);
@@ -273,7 +273,7 @@
try
{
- host = SecurityUtility.getAddressByName(invokerLocator.getHost());
+ host = getAddressByName(invokerLocator.getHost());
}
catch (UnknownHostException e)
{
@@ -301,4 +301,74 @@
return hashCode;
}
}
+
+ static private Socket createSocketPrivate(final String host, final int port) throws IOException
+ {
+ if (SecurityUtility.skipAccessControl())
+ {
+ return new Socket(host, port);
+ }
+
+ try
+ {
+ return (Socket)AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws IOException
+ {
+ return new Socket(host, port);
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (IOException) e.getCause();
+ }
+ }
+
+ static private Socket createSocketPrivate(final SocketFactory sf, final String host, final int port)
+ throws IOException
+ {
+ if (SecurityUtility.skipAccessControl())
+ {
+ return sf.createSocket(host, port);
+ }
+
+ try
+ {
+ return (Socket)AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws IOException
+ {
+ return sf.createSocket(host, port);
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (IOException) e.getCause();
+ }
+ }
+
+ static private InetAddress getAddressByName(final String host) throws UnknownHostException
+ {
+ if (SecurityUtility.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
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/transport/rmi/RemotingRMIServerSocketFactory.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/transport/rmi/RemotingRMIServerSocketFactory.java 2009-04-14 10:20:53 UTC (rev 5016)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/transport/rmi/RemotingRMIServerSocketFactory.java 2009-04-14 10:22:01 UTC (rev 5017)
@@ -123,7 +123,7 @@
this.serverSocketFactory = serverSocketFactory;
this.backlog = backlog;
this.timeout = timeout;
- this.bindAddress = SecurityUtility.getAddressByName(bindHost);
+ this.bindAddress = getAddressByName(bindHost);
}
public RemotingRMIServerSocketFactory(String bindHost, int timeout) throws UnknownHostException
@@ -154,7 +154,7 @@
if(serverSocketFactory != null)
{
- svrSocket = SecurityUtility.createServerSocket(serverSocketFactory, port, backlog, bindAddress);
+ svrSocket = createServerSocket(serverSocketFactory, port, backlog, bindAddress);
}
// if (constructor != null)
@@ -174,7 +174,7 @@
else
{
- svrSocket = SecurityUtility.createServerSocket(port, backlog, bindAddress);
+ svrSocket = createServerSocket(port, backlog, bindAddress);
}
svrSocket.setSoTimeout(timeout);
@@ -263,4 +263,78 @@
return backlog * bindAddress.hashCode();
}
+
+ static private ServerSocket createServerSocket(final ServerSocketFactory ssf,
+ final int port, final int backlog,
+ final InetAddress inetAddress)
+ throws IOException
+ {
+ if (SecurityUtility.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 private ServerSocket createServerSocket(final int port, final int backlog,
+ final InetAddress inetAddress)
+ throws IOException
+ {
+ if (SecurityUtility.skipAccessControl())
+ {
+ return new ServerSocket(port, backlog, inetAddress);
+ }
+
+ try
+ {
+ return (ServerSocket)AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws IOException
+ {
+ return new ServerSocket(port, backlog, inetAddress);
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (IOException) e.getCause();
+ }
+ }
+
+ static private InetAddress getAddressByName(final String host) throws UnknownHostException
+ {
+ if (SecurityUtility.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
15 years, 7 months
JBoss Remoting SVN: r5016 - remoting2/branches/2.x/src/main/org/jboss/remoting/transport/http.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-04-14 06:20:53 -0400 (Tue, 14 Apr 2009)
New Revision: 5016
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/http/HTTPClientInvoker.java
Log:
JBREM-1116: Eliminated dependence on SecurityUtility.
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/transport/http/HTTPClientInvoker.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/transport/http/HTTPClientInvoker.java 2009-04-14 10:20:18 UTC (rev 5015)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/transport/http/HTTPClientInvoker.java 2009-04-14 10:20:53 UTC (rev 5016)
@@ -64,6 +64,9 @@
import java.net.SocketAddress;
import java.net.SocketTimeoutException;
import java.net.URL;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
@@ -328,12 +331,12 @@
conn.setDoInput(true);
conn.setRequestMethod(type);
- OutputStream stream = SecurityUtility.getOutputStream(conn);
+ OutputStream stream = getOutputStream(conn);
if (marshaller instanceof VersionedMarshaller)
((VersionedMarshaller) marshaller).write(invocation, stream, getVersion());
else
marshaller.write(invocation, stream);
- responseCode = SecurityUtility.getResponseCode(conn);
+ responseCode = getResponseCode(conn);
Map headers = conn.getHeaderFields();
if (metadata == null)
@@ -355,7 +358,7 @@
}
}
- String responseMessage = SecurityUtility.getResponseMessage(conn);
+ String responseMessage = getResponseMessage(conn);
metadata.put(HTTPMetadataConstants.RESPONSE_CODE_MESSAGE, responseMessage);
metadata.put(HTTPMetadataConstants.RESPONSE_CODE, new Integer(responseCode));
metadata.put(HTTPMetadataConstants.RESPONSE_HEADERS, headers);
@@ -372,9 +375,9 @@
conn.setDoInput(true);
conn.setRequestMethod(type);
- SecurityUtility.connect(conn);
+ connect(conn);
- InputStream is = (SecurityUtility.getResponseCode(conn) < 400) ? conn.getInputStream() : conn.getErrorStream();
+ InputStream is = (getResponseCode(conn) < 400) ? conn.getInputStream() : conn.getErrorStream();
Map headers = conn.getHeaderFields();
if (is != null || unmarshalNullStream)
@@ -387,9 +390,9 @@
metadata = new HashMap();
}
metadata.putAll(headers);
- String responseMessage = SecurityUtility.getResponseMessage(conn);
+ String responseMessage = getResponseMessage(conn);
metadata.put(HTTPMetadataConstants.RESPONSE_CODE_MESSAGE, responseMessage);
- responseCode = SecurityUtility.getResponseCode(conn);
+ responseCode = getResponseCode(conn);
metadata.put(HTTPMetadataConstants.RESPONSE_CODE, new Integer(responseCode));
metadata.put(HTTPMetadataConstants.RESPONSE_HEADERS, conn.getHeaderFields());
}
@@ -402,8 +405,8 @@
try
{
- String responseMessage = SecurityUtility.getResponseMessage(conn);
- int code = SecurityUtility.getResponseCode(conn);
+ String responseMessage = getResponseMessage(conn);
+ int code = getResponseCode(conn);
message += " Response: " + responseMessage + "/" + code + ".";
}
catch (IOException e1)
@@ -495,7 +498,7 @@
conn.setRequestProperty(HTTPMetadataConstants.REMOTING_USER_AGENT, "JBossRemoting - " + Version.VERSION);
conn.setRequestProperty(HTTPMetadataConstants.REMOTING_LEASE_QUERY, "true");
conn.setRequestProperty("sessionId", request.getSessionId());
- SecurityUtility.connect(conn);
+ connect(conn);
//InputStream is = (conn.getResponseCode() < 400) ? conn.getInputStream() : conn.getErrorStream();
Map headers = conn.getHeaderFields();
@@ -599,7 +602,7 @@
{
Class cl = conn.getClass();
Class[] paramTypes = new Class[] {int.class};
- Method setChunkedLengthMethod = SecurityUtility.getMethod(cl, "setChunkedStreamingMode", paramTypes);
+ Method setChunkedLengthMethod = getMethod(cl, "setChunkedStreamingMode", paramTypes);
setChunkedLengthMethod.invoke(conn, new Object[]{new Integer(chunkedLength)});
}
catch (NoSuchMethodException e)
@@ -675,9 +678,9 @@
{
Class cl = conn.getClass();
Class[] paramTypes = new Class[] {int.class};
- Method setTimeoutMethod = SecurityUtility.getMethod(cl, "setConnectTimeout", paramTypes);
+ Method setTimeoutMethod = getMethod(cl, "setConnectTimeout", paramTypes);
setTimeoutMethod.invoke(conn, new Object[]{new Integer(timeout)});
- setTimeoutMethod = SecurityUtility.getMethod(cl, "setReadTimeout", paramTypes);
+ setTimeoutMethod = getMethod(cl, "setReadTimeout", paramTypes);
setTimeoutMethod.invoke(conn, new Object[]{new Integer(timeout)});
return -1;
}
@@ -817,7 +820,7 @@
}
Constructor proxyConstructor = proxyClass.getConstructor(new Class[] {proxyTypeClass, SocketAddress.class});
Object proxy = proxyConstructor.newInstance(new Object[] {proxyType, proxyAddress});
- Method openConnection = SecurityUtility.getMethod(URL.class, "openConnection", new Class[] {proxyClass});
+ Method openConnection = getMethod(URL.class, "openConnection", new Class[] {proxyClass});
httpURLConn = (HttpURLConnection)openConnection.invoke(externalURL, new Object[] {proxy});
}
catch (Exception e)
@@ -840,7 +843,7 @@
httpURLConn = (HttpURLConnection) externalURL.openConnection();
// Check if proxy is being configured by system properties.
- if (SecurityUtility.getSystemProperty("http.proxyHost") != null)
+ if (getSystemProperty("http.proxyHost") != null)
{
String proxyAuth = getProxyAuth(metadata);
if (proxyAuth != null)
@@ -865,7 +868,7 @@
}
if (username == null || username.length() == 0)
{
- username = SecurityUtility.getSystemProperty("http.proxy.username");
+ username = getSystemProperty("http.proxy.username");
}
if (metadata != null)
{
@@ -873,7 +876,7 @@
}
if (password == null)
{
- password = SecurityUtility.getSystemProperty("http.proxy.password");
+ password = getSystemProperty("http.proxy.password");
}
if (username != null && password != null)
@@ -904,7 +907,7 @@
}
if (username == null || username.length() == 0)
{
- username = SecurityUtility.getSystemProperty("http.basic.username");
+ username = getSystemProperty("http.basic.username");
}
if (metadata != null)
{
@@ -912,7 +915,7 @@
}
if (password == null)
{
- password = SecurityUtility.getSystemProperty("http.basic.password");
+ password = getSystemProperty("http.basic.password");
}
if (username != null && password != null)
@@ -1129,4 +1132,149 @@
return "WaitingTaskWrapper[" + completeTimeout + "]";
}
}
+
+ static private String getSystemProperty(final String name)
+ {
+ if (SecurityUtility.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 private Method getMethod(final Class c, final String name, final Class[] parameterTypes)
+ throws NoSuchMethodException
+ {
+ if (SecurityUtility.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 private void connect(final HttpURLConnection conn) throws IOException
+ {
+ if (SecurityUtility.skipAccessControl())
+ {
+ conn.connect();
+ return;
+ }
+
+ try
+ {
+ AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws IOException
+ {
+ conn.connect();
+ return null;
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (IOException) e.getCause();
+ }
+ }
+
+ static private OutputStream getOutputStream(final HttpURLConnection conn)
+ throws IOException
+ {
+ if (SecurityUtility.skipAccessControl())
+ {
+ return conn.getOutputStream();
+ }
+
+ try
+ {
+ return (OutputStream)AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws IOException
+ {
+ return conn.getOutputStream();
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (IOException) e.getCause();
+ }
+ }
+
+ static private int getResponseCode(final HttpURLConnection conn)
+ throws IOException
+ {
+ if (SecurityUtility.skipAccessControl())
+ {
+ return conn.getResponseCode();
+ }
+
+ try
+ {
+ return ((Integer) AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws IOException
+ {
+ return new Integer(conn.getResponseCode());
+ }
+ })).intValue();
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (IOException) e.getCause();
+ }
+ }
+
+ static private String getResponseMessage(final HttpURLConnection conn)
+ throws IOException
+ {
+ if (SecurityUtility.skipAccessControl())
+ {
+ return conn.getResponseMessage();
+ }
+
+ try
+ {
+ return (String) AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws IOException
+ {
+ return conn.getResponseMessage();
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (IOException) e.getCause();
+ }
+ }
}
\ No newline at end of file
15 years, 7 months