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;
/**
* @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;
// 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
}
return null;
}
+
}
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;
*/
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;