[jboss-remoting-commits] JBoss Remoting SVN: r3939 - remoting2/branches/2.x/src/main/org/jboss/remoting/ident.

jboss-remoting-commits at lists.jboss.org jboss-remoting-commits at lists.jboss.org
Fri Apr 11 21:01:10 EDT 2008


Author: ron.sigal at jboss.com
Date: 2008-04-11 21:01:10 -0400 (Fri, 11 Apr 2008)
New Revision: 3939

Modified:
   remoting2/branches/2.x/src/main/org/jboss/remoting/ident/Identity.java
Log:
JBREM-934: (1) Replaced AccessController.doPrivileged() calls with SecurityUtility calls; (2) renamed SystemUtility 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	2008-04-12 01:00:20 UTC (rev 3938)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/ident/Identity.java	2008-04-12 01:01:10 UTC (rev 3939)
@@ -22,7 +22,7 @@
 package org.jboss.remoting.ident;
 
 import org.jboss.remoting.network.NetworkRegistry;
-import org.jboss.remoting.util.SystemUtility;
+import org.jboss.remoting.util.SecurityUtility;
 
 import javax.management.MBeanServer;
 import javax.management.ObjectName;
@@ -60,20 +60,7 @@
    
    static
    {
-      try
-      {
-         _domain = (String)AccessController.doPrivileged( new PrivilegedExceptionAction()
-         {
-            public Object run() throws Exception
-            {
-               return System.getProperty("jboss.identity.domain", DEFAULT_DOMAIN);
-            }
-         });
-      }
-      catch (Exception e)
-      {
-         e.printStackTrace();
-      }
+      _domain = SecurityUtility.getSystemProperty("jboss.identity.domain", DEFAULT_DOMAIN);
    }
    
    private static transient Map identities = new WeakHashMap(2);
@@ -113,7 +100,7 @@
          }
          ident.calcHashCode();
       }
-      SystemUtility.setSystemProperty("jboss.identity.domain", domain);
+      SecurityUtility.setSystemProperty("jboss.identity.domain", domain);
       _domain = domain;
       NetworkRegistry.getInstance().changeDomain(domain);
    }
