通过调试,
我struts的action的方法里调用
request.getParameter方法,应该是调用的servlet api 中的
org.apache.catalina.connector.RequestFacade 类的重载的getParameter方法,
public String getParameter(String name) {
if (request == null) {
throw new IllegalStateException(
sm.getString("requestFacade.nullRequest"));
}
if (Globals.IS_SECURITY_ENABLED){
return (String)AccessController.doPrivileged(
new GetParameterPrivilegedAction(name));
} else {
return request.getParameter(name);
}
}
然后,上面调用的
return (String)AccessController.doPrivileged(
new GetParameterPrivilegedAction(name));
可我发现doPriviledged是native的,我就不知道tomcat目录下哪个文件里实现的native方法的了....
public static native T doPrivileged(PrivilegedAction action);
这个是Java标准库中的类的native实现,跟Tomcat没关系。如果你用的是Sun的JVM的话,源码是在j2se\src\share\native\java\security\AccessController.c
[code="c"]/*
Signature: (Ljava/security/PrivilegedAction;)Ljava/lang/Object;
*/
JNIEXPORT jobject JNICALL Java_java_security_AccessController_doPrivileged__Ljava_security_PrivilegedAction_2
(JNIEnv *env, jclass cls, jobject action)
{
return JVM_DoPrivileged(env, cls, action, NULL, JNI_FALSE);
}[/code]
hotspot\src\share\vm\prims\jvm.cpp
[code="c++"]JVM_ENTRY(jobject, JVM_DoPrivileged(JNIEnv *env, jclass cls, jobject action, jobject context, jboolean wrapException))
JVMWrapper("JVM_DoPrivileged");
if (action == NULL) {
THROW_MSG_0(vmSymbols::java_lang_NullPointerException(), "Null action");
}
// Stack allocated list of privileged stack elements
PrivilegedElement pi;
// Check that action object understands "Object run()"
Handle object (THREAD, JNIHandles::resolve(action));
// get run() method
methodOop m_oop = Klass::cast(object->klass())->uncached_lookup_method(
vmSymbols::run_method_name(),
vmSymbols::void_object_signature());
methodHandle m (THREAD, m_oop);
if (m.is_null() || !m->is_method() || !methodOop(m())->is_public() || methodOop(m())->is_static()) {
THROW_MSG_0(vmSymbols::java_lang_InternalError(), "No run method");
}
// Compute the frame initiating the do privileged operation and setup the privileged stack
vframeStream vfst(thread);
vfst.security_get_caller_frame(1);
if (!vfst.at_end()) {
pi.initialize(&vfst, JNIHandles::resolve(context), thread->privileged_stack_top(), CHECK_NULL);
thread->set_privileged_stack_top(&pi);
}
// invoke the Object run() in the action object. We cannot use call_interface here, since the static type
// is not really known - it is either java.security.PrivilegedAction or java.security.PrivilegedExceptionAction
Handle pending_exception;
JavaValue result(T_OBJECT);
JavaCallArguments args(object);
JavaCalls::call(&result, m, &args, THREAD);
// done with action, remove ourselves from the list
if (!vfst.at_end()) {
assert(thread->privileged_stack_top() != NULL && thread->privileged_stack_top() == &pi, "wrong top element");
thread->set_privileged_stack_top(thread->privileged_stack_top()->next());
}
if (HAS_PENDING_EXCEPTION) {
pending_exception = Handle(THREAD, PENDING_EXCEPTION);
CLEAR_PENDING_EXCEPTION;
if ( pending_exception->is_a(SystemDictionary::exception_klass()) &&
!pending_exception->is_a(SystemDictionary::runtime_exception_klass())) {
// Throw a java.security.PrivilegedActionException(Exception e) exception
JavaCallArguments args(pending_exception);
THROW_ARG_0(vmSymbolHandles::java_security_PrivilegedActionException(),
vmSymbolHandles::exception_void_signature(),
&args);
}
}
if (pending_exception.not_null()) THROW_OOP_0(pending_exception());
return JNIHandles::make_local(env, (oop) result.get_jobject());
JVM_END[/code]
这些源码可以从Sun的官网获取,http://download.java.net/jdk6/source/ ,也可以下载OpenJDK版,http://download.java.net/openjdk/jdk6/