23
23
package java .security ;
24
24
25
25
import com .ibm .oti .util .Msg ;
26
+ /*[IF JAVA_SPEC_VERSION < 24]*/
26
27
import sun .security .util .SecurityConstants ;
28
+ /*[ENDIF] JAVA_SPEC_VERSION < 24 */
27
29
28
30
/*[IF JAVA_SPEC_VERSION >= 9]
29
31
import jdk.internal.reflect.CallerSensitive;
@@ -49,25 +51,25 @@ public final class AccessController {
49
51
initializeInternal ();
50
52
}
51
53
54
+ private static native void initializeInternal ();
55
+
52
56
/*[IF JAVA_SPEC_VERSION >= 24]*/
53
57
private static AccessControlContext ACC_NO_PERM = new AccessControlContext (
54
58
new ProtectionDomain [] { new ProtectionDomain (null , null ) });
55
- /*[ENDIF] JAVA_SPEC_VERSION >= 24 */
56
-
59
+ /*[ELSE] JAVA_SPEC_VERSION >= 24 */
57
60
static final int OBJS_INDEX_ACC = 0 ;
58
61
static final int OBJS_INDEX_PDS = 1 ;
59
62
static final int OBJS_ARRAY_SIZE = 3 ;
60
63
static final int OBJS_INDEX_PERMS_OR_CACHECHECKED = 2 ;
61
64
62
- private static native void initializeInternal ();
63
-
64
65
/* [PR CMVC 188787] Enabling -Djava.security.debug option within WAS keeps JVM busy */
65
66
static final class DebugRecursionDetection {
66
67
private static ThreadLocal <String > tlDebug = new ThreadLocal <>();
67
68
static ThreadLocal <String > getTlDebug () {
68
69
return tlDebug ;
69
70
}
70
71
}
72
+ /*[ENDIF] JAVA_SPEC_VERSION >= 24 */
71
73
72
74
/*[PR 1FDIC6B] J9JCL:WIN95 - AccessController missing private no-arg constructor */
73
75
/**
@@ -77,6 +79,7 @@ private AccessController() {
77
79
super ();
78
80
}
79
81
82
+ /*[IF JAVA_SPEC_VERSION < 24]*/
80
83
/**
81
84
* The object array returned has following format:
82
85
*
@@ -192,7 +195,6 @@ private static void throwACE(boolean debug, Permission perm, ProtectionDomain pD
192
195
}
193
196
}
194
197
195
- /*[IF JAVA_SPEC_VERSION < 24]*/
196
198
/**
197
199
* Helper method to check whether the running program is allowed to access the resource
198
200
* being guarded by the given Permission argument
@@ -275,7 +277,6 @@ private static boolean checkPermissionHelper(Permission perm, AccessControlConte
275
277
}
276
278
return limitedPermImplied ;
277
279
}
278
- /*[ENDIF] JAVA_SPEC_VERSION < 24 */
279
280
280
281
/**
281
282
* Helper to print debug stack information for checkPermission().
@@ -365,15 +366,23 @@ private static boolean debugHelperJEP140(Object[] objects, Permission perm) {
365
366
debugPrintStack (debug , perm );
366
367
return debug ;
367
368
}
369
+ /*[ENDIF] JAVA_SPEC_VERSION < 24 */
368
370
369
371
/**
372
+ /*[IF JAVA_SPEC_VERSION >= 24]
373
+ * Throws AccessControlException
374
+ *
375
+ * @param perm is ignored
376
+ * @exception AccessControlException is always thrown
377
+ /*[ELSE] JAVA_SPEC_VERSION >= 24
370
378
* Checks whether the running program is allowed to
371
379
* access the resource being guarded by the given
372
380
* Permission argument.
373
381
*
374
382
* @param perm the permission to check
375
383
* @exception AccessControlException if access is not allowed.
376
384
* NullPointerException if perm is null
385
+ /*[ENDIF] JAVA_SPEC_VERSION >= 24
377
386
*/
378
387
public static void checkPermission (Permission perm ) throws AccessControlException {
379
388
/*[IF JAVA_SPEC_VERSION >= 24]*/
@@ -455,6 +464,9 @@ private static void keepalive(Permission... perms) {
455
464
}
456
465
457
466
/**
467
+ /*[IF JAVA_SPEC_VERSION >= 24]
468
+ * @return an AccessControlContext with no permissions
469
+ /*[ELSE] JAVA_SPEC_VERSION >= 24
458
470
* Answers the access controller context of the current thread,
459
471
* including the inherited ones. It basically retrieves all the
460
472
* protection domains from the calling stack and creates an
@@ -463,6 +475,7 @@ private static void keepalive(Permission... perms) {
463
475
* @return an AccessControlContext which captures the current state
464
476
*
465
477
* @see AccessControlContext
478
+ /*[ENDIF] JAVA_SPEC_VERSION >= 24
466
479
*/
467
480
public static AccessControlContext getContext () {
468
481
/*[IF JAVA_SPEC_VERSION >= 24]*/
@@ -472,6 +485,7 @@ public static AccessControlContext getContext() {
472
485
/*[ENDIF] JAVA_SPEC_VERSION >= 24 */
473
486
}
474
487
488
+ /*[IF JAVA_SPEC_VERSION < 24]*/
475
489
/**
476
490
* This is a helper method for getContext() and doPrivilegedWithCombiner methods.
477
491
* Answers the access controller context of the current thread including the inherited ones.
@@ -637,6 +651,7 @@ private static int getNewAuthorizedState(AccessControlContext acc, ProtectionDom
637
651
}
638
652
return newAuthorizedState ;
639
653
}
654
+ /*[ENDIF] JAVA_SPEC_VERSION < 24 */
640
655
641
656
/**
642
657
* Helper method to combine the ProtectionDomain objects
@@ -849,7 +864,11 @@ public static <T> T doPrivileged (PrivilegedExceptionAction<T> action, AccessCon
849
864
*/
850
865
@ CallerSensitive
851
866
public static <T > T doPrivilegedWithCombiner (PrivilegedAction <T > action ) {
867
+ /*[IF JAVA_SPEC_VERSION >= 24]*/
868
+ return doPrivileged (action , null );
869
+ /*[ELSE] JAVA_SPEC_VERSION >= 24*/
852
870
return doPrivileged (action , doPrivilegedWithCombinerHelper (null ));
871
+ /*[ENDIF] JAVA_SPEC_VERSION >= 24*/
853
872
}
854
873
855
874
/**
@@ -876,9 +895,14 @@ public static <T> T doPrivilegedWithCombiner(PrivilegedAction<T> action) {
876
895
public static <T > T doPrivilegedWithCombiner (PrivilegedExceptionAction <T > action )
877
896
throws PrivilegedActionException
878
897
{
898
+ /*[IF JAVA_SPEC_VERSION >= 24]*/
899
+ return doPrivileged (action , null );
900
+ /*[ELSE] JAVA_SPEC_VERSION >= 24*/
879
901
return doPrivileged (action , doPrivilegedWithCombinerHelper (null ));
902
+ /*[ENDIF] JAVA_SPEC_VERSION >= 24*/
880
903
}
881
904
905
+ /*[IF JAVA_SPEC_VERSION < 24]*/
882
906
/**
883
907
* Helper method to check if any permission is null
884
908
*
@@ -894,6 +918,7 @@ private static void checkPermsNPE(Permission... perms) {
894
918
}
895
919
}
896
920
}
921
+ /*[ENDIF] JAVA_SPEC_VERSION < 24 */
897
922
898
923
/**
899
924
* Performs the privileged action specified by <code>action</code>.
@@ -922,7 +947,9 @@ private static void checkPermsNPE(Permission... perms) {
922
947
public static <T > T doPrivileged (PrivilegedAction <T > action ,
923
948
AccessControlContext context , Permission ... perms )
924
949
{
950
+ /*[IF JAVA_SPEC_VERSION < 24]*/
925
951
checkPermsNPE (perms );
952
+ /*[ENDIF] JAVA_SPEC_VERSION < 24 */
926
953
T result = action .run ();
927
954
keepalive (context );
928
955
keepalive (perms );
@@ -954,8 +981,13 @@ public static <T> T doPrivileged(PrivilegedAction<T> action,
954
981
public static <T > T doPrivilegedWithCombiner (PrivilegedAction <T > action ,
955
982
AccessControlContext context , Permission ... perms )
956
983
{
984
+ /*[IF JAVA_SPEC_VERSION >= 24]*/
985
+ return doPrivileged (action , context , perms ); // 24 - perms?
986
+ /*[ELSE] JAVA_SPEC_VERSION >= 24*/
957
987
checkPermsNPE (perms );
958
988
return doPrivileged (action , doPrivilegedWithCombinerHelper (context ), perms );
989
+ /*[ENDIF] JAVA_SPEC_VERSION >= 24*/
990
+
959
991
}
960
992
961
993
/**
@@ -989,7 +1021,9 @@ public static <T> T doPrivileged(PrivilegedExceptionAction<T> action,
989
1021
throws PrivilegedActionException
990
1022
{
991
1023
try {
1024
+ /*[IF JAVA_SPEC_VERSION < 24]*/
992
1025
checkPermsNPE (perms );
1026
+ /*[ENDIF] JAVA_SPEC_VERSION < 24 */
993
1027
T result = action .run ();
994
1028
keepalive (context );
995
1029
keepalive (perms );
@@ -1029,10 +1063,15 @@ public static <T> T doPrivilegedWithCombiner(PrivilegedExceptionAction<T> action
1029
1063
AccessControlContext context , Permission ... perms )
1030
1064
throws PrivilegedActionException
1031
1065
{
1066
+ /*[IF JAVA_SPEC_VERSION >= 24]*/
1067
+ return doPrivileged (action , context , perms );
1068
+ /*[ELSE] JAVA_SPEC_VERSION >= 24 */
1032
1069
checkPermsNPE (perms );
1033
1070
return doPrivileged (action , doPrivilegedWithCombinerHelper (context ), perms );
1071
+ /*[ENDIF] JAVA_SPEC_VERSION >= 24 */
1034
1072
}
1035
1073
1074
+ /*[IF JAVA_SPEC_VERSION < 24]*/
1036
1075
/**
1037
1076
* Helper method to construct an AccessControlContext for doPrivilegedWithCombiner methods.
1038
1077
*
@@ -1052,5 +1091,6 @@ private static AccessControlContext doPrivilegedWithCombinerHelper(AccessControl
1052
1091
}
1053
1092
return fixedContext ;
1054
1093
}
1094
+ /*[ENDIF] JAVA_SPEC_VERSION < 24*/
1055
1095
1056
1096
}
0 commit comments