tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r933007 - in /tomcat/trunk/java: javax/el/ExpressionFactory.java org/apache/el/parser/AstValue.java
Date Sun, 11 Apr 2010 22:43:09 GMT
Author: markt
Date: Sun Apr 11 22:43:09 2010
New Revision: 933007

URL: http://svn.apache.org/viewvc?rev=933007&view=rev
Log:
TCK failures: EL TCK with security manager

Modified:
    tomcat/trunk/java/javax/el/ExpressionFactory.java
    tomcat/trunk/java/org/apache/el/parser/AstValue.java

Modified: tomcat/trunk/java/javax/el/ExpressionFactory.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/javax/el/ExpressionFactory.java?rev=933007&r1=933006&r2=933007&view=diff
==============================================================================
--- tomcat/trunk/java/javax/el/ExpressionFactory.java (original)
+++ tomcat/trunk/java/javax/el/ExpressionFactory.java Sun Apr 11 22:43:09 2010
@@ -27,6 +27,8 @@ import java.io.InputStreamReader;
 import java.io.UnsupportedEncodingException;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationTargetException;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
 import java.util.Properties;
 
 /**
@@ -34,15 +36,46 @@ import java.util.Properties;
  * @since 2.1
  */
 public abstract class ExpressionFactory {
+    
+    private static final boolean IS_SECURITY_ENABLED =
+        (System.getSecurityManager() != null);
 
     private static final String SERVICE_RESOURCE_NAME =
         "META-INF/services/javax.el.ExpressionFactory";
 
-    private static final String SEP = System.getProperty("file.separator");
-    private static final String PROPERTY_FILE =
-        System.getProperty("java.home") + "lib" + SEP + "el.properties";
     private static final String PROPERTY_NAME = "javax.el.ExpressionFactory";
 
+    private static final String SEP;
+    private static final String PROPERTY_FILE;
+
+    static {
+        if (IS_SECURITY_ENABLED) {
+            SEP = AccessController.doPrivileged(
+                    new PrivilegedAction<String>(){
+                        @Override
+                        public String run() {
+                            return System.getProperty("file.separator");
+                        }
+
+                    }
+            );
+            PROPERTY_FILE = AccessController.doPrivileged(
+                    new PrivilegedAction<String>(){
+                        @Override
+                        public String run() {
+                            return System.getProperty("java.home") + "lib" +
+                                    SEP + "el.properties";
+                        }
+
+                    }
+            );
+        } else {
+            SEP = System.getProperty("file.separator");
+            PROPERTY_FILE = System.getProperty("java.home") + "lib" + SEP +
+                    "el.properties";
+        }
+    }
+
     public abstract Object coerceToType(Object obj, Class<?> expectedType)
             throws ELException;
 
@@ -90,12 +123,34 @@ public abstract class ExpressionFactory 
         // First services API
         className = getClassNameServices(tccl);
         if (className == null) {
-            // Second el.properties file
-            className = getClassNameJreDir();
+            if (IS_SECURITY_ENABLED) {
+                className = AccessController.doPrivileged(
+                        new PrivilegedAction<String>() {
+                            @Override
+                            public String run() {
+                                return getClassNameJreDir();
+                            }
+                        }
+                );
+            } else {
+                // Second el.properties file
+                className = getClassNameJreDir();
+            }
         }
         if (className == null) {
-            // Third system property 
-            className = getClassNameSysProp();
+            if (IS_SECURITY_ENABLED) {
+                className = AccessController.doPrivileged(
+                        new PrivilegedAction<String>() {
+                            @Override
+                            public String run() {
+                                return getClassNameSysProp();
+                            }
+                        }
+                );
+            } else {
+                // Third system property 
+                className = getClassNameSysProp();
+            }
         }
         if (className == null) {
             // Fourth - default
@@ -225,4 +280,5 @@ public abstract class ExpressionFactory 
         }
         return null;
     }
+
 }

Modified: tomcat/trunk/java/org/apache/el/parser/AstValue.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/el/parser/AstValue.java?rev=933007&r1=933006&r2=933007&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/el/parser/AstValue.java (original)
+++ tomcat/trunk/java/org/apache/el/parser/AstValue.java Sun Apr 11 22:43:09 2010
@@ -20,6 +20,8 @@ package org.apache.el.parser;
 
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
 
 import javax.el.ELException;
 import javax.el.ELResolver;
@@ -39,10 +41,31 @@ import org.apache.el.util.ReflectionUtil
  */
 public final class AstValue extends SimpleNode {
 
-    protected static final boolean COERCE_TO_ZERO =
-        Boolean.valueOf(System.getProperty(
-                "org.apache.el.parser.COERCE_TO_ZERO", "true")).booleanValue();
+    private static final boolean IS_SECURITY_ENABLED =
+        (System.getSecurityManager() != null);
+
+    protected static final boolean COERCE_TO_ZERO;
     
+    static {
+        if (IS_SECURITY_ENABLED) {
+            COERCE_TO_ZERO = AccessController.doPrivileged(
+                    new PrivilegedAction<Boolean>(){
+                        @Override
+                        public Boolean run() {
+                            return Boolean.valueOf(System.getProperty(
+                                    "org.apache.el.parser.COERCE_TO_ZERO",
+                                    "true"));
+                        }
+
+                    }
+            ).booleanValue();
+        } else {
+            COERCE_TO_ZERO = Boolean.valueOf(System.getProperty(
+                    "org.apache.el.parser.COERCE_TO_ZERO",
+                    "true")).booleanValue();
+        }
+    }
+
     protected static class Target {
         protected Object base;
 



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message