1 17 18 package org.apache.jasper.runtime; 19 20 import java.util.HashMap ; 21 import java.security.AccessController ; 22 import java.security.PrivilegedAction ; 23 import java.security.PrivilegedExceptionAction ; 24 import java.security.PrivilegedActionException ; 25 import java.lang.reflect.Method ; 26 import javax.servlet.jsp.el.FunctionMapper ; 27 28 import org.apache.jasper.security.SecurityUtil; 29 30 37 public final class ProtectedFunctionMapper extends javax.el.FunctionMapper 38 implements FunctionMapper { 39 40 43 private HashMap fnmap = null; 44 45 48 private Method theMethod = null; 49 50 53 private ProtectedFunctionMapper() { 54 } 55 56 64 public static ProtectedFunctionMapper getInstance() { 65 ProtectedFunctionMapper funcMapper; 66 if (SecurityUtil.isPackageProtectionEnabled()) { 67 funcMapper = (ProtectedFunctionMapper) AccessController 68 .doPrivileged(new PrivilegedAction () { 69 public Object run() { 70 return new ProtectedFunctionMapper(); 71 } 72 }); 73 } else { 74 funcMapper = new ProtectedFunctionMapper(); 75 } 76 funcMapper.fnmap = new java.util.HashMap (); 77 return funcMapper; 78 } 79 80 95 public void mapFunction(String fnQName, final Class c, 96 final String methodName, final Class [] args) { 97 java.lang.reflect.Method method; 98 if (SecurityUtil.isPackageProtectionEnabled()) { 99 try { 100 method = (java.lang.reflect.Method ) AccessController 101 .doPrivileged(new PrivilegedExceptionAction () { 102 103 public Object run() throws Exception { 104 return c.getDeclaredMethod(methodName, args); 105 } 106 }); 107 } catch (PrivilegedActionException ex) { 108 throw new RuntimeException ( 109 "Invalid function mapping - no such method: " 110 + ex.getException().getMessage()); 111 } 112 } else { 113 try { 114 method = c.getDeclaredMethod(methodName, args); 115 } catch (NoSuchMethodException e) { 116 throw new RuntimeException ( 117 "Invalid function mapping - no such method: " 118 + e.getMessage()); 119 } 120 } 121 122 this.fnmap.put(fnQName, method); 123 } 124 125 141 public static ProtectedFunctionMapper getMapForFunction(String fnQName, 142 final Class c, final String methodName, final Class [] args) { 143 java.lang.reflect.Method method; 144 ProtectedFunctionMapper funcMapper; 145 if (SecurityUtil.isPackageProtectionEnabled()) { 146 funcMapper = (ProtectedFunctionMapper) AccessController 147 .doPrivileged(new PrivilegedAction () { 148 public Object run() { 149 return new ProtectedFunctionMapper(); 150 } 151 }); 152 153 try { 154 method = (java.lang.reflect.Method ) AccessController 155 .doPrivileged(new PrivilegedExceptionAction () { 156 157 public Object run() throws Exception { 158 return c.getDeclaredMethod(methodName, args); 159 } 160 }); 161 } catch (PrivilegedActionException ex) { 162 throw new RuntimeException ( 163 "Invalid function mapping - no such method: " 164 + ex.getException().getMessage()); 165 } 166 } else { 167 funcMapper = new ProtectedFunctionMapper(); 168 try { 169 method = c.getDeclaredMethod(methodName, args); 170 } catch (NoSuchMethodException e) { 171 throw new RuntimeException ( 172 "Invalid function mapping - no such method: " 173 + e.getMessage()); 174 } 175 } 176 funcMapper.theMethod = method; 177 return funcMapper; 178 } 179 180 190 public Method resolveFunction(String prefix, String localName) { 191 if (this.fnmap != null) { 192 return (Method ) this.fnmap.get(prefix + ":" + localName); 193 } 194 return theMethod; 195 } 196 } 197 | Popular Tags |