47
47
import javax .resource .ResourceException ;
48
48
import java .lang .reflect .InvocationTargetException ;
49
49
import java .lang .reflect .Method ;
50
+ import java .security .AccessController ;
51
+ import java .security .PrivilegedAction ;
52
+ import java .security .PrivilegedActionException ;
53
+ import java .security .PrivilegedExceptionAction ;
50
54
import java .util .Vector ;
51
55
import java .util .Properties ;
52
56
import java .util .logging .Level ;
@@ -87,28 +91,38 @@ public void runJavaBeanMethod(String value, Method method, Object obj) throws Re
87
91
if (value == null || value .trim ().equals ("" )) {
88
92
return ;
89
93
}
90
- try {
91
- Class [] parameters = method .getParameterTypes ();
92
- if (parameters .length == 1 ) {
93
- Object [] values = new Object [1 ];
94
- values [0 ] = convertType (parameters [0 ], value );
95
- method .invoke (obj , values );
94
+
95
+ Class [] parameters = method .getParameterTypes ();
96
+ if (parameters .length == 1 ) {
97
+ Object [] values = new Object [1 ];
98
+ values [0 ] = convertType (parameters [0 ], value );
99
+
100
+ final ResourceException [] exception = new ResourceException [1 ];
101
+ AccessController
102
+ .doPrivileged (new PrivilegedAction () {
103
+ public Object run () {
104
+ try {
105
+ method .setAccessible (true );
106
+ method .invoke (obj , values );
107
+ } catch (IllegalAccessException | InvocationTargetException | SecurityException iae ) {
108
+ _logger .log (Level .SEVERE , "jdbc.exc_jb_val" , value );
109
+ _logger .log (Level .SEVERE , "" , iae );
110
+ String msg = sm .getString ("me.access_denied" ,
111
+ method .getName ());
112
+ exception [0 ] = new ResourceException (msg );
113
+ } catch (IllegalArgumentException ie ) {
114
+ _logger .log (Level .SEVERE , "jdbc.exc_jb_val" , value );
115
+ _logger .log (Level .SEVERE , "" , ie );
116
+ String msg = sm
117
+ .getString ("me.illegal_args" , method .getName ());
118
+ exception [0 ] = new ResourceException (msg );
119
+ }
120
+ return null ;
121
+ }
122
+ });
123
+ if ( exception [0 ] != null ){
124
+ throw exception [0 ];
96
125
}
97
- } catch (IllegalAccessException iae ) {
98
- _logger .log (Level .SEVERE , "jdbc.exc_jb_val" , value );
99
- _logger .log (Level .SEVERE , "" , iae );
100
- String msg = sm .getString ("me.access_denied" , method .getName ());
101
- throw new ResourceException (msg );
102
- } catch (IllegalArgumentException ie ) {
103
- _logger .log (Level .SEVERE , "jdbc.exc_jb_val" , value );
104
- _logger .log (Level .SEVERE , "" , ie );
105
- String msg = sm .getString ("me.illegal_args" , method .getName ());
106
- throw new ResourceException (msg );
107
- } catch (InvocationTargetException ite ) {
108
- _logger .log (Level .SEVERE , "jdbc.exc_jb_val" , value );
109
- _logger .log (Level .SEVERE , "" , ite );
110
- String msg = sm .getString ("me.access_denied" , method .getName ());
111
- throw new ResourceException (msg );
112
126
}
113
127
}
114
128
@@ -123,7 +137,6 @@ public void runJavaBeanMethod(String value, Method method, Object obj) throws Re
123
137
* a security violation.
124
138
*/
125
139
public void runMethod (Method method , Object obj , Vector values ) throws ResourceException {
126
- try {
127
140
Class [] parameters = method .getParameterTypes ();
128
141
if (values .size () != parameters .length ) {
129
142
return ;
@@ -137,22 +150,30 @@ public void runMethod(Method method, Object obj, Vector values) throws ResourceE
137
150
actualValues [i ] = convertType (parameters [i ], val );
138
151
}
139
152
}
140
- method .invoke (obj , actualValues );
141
- } catch (IllegalAccessException iae ) {
142
- _logger .log (Level .SEVERE , "jdbc.exc_jb_val" , values );
143
- _logger .log (Level .SEVERE , "" , iae );
144
- String msg = sm .getString ("me.access_denied" , method .getName ());
145
- throw new ResourceException (msg );
146
- } catch (IllegalArgumentException ie ) {
147
- _logger .log (Level .SEVERE , "jdbc.exc_jb_val" , values );
148
- _logger .log (Level .SEVERE , "" , ie );
149
- String msg = sm .getString ("me.illegal_args" , method .getName ());
150
- throw new ResourceException (msg );
151
- } catch (InvocationTargetException ite ) {
152
- _logger .log (Level .SEVERE , "jdbc.exc_jb_val" , values );
153
- _logger .log (Level .SEVERE , "" , ite );
154
- String msg = sm .getString ("me.access_denied" , method .getName ());
155
- throw new ResourceException (msg );
153
+ final ResourceException [] exception = new ResourceException [1 ];
154
+ AccessController .doPrivileged (new PrivilegedAction () {
155
+ public Object run () {
156
+ try {
157
+ method .setAccessible (true );
158
+ method .invoke (obj , actualValues );
159
+ } catch (IllegalAccessException | InvocationTargetException | SecurityException iae ) {
160
+ _logger .log (Level .SEVERE , "jdbc.exc_jb_val" , values );
161
+ _logger .log (Level .SEVERE , "" , iae );
162
+ String msg = sm
163
+ .getString ("me.access_denied" , method .getName ());
164
+ exception [0 ] = new ResourceException (msg );
165
+ } catch (IllegalArgumentException ie ) {
166
+ _logger .log (Level .SEVERE , "jdbc.exc_jb_val" , values );
167
+ _logger .log (Level .SEVERE , "" , ie );
168
+ String msg = sm
169
+ .getString ("me.illegal_args" , method .getName ());
170
+ exception [0 ] = new ResourceException (msg );
171
+ }
172
+ return null ;
173
+ }
174
+ });
175
+ if ( exception [0 ] != null ){
176
+ throw exception [0 ];
156
177
}
157
178
}
158
179
@@ -225,7 +246,7 @@ private Object convertType(Class type, String parameter) throws ResourceExceptio
225
246
public Object invokeMethod (Object object , String methodName ,
226
247
Class <?>[] valueTypes , Object ... values ) throws ResourceException {
227
248
Object returnValue = null ;
228
- Method actualMethod = null ;
249
+ Method actualMethod ;
229
250
try {
230
251
actualMethod = object .getClass ().getMethod (methodName , valueTypes );
231
252
} catch (NoSuchMethodException ex ) {
@@ -235,13 +256,17 @@ public Object invokeMethod(Object object, String methodName,
235
256
}
236
257
if (actualMethod != null ) {
237
258
try {
238
- returnValue = actualMethod .invoke (object , values );
239
- } catch (IllegalAccessException ex ) {
240
- throw new ResourceException (ex );
241
- } catch (IllegalArgumentException ex ) {
242
- throw new ResourceException (ex );
243
- } catch (InvocationTargetException ex ) {
244
- throw new ResourceException (ex );
259
+ returnValue = AccessController .doPrivileged (
260
+ (PrivilegedExceptionAction <Object >) () -> {
261
+ actualMethod .setAccessible (true );
262
+ return actualMethod .invoke (object , values );
263
+ });
264
+ } catch (PrivilegedActionException e ) {
265
+ if (e .getException () != null ){
266
+ throw new ResourceException (e .getException ());
267
+ }else {
268
+ throw new ResourceException (e );
269
+ }
245
270
}
246
271
}
247
272
return returnValue ;
0 commit comments