@@ -226,45 +213,9 @@
       }
       try
       {
-         InetAddress localHost = null;
-         try
-         {
-            localHost = (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 (IOException) e.getCause();
-         }
-         
-         String serverid = null;
-         try
-         {
-            serverid = (String)AccessController.doPrivileged( new PrivilegedExceptionAction()
-            {
-               public Object run() throws Exception
-               {
-                  return server.getAttribute(new ObjectName("JMImplementation:type=MBeanServerDelegate"), "MBeanServerId");
-               }
-            });
-         }
-         catch (PrivilegedActionException e)
-         {
-            throw (Exception) e.getCause();
-         }
-
+         InetAddress localHost = SecurityUtility.getLocalHost();
+         ObjectName objectName = new ObjectName("JMImplementation:type=MBeanServerDelegate");
+         String serverid = (String) SecurityUtility.getMBeanAttribute(server, objectName, "MBeanServerId");
          Identity identity = new Identity(localHost, createId(server), serverid);
          identities.put(server, identity);
          return identity;
@@ -281,7 +232,7 @@
    private static final synchronized String createId(final MBeanServer server)
    {
       // we can set as a system property
-      String myid = SystemUtility.getSystemProperty("jboss.identity");
+      String myid = SecurityUtility.getSystemProperty("jboss.identity");
       if(myid != null)
       {
          return myid;
@@ -292,28 +243,12 @@
       {
          // FIRST TRY THE JBOSS guy to determine our data directory
          final ObjectName obj = new ObjectName("jboss.system:type=ServerConfig");
-         File dir = null;
-         
-         try
-         {
-            dir = (File)AccessController.doPrivileged( new PrivilegedExceptionAction()
-            {
-               public Object run() throws Exception
-               {
-                  return server.getAttribute(obj, "ServerDataDir");
-               }
-            });
-         }
-         catch (PrivilegedActionException e)
-         {
-             throw (Exception) e.getCause();
-         }
-         
+         File dir = (File) SecurityUtility.getMBeanAttribute(server, obj, "ServerDataDir");
          if(dir != null)
          {
-            if(fileExists(dir) == false)
+            if(SecurityUtility.fileExists(dir) == false)
             {
-               SystemUtility.mkdirs(dir);
+               SecurityUtility.mkdirs(dir);
             }
             file = new File(dir, "jboss.identity");
          }
@@ -324,60 +259,23 @@
       if(file == null)
       {
          // we may not have that mbean, which is OK
-         String fl = ".";
-         try
-         {
-            fl = (String)AccessController.doPrivileged( new PrivilegedExceptionAction()
-            {
-               public Object run() throws Exception
-               {
-                  return System.getProperty("jboss.identity.dir", ".");
-               }
-            });
-         }
-         catch (Exception e)
-         {
-            e.printStackTrace();
-         }
+         String fl = SecurityUtility.getSystemProperty("jboss.identity.dir", ".");
          
-         final File dir = new File(fl);
-         if(fileExists(dir) == false)
+         File dir = new File(fl);
+         if(SecurityUtility.fileExists(dir) == false)
          {
-            SystemUtility.mkdirs(dir);
+            SecurityUtility.mkdirs(dir);
          }
          file = new File(dir, "jboss.identity");
       }
 
-      final File finalFile = file;
-      boolean canRead = ((Boolean)AccessController.doPrivileged( new PrivilegedAction()
+      boolean canRead = SecurityUtility.canRead(file);
+      if(SecurityUtility.fileExists(file) && canRead)
       {
-         public Object run()
-         {
-            return new Boolean(finalFile.canRead());
-         }
-      })).booleanValue();
-
-      
-      if(fileExists(file) && canRead)
-      {
          InputStream is = null;
          try
          {
-            try
-            {
-               is = (FileInputStream) AccessController.doPrivileged( new PrivilegedExceptionAction()
-               {
-                  public Object run() throws Exception
-                  {
-                     return new FileInputStream(finalFile);
-                  }
-               });
-            }
-            catch (Exception e)
-            {
-               throw (Exception) e.getCause();
-            }
-            
+            is = SecurityUtility.getFileInputStream(file);
             byte buf[] = new byte[800];
             int c = is.read(buf);
             id = new String(buf, 0, c);
@@ -406,39 +304,12 @@
          try
          {
             id = createUniqueID();
-            if(fileExists(file) == false)
+            if(SecurityUtility.fileExists(file) == false)
             {
-               try
-               {
-                  AccessController.doPrivileged( new PrivilegedExceptionAction()
-                  {
-                     public Object run() throws Exception
-                     {
-                        finalFile.createNewFile();
-                        return null;
-                     }
-                  });
-               }
-               catch (Exception e)
-               {
-                  throw (Exception) e.getCause();
-               }
+               SecurityUtility.createNewFile(file);
             }
 
-            try
-            {
-               out = (FileOutputStream) AccessController.doPrivileged( new PrivilegedExceptionAction()
-               {
-                  public Object run() throws Exception
-                  {
-                     return new FileOutputStream(finalFile);
-                  }
-               });
-            }
-            catch (Exception e)
-            {
-               throw (Exception) e.getCause();
-            }
+            out = SecurityUtility.getFileOutputStream(file);
             out.write(id.getBytes());
          }
          catch(Exception ex)
@@ -461,7 +332,7 @@
          }
       }
       
-      SystemUtility.setSystemProperty("jboss.identity", id);
+      SecurityUtility.setSystemProperty("jboss.identity", id);
       
       return id;
    }
@@ -472,22 +343,4 @@
       // colons don't work in JMX
       return id.replace(':', 'x') + random.nextInt(1000);
    }
-   
-   private static boolean fileExists(final File file)
-   {
-      try
-      {
-         return ((Boolean)AccessController.doPrivileged( new PrivilegedExceptionAction()
-         {
-            public Object run() throws Exception
-            {
-               return new Boolean(file.exists());
-            }
-         })).booleanValue();
-      }
-      catch (Exception e)
-      {
-         return false;
-      }
-   }
 }




More information about the jboss-remoting-commits mailing list