01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */
19: package org.apache.openjpa.lib.util;
20:
21: import java.lang.reflect.AnnotatedElement;
22: import java.security.PrivilegedAction;
23:
24: /**
25: * Helper class to obtain the Privilege(Exception)Action object to perform
26: * Java 2 doPrivilege security sensitive function call in the following
27: * methods:
28: * <ul>
29: * <li>AnnotatedElement.getAnnotations
30: * <li>AnnotatedElement.getDeclaredAnnotations
31: * <li>AnnotatedElement.isAnnotationPresent
32: * </ul>
33: *
34: * @author Albert Lee
35: */
36:
37: public abstract class J2DoPriv5Helper extends J2DoPrivHelper {
38:
39: /**
40: * Return a PrivilegeAction object for AnnotatedElement.getAnnotations().
41: *
42: * Requires security policy:
43: * 'permission java.lang.RuntimePermission "accessDeclaredMembers";'
44: *
45: * @return Annotation[]
46: */
47: public static final PrivilegedAction getAnnotationsAction(
48: final AnnotatedElement element) {
49: return new PrivilegedAction() {
50: public Object run() {
51: return element.getAnnotations();
52: }
53: };
54: }
55:
56: /**
57: * Return a PrivilegeAction object for
58: * AnnotatedElement.getDeclaredAnnotations().
59: *
60: * Requires security policy:
61: * 'permission java.lang.RuntimePermission "accessDeclaredMembers";'
62: *
63: * @return Annotation[]
64: */
65: public static final PrivilegedAction getDeclaredAnnotationsAction(
66: final AnnotatedElement element) {
67: return new PrivilegedAction() {
68: public Object run() {
69: return element.getDeclaredAnnotations();
70: }
71: };
72: }
73:
74: /**
75: * Return a PrivilegeAction object for
76: * AnnotatedElement.isAnnotationPresent().
77: *
78: * Requires security policy:
79: * 'permission java.lang.RuntimePermission "accessDeclaredMembers";'
80: *
81: * @return Boolean
82: */
83: public static final PrivilegedAction isAnnotationPresentAction(
84: final AnnotatedElement element, final Class annotationClazz) {
85: return new PrivilegedAction() {
86: public Object run() {
87: return element.isAnnotationPresent(annotationClazz) ? Boolean.TRUE
88: : Boolean.FALSE;
89: }
90: };
91: }
92: }
|