KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > soot > jimple > toolkits > pointer > nativemethods > JavaSecurityAccessControllerNative


1 /* Soot - a J*va Optimization Framework
2  * Copyright (C) 2003 Feng Qian
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */

19
20 /**
21  * Simulates the native method side effects in class java.security.AccessController
22  *
23  * @author Feng Qian
24  * @author <XXX>
25  */

26
27 package soot.jimple.toolkits.pointer.nativemethods;
28
29 import soot.*;
30 import soot.jimple.toolkits.pointer.representations.*;
31 import soot.jimple.toolkits.pointer.util.*;
32
33 public class JavaSecurityAccessControllerNative extends NativeMethodClass {
34     public JavaSecurityAccessControllerNative( NativeHelper helper ) { super(helper); }
35
36   /**
37    * Implements the abstract method simulateMethod.
38    * It distributes the request to the corresponding methods
39    * by signatures.
40    */

41   public void simulateMethod(SootMethod method,
42                  ReferenceVariable thisVar,
43                  ReferenceVariable returnVar,
44                  ReferenceVariable params[]){
45
46     String JavaDoc subSignature = method.getSubSignature();
47
48     if (subSignature.equals("java.lang.Object doPrivileged(java.security.PrivilegedAction)")){
49       java_security_AccessController_doPrivileged(method, thisVar,
50                           returnVar, params);
51       return;
52
53     } else if (subSignature.equals("java.lang.Object doPrivileged(java.security.PrivilegedExceptionAction)")){
54       java_security_AccessController_doPrivileged(method, thisVar,
55                           returnVar, params);
56       return;
57
58     } else if (subSignature.equals("java.lang.Object doPrivileged(java.security.PrivilegedAction,java.security.AccessControlContext)")){
59       java_security_AccessController_doPrivileged(method, thisVar,
60                           returnVar, params);
61       return;
62
63     } else if (subSignature.equals("java.lang.Object doPrivileged(java.security.PrivilegedExceptionAction,java.security.AccessControlContext)")){
64       java_security_AccessController_doPrivileged(method, thisVar,
65                           returnVar, params);
66       return;
67
68     } else if (subSignature.equals("java.security.AccessControlContext getStackAccessControlContext()")){
69       java_security_AccessController_getStackAccessControlContext(method,
70                                   thisVar,
71                                   returnVar,
72                                   params);
73       return;
74
75     } else if (subSignature.equals("java.security.AccessControlContext getInheritedAccessControlContext()")){
76       java_security_AccessController_getInheritedAccessControlContext(
77                             method,
78                         thisVar,
79                         returnVar,
80                         params);
81       return;
82
83     } else {
84       defaultMethod(method, thisVar, returnVar, params);
85       return;
86
87     }
88   }
89
90   /************************ java.security.AccessController ************/
91   /* The return value of doPrivileged depends on the implementation.
92    *
93    * public static native
94    * java.lang.Object doPrivileged(java.security.PrivilegedAction);
95    *
96    * public static native
97    * java.lang.Object doPrivileged(java.security.PrivilegedExceptionAction)
98    * throws java.security.PrivilegedActionException;
99    *
100    * public static native
101    * java.lang.Object doPrivileged(java.security.PrivilegedAction,
102    * java.security.AccessControlContext);
103    *
104    * public static native
105    * java.lang.Object doPrivileged(java.security.PrivilegedExceptionAction,
106    * java.security.AccessControlContext)
107    * throws java.security.PrivilegedActionException;
108    */

109   public
110     void java_security_AccessController_doPrivileged(
111                  SootMethod method,
112                  ReferenceVariable thisVar,
113                  ReferenceVariable returnVar,
114                  ReferenceVariable params[]){
115     // No longer necessary since Spark handles it itself in a more precise
116
// way.
117
//helper.assignObjectTo(returnVar, Environment.v().getLeastObject());
118
helper.throwException(Environment.v().getPrivilegedActionExceptionObject());
119   }
120
121   /**
122    * Creates an access control context object.
123    *
124    * private static native
125    * java.security.AccessControlContext getStackAccessControlContext();
126    */

127   public
128     void java_security_AccessController_getStackAccessControlContext(
129                         SootMethod method,
130                         ReferenceVariable thisVar,
131                         ReferenceVariable returnVar,
132                         ReferenceVariable params[]){
133     helper.assignObjectTo(returnVar, Environment.v().getLeastObject());
134   }
135
136
137   /**
138    * NOTE: not documented and not called by anyone
139    *
140    * static native
141    * java.security.AccessControlContext getInheritedAccessControlContext();
142    */

143   public
144     void java_security_AccessController_getInheritedAccessControlContext(
145                        SootMethod method,
146                        ReferenceVariable thisVar,
147                        ReferenceVariable returnVar,
148                        ReferenceVariable params[]){
149     helper.assignObjectTo(returnVar, Environment.v().getLeastObject());
150   }
151 }
152
Popular Tags