JBoss Remoting SVN: r5005 - remoting2/branches/2.x/src/main/org/jboss/remoting/samples/detection/jndi.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-04-14 06:16:19 -0400 (Tue, 14 Apr 2009)
New Revision: 5005
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/samples/detection/jndi/SimpleJNDIServer.java
Log:
JBREM-1116: Eliminated dependence on SecurityUtility.
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/samples/detection/jndi/SimpleJNDIServer.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/samples/detection/jndi/SimpleJNDIServer.java 2009-04-14 10:15:47 UTC (rev 5004)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/samples/detection/jndi/SimpleJNDIServer.java 2009-04-14 10:16:19 UTC (rev 5005)
@@ -5,6 +5,9 @@
import java.lang.reflect.Method;
import java.net.InetAddress;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
/**
* A JNDI server that should be run before running the simple detector client/server.
@@ -95,7 +98,7 @@
namingBeanImplClass = Class.forName("org.jnp.server.NamingBeanImpl");
namingBean = namingBeanImplClass.newInstance();
Method startMethod = namingBeanImplClass.getMethod("start", new Class[] {});
- SecurityUtility.setSystemProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
+ setSystemProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
startMethod.invoke(namingBean, new Object[] {});
}
catch (Exception e)
@@ -129,5 +132,28 @@
{
System.out.println(new java.util.Date() + ": [SERVER]: " + msg);
}
-
+
+ static private void setSystemProperty(final String name, final String value)
+ {
+ if (SecurityUtility.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();
+ }
+ }
}
15 years, 7 months
JBoss Remoting SVN: r5004 - remoting2/branches/2.x/src/main/org/jboss/remoting/network.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-04-14 06:15:47 -0400 (Tue, 14 Apr 2009)
New Revision: 5004
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/network/NetworkRegistry.java
remoting2/branches/2.x/src/main/org/jboss/remoting/network/NetworkRegistryQuery.java
Log:
JBREM-1116: Eliminated dependence on SecurityUtility.
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/network/NetworkRegistry.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/network/NetworkRegistry.java 2009-04-14 10:15:03 UTC (rev 5003)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/network/NetworkRegistry.java 2009-04-14 10:15:47 UTC (rev 5004)
@@ -22,6 +22,9 @@
package org.jboss.remoting.network;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
@@ -269,9 +272,9 @@
Identity identity = Identity.get(this.mBeanServer);
// this is a slight hack, but we have to have some way to know the main
// JBoss MBeanServer data
- SecurityUtility.setSystemProperty("jboss.remoting.jmxid", identity.getJMXId());
- SecurityUtility.setSystemProperty("jboss.remoting.instanceid", identity.getInstanceId());
- SecurityUtility.setSystemProperty("jboss.remoting.domain", identity.getDomain());
+ setSystemProperty("jboss.remoting.jmxid", identity.getJMXId());
+ setSystemProperty("jboss.remoting.instanceid", identity.getInstanceId());
+ setSystemProperty("jboss.remoting.domain", identity.getDomain());
return objectName;
}
@@ -282,7 +285,7 @@
*/
public synchronized void changeDomain(String newDomain)
{
- SecurityUtility.setSystemProperty("jboss.remoting.domain", newDomain);
+ setSystemProperty("jboss.remoting.domain", newDomain);
NetworkInstance servers[] = getServers();
if(servers == null || servers.length <= 0)
{
@@ -305,5 +308,28 @@
}
}.start();
}
-
+
+ static private void setSystemProperty(final String name, final String value)
+ {
+ if (SecurityUtility.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();
+ }
+ }
}
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/network/NetworkRegistryQuery.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/network/NetworkRegistryQuery.java 2009-04-14 10:15:03 UTC (rev 5003)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/network/NetworkRegistryQuery.java 2009-04-14 10:15:47 UTC (rev 5004)
@@ -22,6 +22,10 @@
package org.jboss.remoting.network;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+
import javax.management.BadAttributeValueExpException;
import javax.management.BadBinaryOpValueExpException;
import javax.management.BadStringOperationException;
@@ -48,7 +52,7 @@
{
try
{
- return SecurityUtility.isInstanceOf(server, objectName, NetworkRegistryMBean.class.getName());
+ return isInstanceOf(server, objectName, NetworkRegistryMBean.class.getName());
}
catch (InstanceNotFoundException e)
{
@@ -61,4 +65,28 @@
{
this.server = mBeanServer;
}
+
+ static private boolean isInstanceOf(final MBeanServer server, final ObjectName objectName, final String className)
+ throws InstanceNotFoundException
+ {
+ if (SecurityUtility.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();
+ }
+ }
}
15 years, 7 months
JBoss Remoting SVN: r5003 - remoting2/branches/2.x/src/main/org/jboss/remoting/loading.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-04-14 06:15:03 -0400 (Tue, 14 Apr 2009)
New Revision: 5003
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/loading/ClassByteClassLoader.java
remoting2/branches/2.x/src/main/org/jboss/remoting/loading/ObjectInputStreamWithClassLoader.java
Log:
JBREM-1116: Eliminated dependence on SecurityUtility.
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/loading/ClassByteClassLoader.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/loading/ClassByteClassLoader.java 2009-04-14 10:14:29 UTC (rev 5002)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/loading/ClassByteClassLoader.java 2009-04-14 10:15:03 UTC (rev 5003)
@@ -26,12 +26,19 @@
import org.jboss.remoting.util.SecurityUtility;
import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.ref.Reference;
import java.lang.ref.ReferenceQueue;
import java.lang.ref.WeakReference;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@@ -180,7 +187,7 @@
{
return cl;
}
- cl = Class.forName(className, false, SecurityUtility.getSystemClassLoader());
+ cl = Class.forName(className, false, getSystemClassLoaderPrivate());
if(cl != null)
{
return cl;
@@ -208,12 +215,12 @@
File file = null;
try
{
- file = SecurityUtility.createTempFile("cbc", ".class", true);
+ file = createTempFile("cbc", ".class", true);
if(log.isTraceEnabled())
{
log.trace("adding resource at: " + name + " to file: " + file);
}
- out = SecurityUtility.getFileOutputStream(file);
+ out = getFileOutputStream(file);
out.write(buf);
out.flush();
}
@@ -253,11 +260,11 @@
{
log.trace("getResourceAsStream =>" + denormalized + " = " + file);
}
- if(file != null && SecurityUtility.fileExists(file))
+ if(file != null && fileExists(file))
{
try
{
- InputStream is = SecurityUtility.getFileInputStream(file);
+ InputStream is = getFileInputStream(file);
return new java.io.BufferedInputStream(is);
}
catch(Exception ex)
@@ -424,4 +431,113 @@
return loadedClass;
}
+
+ static private File createTempFile(final String prefix, final String suffix, final boolean deleteOnExit) throws IOException
+ {
+ if (SecurityUtility.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 private boolean fileExists(final File file)
+ {
+ if (file == null)
+ return false;
+
+ if (SecurityUtility.skipAccessControl())
+ {
+ return file.exists();
+ }
+
+ return ((Boolean)AccessController.doPrivileged( new PrivilegedAction()
+ {
+ public Object run()
+ {
+ return new Boolean(file.exists());
+ }
+ })).booleanValue();
+ }
+
+ static private FileInputStream getFileInputStream(final File file) throws FileNotFoundException
+ {
+ if (SecurityUtility.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 private FileOutputStream getFileOutputStream(final File file)
+ throws FileNotFoundException
+ {
+ if (SecurityUtility.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 private ClassLoader getSystemClassLoaderPrivate()
+ {
+ if (SecurityUtility.skipAccessControl())
+ {
+ return ClassLoader.getSystemClassLoader();
+ }
+
+ return (ClassLoader)AccessController.doPrivileged( new PrivilegedAction()
+ {
+ public Object run()
+ {
+ return ClassLoader.getSystemClassLoader();
+ }
+ });
+ }
}
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/loading/ObjectInputStreamWithClassLoader.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/loading/ObjectInputStreamWithClassLoader.java 2009-04-14 10:14:29 UTC (rev 5002)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/loading/ObjectInputStreamWithClassLoader.java 2009-04-14 10:15:03 UTC (rev 5003)
@@ -26,6 +26,9 @@
import java.io.ObjectInputStream;
import java.io.StreamCorruptedException;
import java.lang.reflect.Method;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
import java.util.HashMap;
import org.jboss.logging.Logger;
@@ -52,7 +55,7 @@
{
try
{
- clearMethod = SecurityUtility.getDeclaredMethod(ObjectInputStream.class, "clear", new Class[]{});
+ clearMethod = getDeclaredMethod(ObjectInputStream.class, "clear", new Class[]{});
} catch (SecurityException e) {
log.error(e.getMessage(), e);
@@ -259,4 +262,32 @@
}
}
}
+
+ static private Method getDeclaredMethod(final Class c, final String name, final Class[] parameterTypes)
+ throws NoSuchMethodException
+ {
+ if (SecurityUtility.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();
+ }
+ }
}
\ No newline at end of file
15 years, 7 months
JBoss Remoting SVN: r5002 - remoting2/branches/2.x/src/main/org/jboss/remoting/ident.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-04-14 06:14:29 -0400 (Tue, 14 Apr 2009)
New Revision: 5002
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/ident/Identity.java
Log:
JBREM-1116: Eliminated dependence on SecurityUtility.
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/ident/Identity.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/ident/Identity.java 2009-04-14 10:13:51 UTC (rev 5001)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/ident/Identity.java 2009-04-14 10:14:29 UTC (rev 5002)
@@ -28,12 +28,14 @@
import javax.management.ObjectName;
import java.io.File;
import java.io.FileInputStream;
+import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Serializable;
import java.net.InetAddress;
+import java.net.UnknownHostException;
import java.rmi.dgc.VMID;
import java.security.AccessController;
import java.security.PrivilegedAction;
@@ -60,7 +62,7 @@
static
{
- _domain = SecurityUtility.getSystemProperty("jboss.identity.domain", DEFAULT_DOMAIN);
+ _domain = getSystemProperty("jboss.identity.domain", DEFAULT_DOMAIN);
}
private static transient Map identities = new WeakHashMap(2);
@@ -100,7 +102,7 @@
}
ident.calcHashCode();
}
- SecurityUtility.setSystemProperty("jboss.identity.domain", domain);
+ setSystemProperty("jboss.identity.domain", domain);
_domain = domain;
NetworkRegistry.getInstance().changeDomain(domain);
}
@@ -213,9 +215,9 @@
}
try
{
- InetAddress localHost = SecurityUtility.getLocalHost();
+ InetAddress localHost = getLocalHost();
ObjectName objectName = new ObjectName("JMImplementation:type=MBeanServerDelegate");
- String serverid = (String) SecurityUtility.getMBeanAttribute(server, objectName, "MBeanServerId");
+ String serverid = (String) getMBeanAttribute(server, objectName, "MBeanServerId");
Identity identity = new Identity(localHost, createId(server), serverid);
identities.put(server, identity);
return identity;
@@ -232,7 +234,7 @@
private static final synchronized String createId(final MBeanServer server)
{
// we can set as a system property
- String myid = SecurityUtility.getSystemProperty("jboss.identity");
+ String myid = getSystemProperty("jboss.identity");
if(myid != null)
{
return myid;
@@ -243,12 +245,12 @@
{
// FIRST TRY THE JBOSS guy to determine our data directory
final ObjectName obj = new ObjectName("jboss.system:type=ServerConfig");
- File dir = (File) SecurityUtility.getMBeanAttribute(server, obj, "ServerDataDir");
+ File dir = (File) getMBeanAttribute(server, obj, "ServerDataDir");
if(dir != null)
{
- if(SecurityUtility.fileExists(dir) == false)
+ if(fileExists(dir) == false)
{
- SecurityUtility.mkdirs(dir);
+ mkdirs(dir);
}
file = new File(dir, "jboss.identity");
}
@@ -259,23 +261,23 @@
if(file == null)
{
// we may not have that mbean, which is OK
- String fl = SecurityUtility.getSystemProperty("jboss.identity.dir", ".");
+ String fl = getSystemProperty("jboss.identity.dir", ".");
File dir = new File(fl);
- if(SecurityUtility.fileExists(dir) == false)
+ if(fileExists(dir) == false)
{
- SecurityUtility.mkdirs(dir);
+ mkdirs(dir);
}
file = new File(dir, "jboss.identity");
}
- boolean canRead = SecurityUtility.canRead(file);
- if(SecurityUtility.fileExists(file) && canRead)
+ boolean canRead = canRead(file);
+ if(fileExists(file) && canRead)
{
InputStream is = null;
try
{
- is = SecurityUtility.getFileInputStream(file);
+ is = getFileInputStream(file);
byte buf[] = new byte[800];
int c = is.read(buf);
id = new String(buf, 0, c);
@@ -304,12 +306,12 @@
try
{
id = createUniqueID();
- if(SecurityUtility.fileExists(file) == false)
+ if(fileExists(file) == false)
{
- SecurityUtility.createNewFile(file);
+ createNewFile(file);
}
- out = SecurityUtility.getFileOutputStream(file);
+ out = getFileOutputStream(file);
out.write(id.getBytes());
}
catch(Exception ex)
@@ -332,7 +334,7 @@
}
}
- SecurityUtility.setSystemProperty("jboss.identity", id);
+ setSystemProperty("jboss.identity", id);
return id;
}
@@ -343,4 +345,258 @@
// colons don't work in JMX
return id.replace(':', 'x') + random.nextInt(1000);
}
+
+ static private boolean fileExists(final File file)
+ {
+ if (file == null)
+ return false;
+
+ if (SecurityUtility.skipAccessControl())
+ {
+ return file.exists();
+ }
+
+ return ((Boolean)AccessController.doPrivileged( new PrivilegedAction()
+ {
+ public Object run()
+ {
+ return new Boolean(file.exists());
+ }
+ })).booleanValue();
+ }
+
+ static private boolean mkdirs(final File dir)
+ {
+ if (SecurityUtility.skipAccessControl())
+ {
+ return dir.mkdirs();
+ }
+
+ return ((Boolean) AccessController.doPrivileged( new PrivilegedAction()
+ {
+ public Object run()
+ {
+ return new Boolean(dir.mkdirs());
+ }
+ })).booleanValue();
+ }
+
+ static private FileInputStream getFileInputStream(final File file) throws FileNotFoundException
+ {
+ if (SecurityUtility.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 private FileOutputStream getFileOutputStream(final File file)
+ throws FileNotFoundException
+ {
+ if (SecurityUtility.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 private boolean canRead(final File file)
+ {
+ if (SecurityUtility.skipAccessControl())
+ {
+ return file.canRead();
+ }
+
+ return ((Boolean)AccessController.doPrivileged( new PrivilegedAction()
+ {
+ public Object run()
+ {
+ return new Boolean(file.canRead());
+ }
+ })).booleanValue();
+ }
+
+ static private boolean createNewFile(final File file) throws IOException
+ {
+ if (SecurityUtility.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();
+ }
+ }
+
+ static private Object getMBeanAttribute(final MBeanServer server, final ObjectName objectName, final String attribute)
+ throws Exception
+ {
+ if (SecurityUtility.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 private String getSystemProperty(final String name, final String defaultValue)
+ {
+ if (SecurityUtility.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 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 void setSystemProperty(final String name, final String value)
+ {
+ if (SecurityUtility.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();
+ }
+ }
+
+ static private InetAddress getLocalHost() throws UnknownHostException
+ {
+ if (SecurityUtility.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();
+ }
+ }
}
15 years, 7 months
JBoss Remoting SVN: r5001 - remoting2/branches/2.x/src/main/org/jboss/remoting/detection/util.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-04-14 06:13:51 -0400 (Tue, 14 Apr 2009)
New Revision: 5001
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/detection/util/DetectorUtil.java
Log:
JBREM-1116: Eliminated dependence on SecurityUtility.
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/detection/util/DetectorUtil.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/detection/util/DetectorUtil.java 2009-04-14 10:13:24 UTC (rev 5000)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/detection/util/DetectorUtil.java 2009-04-14 10:13:51 UTC (rev 5001)
@@ -21,7 +21,12 @@
*/
package org.jboss.remoting.detection.util;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+
import javax.management.MBeanServer;
+import javax.management.MBeanServerFactory;
import javax.management.ObjectName;
import org.apache.log4j.Level;
import org.jboss.logging.Logger;
@@ -99,11 +104,11 @@
org.apache.log4j.Category.getRoot().setLevel(Level.DEBUG);
Logger log = Logger.getLogger(getClass());
- SecurityUtility.setSystemProperty("jboss.identity", String.valueOf(System.currentTimeMillis()));
+ setSystemProperty("jboss.identity", String.valueOf(System.currentTimeMillis()));
- MBeanServer server = SecurityUtility.createMBeanServer();
+ MBeanServer server = createMBeanServer();
NetworkRegistry registry = NetworkRegistry.getInstance();
- SecurityUtility.registerMBean(server, registry, new ObjectName("remoting:type=NetworkRegistry"));
+ registerMBean(server, registry, new ObjectName("remoting:type=NetworkRegistry"));
InvokerLocator locator = new InvokerLocator("socket://localhost");
//ClassLoader clsLoader = Thread.currentThread().getContextClassLoader();
@@ -115,7 +120,7 @@
Connector connector = new Connector();
connector.setInvokerLocator(locator.getLocatorURI());
ObjectName obj = new ObjectName("jboss.remoting:type=Connector,transport=" + locator.getProtocol());
- SecurityUtility.registerMBean(server, connector, obj);
+ registerMBean(server, connector, obj);
//connector.create();
connector.start();
@@ -140,7 +145,7 @@
objName = new ObjectName("remoting:type=Detector,transport=jndi");
}
- SecurityUtility.registerMBean(server, detector, objName);
+ registerMBean(server, detector, objName);
detector.start();
System.err.println("Starting Detector");
@@ -214,5 +219,76 @@
return type;
}
-
+ 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();
+ }
+ }
+
+ 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();
+ }
+ }
+
+ static private void setSystemProperty(final String name, final String value)
+ {
+ if (SecurityUtility.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();
+ }
+ }
}
15 years, 7 months
JBoss Remoting SVN: r5000 - remoting2/branches/2.x/src/main/org/jboss/remoting/detection/multicast.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-04-14 06:13:24 -0400 (Tue, 14 Apr 2009)
New Revision: 5000
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/detection/multicast/MulticastDetector.java
Log:
JBREM-1116: Eliminated dependence on SecurityUtility.
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/detection/multicast/MulticastDetector.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/detection/multicast/MulticastDetector.java 2009-04-14 10:13:00 UTC (rev 4999)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/detection/multicast/MulticastDetector.java 2009-04-14 10:13:24 UTC (rev 5000)
@@ -35,6 +35,7 @@
import java.net.InetSocketAddress;
import java.net.MulticastSocket;
import java.net.SocketAddress;
+import java.net.UnknownHostException;
import java.security.AccessController;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
@@ -158,11 +159,11 @@
{
if(addr == null)
{
- addr = SecurityUtility.getAddressByName(defaultIP);
+ addr = getAddressByName(defaultIP);
}
// check to see if we're running on a machine with loopback and no NIC
- InetAddress localHost = SecurityUtility.getLocalHost();
+ InetAddress localHost = getLocalHost();
if(bindAddr == null && localHost.getHostAddress().equals("127.0.0.1"))
{
// use this to bind so multicast will work w/o network
@@ -370,4 +371,64 @@
}
}
}
+
+ static private InetAddress getLocalHost() throws UnknownHostException
+ {
+ if (SecurityUtility.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 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();
+ }
+ }
}
15 years, 7 months
JBoss Remoting SVN: r4999 - remoting2/branches/2.x/src/main/org/jboss/remoting/detection/jndi.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-04-14 06:13:00 -0400 (Tue, 14 Apr 2009)
New Revision: 4999
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/detection/jndi/JNDIDetector.java
Log:
JBREM-1116: Eliminated dependence on SecurityUtility.
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/detection/jndi/JNDIDetector.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/detection/jndi/JNDIDetector.java 2009-04-14 10:12:27 UTC (rev 4998)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/detection/jndi/JNDIDetector.java 2009-04-14 10:13:00 UTC (rev 4999)
@@ -39,9 +39,14 @@
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
+import java.io.IOException;
import java.lang.reflect.Method;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
import java.security.AccessController;
import java.security.PrivilegedAction;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
import java.util.Map;
import java.util.Properties;
@@ -277,7 +282,7 @@
cleanDetectionCount++;
boolean cleanDetect = cleanDetectionCount > detectionNumber;
String bindName = "";
- NamingEnumeration enumeration = SecurityUtility.listBindings(context, bindName);
+ NamingEnumeration enumeration = listBindings(context, bindName);
while(enumeration.hasMore())
{
Binding binding = (Binding) enumeration.next();
@@ -414,7 +419,7 @@
{
try
{
- SecurityUtility.rebind(context, sId, msg);
+ rebind(context, sId, msg);
log.info("Added " + sId + " to registry.");
}
catch(NameAlreadyBoundException nabex)
@@ -447,7 +452,7 @@
namingBeanImplClass = Class.forName("org.jnp.server.NamingBeanImpl");
namingBean = namingBeanImplClass.newInstance();
Method startMethod = namingBeanImplClass.getMethod("start", new Class[] {});
- SecurityUtility.setSystemProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
+ setSystemProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
startMethod.invoke(namingBean, new Object[] {});
}
catch (Exception e)
@@ -455,7 +460,7 @@
log.debug("Cannot find NamingBeanImpl: must be running jdk 1.4");
}
- host = SecurityUtility.getLocalHostName();
+ host = getLocalHostName();
port = PortUtil.findFreePort(host);
log.info("Remoting JNDI detector starting JNDI server instance since none where specified via configuration.");
@@ -502,18 +507,18 @@
InitialContext initialContext = new InitialContext(env);
try
{
- context = SecurityUtility.initialContextLookup(initialContext, subContextName);
+ context = initialContextLookup(initialContext, subContextName);
}
catch(NamingException e)
{
try
{
- context = SecurityUtility.createSubcontext(initialContext, subContextName);
+ context = createSubcontext(initialContext, subContextName);
}
catch(NameAlreadyBoundException e1)
{
log.debug("The sub context " + subContextName + " was created before we could.");
- context = SecurityUtility.initialContextLookup(initialContext, subContextName);
+ context = initialContextLookup(initialContext, subContextName);
}
}
}
@@ -545,6 +550,224 @@
{
log.trace("unregistering detector " + sId);
}
- SecurityUtility.unbind(context, sId);
+ unbind(context, sId);
}
+
+ static private void setSystemProperty(final String name, final String value)
+ {
+ if (SecurityUtility.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();
+ }
+ }
+
+ static private InetAddress getLocalHost() throws UnknownHostException
+ {
+ if (SecurityUtility.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 private String getLocalHostName() throws UnknownHostException
+ {
+ if (SecurityUtility.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 private Context createSubcontext(final InitialContext initialContext, final String subContextName)
+ throws NamingException
+ {
+ if (SecurityUtility.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 private Context initialContextLookup(final InitialContext initialContext, final String subContextName)
+ throws NamingException
+ {
+ if (SecurityUtility.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 private NamingEnumeration listBindings(final Context context, final String bindName)
+ throws NamingException
+ {
+ if (SecurityUtility.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 private void rebind(final Context context, final String name, final Object object)
+ throws NamingException
+ {
+ if (SecurityUtility.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 private void unbind(final Context context, final String name)
+ throws NamingException
+ {
+ if (SecurityUtility.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();
+ }
+ }
}
15 years, 7 months
JBoss Remoting SVN: r4998 - remoting2/branches/2.x/src/main/org/jboss/remoting/callback.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-04-14 06:12:27 -0400 (Tue, 14 Apr 2009)
New Revision: 4998
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/callback/CallbackStore.java
remoting2/branches/2.x/src/main/org/jboss/remoting/callback/ServerInvokerCallbackHandler.java
Log:
JBREM-1116: Eliminated dependence on SecurityUtility.
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/callback/CallbackStore.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/callback/CallbackStore.java 2009-04-14 10:11:33 UTC (rev 4997)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/callback/CallbackStore.java 2009-04-14 10:12:27 UTC (rev 4998)
@@ -123,7 +123,7 @@
{
try
{
- filePath = SecurityUtility.getSystemProperty("jboss.server.data.dir", "data");
+ filePath = getSystemProperty("jboss.server.data.dir", "data");
}
catch (Exception e)
{
@@ -134,7 +134,7 @@
File storeFile = new File(filePath);
if (!storeFile.exists())
{
- boolean madeDir = SecurityUtility.mkdirs(storeFile);
+ boolean madeDir = mkdirs(storeFile);
if (!madeDir)
{
throw new IOException("Can not create directory for store. Path given: " + filePath);
@@ -202,7 +202,7 @@
{
try
{
- String separator = SecurityUtility.getSystemProperty("file.separator");
+ String separator = getSystemProperty("file.separator");
fileToDelete = filePath + separator + fileList[x];
final File currentFile = new File(fileToDelete);
@@ -352,9 +352,9 @@
{
// only getting the first one, which will be first one entered since the getting
// of the list is automatically ordered by the OS and all file names are numeric by time.
- String separator = SecurityUtility.getSystemProperty("file.separator");
+ String separator = getSystemProperty("file.separator");
objectFilePath = filePath + separator + objectFileList[0];
- inFile = SecurityUtility.getFileInputStream(objectFilePath);
+ inFile = getFileInputStream(objectFilePath);
in = SerializationStreamFactory.getManagerInstance(serializationType).createRegularInput(inFile);
try
@@ -456,7 +456,7 @@
}
StringBuffer path = new StringBuffer(filePath);
- String separator = SecurityUtility.getSystemProperty("file.separator");
+ String separator = getSystemProperty("file.separator");
path.append(separator).append(String.valueOf(currentTimestamp));
path.append("-").append(timestampCounter).append(".").append(fileSuffix);
final File storeFile = new File(path.toString());
@@ -465,7 +465,7 @@
try
{
- outFile = SecurityUtility.getFileOutputStream(storeFile, false);
+ outFile = getFileOutputStream(storeFile, false);
if (serializationType.indexOf("jboss") > 0)
{
out = SerializationStreamFactory.getManagerInstance(serializationType).createOutput(outFile);
@@ -545,5 +545,115 @@
}
}
}
-
+
+ static private boolean mkdirs(final File dir)
+ {
+ if (SecurityUtility.skipAccessControl())
+ {
+ return dir.mkdirs();
+ }
+
+ return ((Boolean) AccessController.doPrivileged( new PrivilegedAction()
+ {
+ public Object run()
+ {
+ return new Boolean(dir.mkdirs());
+ }
+ })).booleanValue();
+ }
+
+ static private FileInputStream getFileInputStream(final String path) throws FileNotFoundException
+ {
+ if (SecurityUtility.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 private FileOutputStream getFileOutputStream(final File file, final boolean append)
+ throws FileNotFoundException
+ {
+ if (SecurityUtility.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 private String getSystemProperty(final String name, final String defaultValue)
+ {
+ if (SecurityUtility.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 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;
+ }
}
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/callback/ServerInvokerCallbackHandler.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/callback/ServerInvokerCallbackHandler.java 2009-04-14 10:11:33 UTC (rev 4997)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/callback/ServerInvokerCallbackHandler.java 2009-04-14 10:12:27 UTC (rev 4998)
@@ -36,6 +36,7 @@
import org.jboss.remoting.security.SSLSocketFactoryService;
import org.jboss.remoting.util.SecurityUtility;
+import javax.management.InstanceNotFoundException;
import javax.management.MBeanServer;
import javax.management.MBeanServerInvocationHandler;
import javax.management.MalformedObjectNameException;
@@ -295,10 +296,10 @@
if (server != null)
{
String className = SSLServerSocketFactoryServiceMBean.class.getName();
- boolean isCorrectType = SecurityUtility.isInstanceOf(server, serverSocketFactoryObjName, className);
+ boolean isCorrectType = isInstanceOf(server, serverSocketFactoryObjName, className);
if (isCorrectType)
{
- Object o = SecurityUtility.getMBeanAttribute(server, serverSocketFactoryObjName, "SSLSocketBuilder");
+ Object o = getMBeanAttribute(server, serverSocketFactoryObjName, "SSLSocketBuilder");
SSLSocketBuilderMBean sslSocketBuilder = (SSLSocketBuilderMBean) o;
if (sslSocketBuilder != null)
@@ -428,10 +429,10 @@
String filePath = (String) storeConfig.get(CallbackStore.FILE_PATH_KEY);
if(filePath == null)
{
- filePath = SecurityUtility.getSystemProperty("jboss.server.data.dir", "data");
+ filePath = getSystemProperty("jboss.server.data.dir", "data");
}
- String separator = SecurityUtility.getSystemProperty("file.separator");
+ String separator = getSystemProperty("file.separator");
String newFilePath = filePath + separator + "remoting" + separator + sessionId;
storeConfig.put(CallbackStore.FILE_PATH_KEY, newFilePath);
callbackStore.setConfig(storeConfig);
@@ -1051,4 +1052,100 @@
{
this.shouldPersist = shouldPersist;
}
+
+ static private Object getMBeanAttribute(final MBeanServer server, final ObjectName objectName, final String attribute)
+ throws Exception
+ {
+ if (SecurityUtility.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 private boolean isInstanceOf(final MBeanServer server, final ObjectName objectName, final String className)
+ throws InstanceNotFoundException
+ {
+ if (SecurityUtility.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 private String getSystemProperty(final String name, final String defaultValue)
+ {
+ if (SecurityUtility.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 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;
+ }
}
15 years, 7 months
JBoss Remoting SVN: r4997 - remoting2/branches/2.x/src/main/org/jboss/remoting.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-04-14 06:11:33 -0400 (Tue, 14 Apr 2009)
New Revision: 4997
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/Version.java
Log:
JBREM-1116: Eliminated dependence on SecurityUtility.
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/Version.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/Version.java 2009-04-14 10:11:02 UTC (rev 4996)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/Version.java 2009-04-14 10:11:33 UTC (rev 4997)
@@ -22,6 +22,10 @@
package org.jboss.remoting;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+
import org.jboss.remoting.util.SecurityUtility;
/**
@@ -50,7 +54,7 @@
static
{
boolean precompatibleFlag = false;
- String precompatible = SecurityUtility.getSystemProperty(PRE_2_0_COMPATIBLE);
+ String precompatible = getSystemProperty(PRE_2_0_COMPATIBLE);
if(precompatible != null && precompatible.length() > 0)
{
@@ -64,7 +68,7 @@
}
else
{
- String userDefinedVersion = SecurityUtility.getSystemProperty(REMOTING_VERSION_TO_USE);
+ String userDefinedVersion = getSystemProperty(REMOTING_VERSION_TO_USE);
if(userDefinedVersion != null && userDefinedVersion.length() > 0)
{
@@ -85,7 +89,7 @@
}
else
{
- SecurityUtility.setSystemProperty(REMOTING_VERSION_TO_USE, new Byte(defaultByteVersion).toString());
+ setSystemProperty(REMOTING_VERSION_TO_USE, new Byte(defaultByteVersion).toString());
}
}
}
@@ -114,4 +118,52 @@
{
return version == VERSION_1 || version == VERSION_2 || version == VERSION_2_2;
}
+
+ 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 void setSystemProperty(final String name, final String value)
+ {
+ if (SecurityUtility.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();
+ }
+ }
}
\ No newline at end of file
15 years, 7 months
JBoss Remoting SVN: r4996 - remoting2/branches/2.x/src/main/org/jboss/remoting.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-04-14 06:11:02 -0400 (Tue, 14 Apr 2009)
New Revision: 4996
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/ServerInvoker.java
Log:
JBREM-1116: Eliminated dependence on SecurityUtility.
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/ServerInvoker.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/ServerInvoker.java 2009-04-14 10:10:28 UTC (rev 4995)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/ServerInvoker.java 2009-04-14 10:11:02 UTC (rev 4996)
@@ -55,6 +55,10 @@
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
@@ -1188,11 +1192,11 @@
InetAddress addr = null;
if(locatorhost != null)
{
- addr = SecurityUtility.getAddressByName(locatorhost);
+ addr = getAddressByName(locatorhost);
}
else
{
- addr = SecurityUtility.getLocalHost();
+ addr = getLocalHost();
}
int port = locator.getPort();
@@ -1209,7 +1213,7 @@
if(clientConnectAddress != null)
{
// can't use uri address, as is for client only
- serverBindAddress = SecurityUtility.getLocalHost().getHostAddress();
+ serverBindAddress = getLocalHost().getHostAddress();
}
else
{
@@ -2124,5 +2128,64 @@
return handleObject;
}
}
+
+ static private InetAddress getLocalHost() throws UnknownHostException
+ {
+ if (SecurityUtility.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 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();
+ }
+ }
}
15 years, 7 months