[jboss-cvs] JBossAS SVN: r89208 - trunk/varia/src/main/org/jboss/services/binding/impl.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed May 20 14:47:28 EDT 2009


Author: anil.saldhana at jboss.com
Date: 2009-05-20 14:47:28 -0400 (Wed, 20 May 2009)
New Revision: 89208

Added:
   trunk/varia/src/main/org/jboss/services/binding/impl/SecurityActions.java
Modified:
   trunk/varia/src/main/org/jboss/services/binding/impl/Util.java
   trunk/varia/src/main/org/jboss/services/binding/impl/XSLTServiceBindingValueSourceImpl.java
Log:
JBAS-6964: priv blocks for XSLTServiceBindingValueSourceImpl

Copied: trunk/varia/src/main/org/jboss/services/binding/impl/SecurityActions.java (from rev 89205, branches/Branch_5_x/varia/src/main/org/jboss/services/binding/impl/SecurityActions.java)
===================================================================
--- trunk/varia/src/main/org/jboss/services/binding/impl/SecurityActions.java	                        (rev 0)
+++ trunk/varia/src/main/org/jboss/services/binding/impl/SecurityActions.java	2009-05-20 18:47:28 UTC (rev 89208)
@@ -0,0 +1,57 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.services.binding.impl;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+
+/**
+ *  Privileged Blocks
+ *  @author Anil.Saldhana at redhat.com
+ *  @since  Sep 10, 2007 
+ *  @version $Revision: 88886 $
+ */
+class SecurityActions
+{
+   static ClassLoader getContextClassLoader()
+   {
+      return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>()
+      {
+         public ClassLoader run()
+         { 
+            return Thread.currentThread().getContextClassLoader();
+         }
+      });
+   }
+   
+   static String getSystemProperty(final String key, final String defaultValue)
+   {
+      return AccessController.doPrivileged(new PrivilegedAction<String>()
+      {
+         public String run()
+         { 
+            return System.getProperty(key, defaultValue); 
+         }
+      });
+   }
+}
\ No newline at end of file

Modified: trunk/varia/src/main/org/jboss/services/binding/impl/Util.java
===================================================================
--- trunk/varia/src/main/org/jboss/services/binding/impl/Util.java	2009-05-20 18:16:27 UTC (rev 89207)
+++ trunk/varia/src/main/org/jboss/services/binding/impl/Util.java	2009-05-20 18:47:28 UTC (rev 89208)
@@ -140,7 +140,7 @@
    
    public static File createTempFile() throws IOException
    {
-      String tmpName = System.getProperty(ServerConfig.SERVER_TEMP_DIR);
+      String tmpName = SecurityActions.getSystemProperty(ServerConfig.SERVER_TEMP_DIR, "");
       File tempDirectory = new File(tmpName);
       File targetFile = File.createTempFile("service-binding", ".tmp", tempDirectory);
       targetFile.deleteOnExit();

Modified: trunk/varia/src/main/org/jboss/services/binding/impl/XSLTServiceBindingValueSourceImpl.java
===================================================================
--- trunk/varia/src/main/org/jboss/services/binding/impl/XSLTServiceBindingValueSourceImpl.java	2009-05-20 18:16:27 UTC (rev 89207)
+++ trunk/varia/src/main/org/jboss/services/binding/impl/XSLTServiceBindingValueSourceImpl.java	2009-05-20 18:47:28 UTC (rev 89208)
@@ -34,6 +34,8 @@
 import java.io.Writer;
 import java.net.MalformedURLException;
 import java.net.URL;
+import java.security.AccessController;
+import java.security.PrivilegedExceptionAction;
 import java.util.Map;
 
 import javax.xml.transform.Result;
@@ -64,7 +66,7 @@
 {
    private static final Logger log = Logger.getLogger(XSLTServiceBindingValueSourceImpl.class);
    
-   public String getResourceServiceBindingValue(ServiceBinding binding, String input)
+   public String getResourceServiceBindingValue(ServiceBinding binding, final String input)
    {
       if (input == null)
          throw new IllegalArgumentException("input cannot be null");
@@ -74,9 +76,15 @@
       Reader reader = null;
       try
       {
-         reader = Util.getInputStreamReader(input);
+         reader = AccessController.doPrivileged(new PrivilegedExceptionAction<Reader>()
+         {
+            public Reader run() throws IOException
+            { 
+               return Util.getInputStreamReader(input);
+            }
+         });
       }
-      catch (IOException e)
+      catch (Exception e)
       {
          throw new RuntimeException("Caught IOException during transformation", e);
       }
@@ -160,14 +168,20 @@
       File targetFile = null;
       try
       {
-         targetFile = Util.createTempFile();
+         targetFile = AccessController.doPrivileged(new PrivilegedExceptionAction<File>()
+         {
+            public File run() throws Exception
+            {
+               return Util.createTempFile();
+            }
+         });
          writer = new OutputStreamWriter(new FileOutputStream(targetFile));
          
          doXslTransform(binding, config, reader, writer);
 
          return targetFile;
       }
-      catch (IOException e)
+      catch (Exception e)
       {
          throw new RuntimeException("Caught IOException during transformation", e);
       }




More information about the jboss-cvs-commits mailing list