Skip to content

Commit

Permalink
java.security comment update and exclude helper methods
Browse files Browse the repository at this point in the history
Signed-off-by: Theresa Mammarella <[email protected]>
  • Loading branch information
theresa-m committed Nov 22, 2024
1 parent 7492ec2 commit 2bf463b
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,13 @@ private boolean debugHelper(Permission perm) {
}

/**
/*[IF JAVA_SPEC_VERSION >= 24]
* Throws java.security.AccessControlException
*
* @param perm is ignored
* @exception java.security.AccessControlException
* is always thrown
/*[ELSE] JAVA_SPEC_VERSION >= 24
* Checks if the permission <code>perm</code> is allowed in this context.
* All ProtectionDomains must grant the permission for it to be granted.
*
Expand All @@ -731,6 +738,7 @@ private boolean debugHelper(Permission perm) {
* thrown when perm is not granted.
* @exception NullPointerException
* if perm is null
/*[ENDIF] JAVA_SPEC_VERSION >= 24
*/
public void checkPermission(Permission perm) throws AccessControlException {
/*[IF JAVA_SPEC_VERSION >= 24]*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
package java.security;

import com.ibm.oti.util.Msg;
/*[IF JAVA_SPEC_VERSION < 24]*/
import sun.security.util.SecurityConstants;
/*[ENDIF] JAVA_SPEC_VERSION < 24 */

/*[IF JAVA_SPEC_VERSION >= 9]
import jdk.internal.reflect.CallerSensitive;
Expand All @@ -49,25 +51,25 @@ public final class AccessController {
initializeInternal();
}

private static native void initializeInternal();

/*[IF JAVA_SPEC_VERSION >= 24]*/
private static AccessControlContext ACC_NO_PERM = new AccessControlContext(
new ProtectionDomain[] { new ProtectionDomain(null, null) });
/*[ENDIF] JAVA_SPEC_VERSION >= 24 */

/*[ELSE] JAVA_SPEC_VERSION >= 24 */
static final int OBJS_INDEX_ACC = 0;
static final int OBJS_INDEX_PDS = 1;
static final int OBJS_ARRAY_SIZE = 3;
static final int OBJS_INDEX_PERMS_OR_CACHECHECKED = 2;

private static native void initializeInternal();

/* [PR CMVC 188787] Enabling -Djava.security.debug option within WAS keeps JVM busy */
static final class DebugRecursionDetection {
private static ThreadLocal<String> tlDebug = new ThreadLocal<>();
static ThreadLocal<String> getTlDebug() {
return tlDebug;
}
}
/*[ENDIF] JAVA_SPEC_VERSION >= 24 */

/*[PR 1FDIC6B] J9JCL:WIN95 - AccessController missing private no-arg constructor */
/**
Expand All @@ -77,6 +79,7 @@ private AccessController() {
super();
}

/*[IF JAVA_SPEC_VERSION < 24]*/
/**
* The object array returned has following format:
*
Expand Down Expand Up @@ -192,7 +195,6 @@ private static void throwACE(boolean debug, Permission perm, ProtectionDomain pD
}
}

/*[IF JAVA_SPEC_VERSION < 24]*/
/**
* Helper method to check whether the running program is allowed to access the resource
* being guarded by the given Permission argument
Expand Down Expand Up @@ -275,7 +277,6 @@ private static boolean checkPermissionHelper(Permission perm, AccessControlConte
}
return limitedPermImplied;
}
/*[ENDIF] JAVA_SPEC_VERSION < 24 */

/**
* Helper to print debug stack information for checkPermission().
Expand Down Expand Up @@ -365,15 +366,23 @@ private static boolean debugHelperJEP140(Object[] objects, Permission perm) {
debugPrintStack(debug, perm);
return debug;
}
/*[ENDIF] JAVA_SPEC_VERSION < 24 */

/**
/*[IF JAVA_SPEC_VERSION >= 24]
* Throws AccessControlException
*
* @param perm is ignored
* @exception AccessControlException is always thrown
/*[ELSE] JAVA_SPEC_VERSION >= 24
* Checks whether the running program is allowed to
* access the resource being guarded by the given
* Permission argument.
*
* @param perm the permission to check
* @exception AccessControlException if access is not allowed.
* NullPointerException if perm is null
/*[ENDIF] JAVA_SPEC_VERSION >= 24
*/
public static void checkPermission(Permission perm) throws AccessControlException {
/*[IF JAVA_SPEC_VERSION >= 24]*/
Expand Down Expand Up @@ -455,6 +464,9 @@ private static void keepalive(Permission... perms) {
}

/**
/*[IF JAVA_SPEC_VERSION >= 24]
* @return an AccessControlContext with no permissions
/*[ELSE] JAVA_SPEC_VERSION >= 24
* Answers the access controller context of the current thread,
* including the inherited ones. It basically retrieves all the
* protection domains from the calling stack and creates an
Expand All @@ -463,6 +475,7 @@ private static void keepalive(Permission... perms) {
* @return an AccessControlContext which captures the current state
*
* @see AccessControlContext
/*[ENDIF] JAVA_SPEC_VERSION >= 24
*/
public static AccessControlContext getContext() {
/*[IF JAVA_SPEC_VERSION >= 24]*/
Expand All @@ -472,6 +485,7 @@ public static AccessControlContext getContext() {
/*[ENDIF] JAVA_SPEC_VERSION >= 24 */
}

/*[IF JAVA_SPEC_VERSION < 24]*/
/**
* This is a helper method for getContext() and doPrivilegedWithCombiner methods.
* Answers the access controller context of the current thread including the inherited ones.
Expand Down Expand Up @@ -637,6 +651,7 @@ private static int getNewAuthorizedState(AccessControlContext acc, ProtectionDom
}
return newAuthorizedState;
}
/*[ENDIF] JAVA_SPEC_VERSION < 24 */

/**
* Helper method to combine the ProtectionDomain objects
Expand Down Expand Up @@ -849,7 +864,11 @@ public static <T> T doPrivileged (PrivilegedExceptionAction<T> action, AccessCon
*/
@CallerSensitive
public static <T> T doPrivilegedWithCombiner(PrivilegedAction<T> action) {
/*[IF JAVA_SPEC_VERSION >= 24]*/
return doPrivileged(action, null);
/*[ELSE] JAVA_SPEC_VERSION >= 24*/
return doPrivileged(action, doPrivilegedWithCombinerHelper(null));
/*[ENDIF] JAVA_SPEC_VERSION >= 24*/
}

/**
Expand All @@ -876,9 +895,14 @@ public static <T> T doPrivilegedWithCombiner(PrivilegedAction<T> action) {
public static <T> T doPrivilegedWithCombiner(PrivilegedExceptionAction<T> action)
throws PrivilegedActionException
{
/*[IF JAVA_SPEC_VERSION >= 24]*/
return doPrivileged(action, null);
/*[ELSE] JAVA_SPEC_VERSION >= 24*/
return doPrivileged(action, doPrivilegedWithCombinerHelper(null));
/*[ENDIF] JAVA_SPEC_VERSION >= 24*/
}

/*[IF JAVA_SPEC_VERSION < 24]*/
/**
* Helper method to check if any permission is null
*
Expand All @@ -894,6 +918,7 @@ private static void checkPermsNPE(Permission... perms) {
}
}
}
/*[ENDIF] JAVA_SPEC_VERSION < 24 */

/**
* Performs the privileged action specified by <code>action</code>.
Expand Down Expand Up @@ -922,7 +947,9 @@ private static void checkPermsNPE(Permission... perms) {
public static <T> T doPrivileged(PrivilegedAction<T> action,
AccessControlContext context, Permission... perms)
{
/*[IF JAVA_SPEC_VERSION < 24]*/
checkPermsNPE(perms);
/*[ENDIF] JAVA_SPEC_VERSION < 24 */
T result = action.run();
keepalive(context);
keepalive(perms);
Expand Down Expand Up @@ -954,8 +981,13 @@ public static <T> T doPrivileged(PrivilegedAction<T> action,
public static <T> T doPrivilegedWithCombiner(PrivilegedAction<T> action,
AccessControlContext context, Permission... perms)
{
/*[IF JAVA_SPEC_VERSION >= 24]*/
return doPrivileged(action, context, perms); // 24 - perms?
/*[ELSE] JAVA_SPEC_VERSION >= 24*/
checkPermsNPE(perms);
return doPrivileged(action, doPrivilegedWithCombinerHelper(context), perms);
/*[ENDIF] JAVA_SPEC_VERSION >= 24*/

}

/**
Expand Down Expand Up @@ -989,7 +1021,9 @@ public static <T> T doPrivileged(PrivilegedExceptionAction<T> action,
throws PrivilegedActionException
{
try {
/*[IF JAVA_SPEC_VERSION < 24]*/
checkPermsNPE(perms);
/*[ENDIF] JAVA_SPEC_VERSION < 24 */
T result = action.run();
keepalive(context);
keepalive(perms);
Expand Down Expand Up @@ -1029,10 +1063,15 @@ public static <T> T doPrivilegedWithCombiner(PrivilegedExceptionAction<T> action
AccessControlContext context, Permission... perms)
throws PrivilegedActionException
{
/*[IF JAVA_SPEC_VERSION >= 24]*/
return doPrivileged(action, context, perms);
/*[ELSE] JAVA_SPEC_VERSION >= 24 */
checkPermsNPE(perms);
return doPrivileged(action, doPrivilegedWithCombinerHelper(context), perms);
/*[ENDIF] JAVA_SPEC_VERSION >= 24 */
}

/*[IF JAVA_SPEC_VERSION < 24]*/
/**
* Helper method to construct an AccessControlContext for doPrivilegedWithCombiner methods.
*
Expand All @@ -1052,5 +1091,6 @@ private static AccessControlContext doPrivilegedWithCombinerHelper(AccessControl
}
return fixedContext;
}
/*[ENDIF] JAVA_SPEC_VERSION < 24*/

}
7 changes: 4 additions & 3 deletions runtime/jcl/common/java_lang_Class.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,11 @@ typedef enum {
#define STACK_WALK_STATE_FULL_DOPRIVILEGED (void *)3

static UDATA isPrivilegedFrameIterator(J9VMThread * currentThread, J9StackWalkState * walkState);
#if JAVA_SPEC_VERSION < 24
static UDATA isPrivilegedFrameIteratorGetAccSnapshot(J9VMThread * currentThread, J9StackWalkState * walkState);
static UDATA frameIteratorGetAccSnapshotHelper(J9VMThread * currentThread, J9StackWalkState * walkState, j9object_t acc, j9object_t perm);
static j9object_t storePDobjectsHelper(J9VMThread* vmThread, J9Class* arrayClass, J9StackWalkState* walkState, j9object_t contextObject, U_32 arraySize, UDATA framesWalked, I_32 startPos, BOOLEAN dupCallerPD);
#endif /* JAVA_SPEC_VERSION < 24 */
static BOOLEAN checkInnerClassHelper(J9Class* declaringClass, J9Class* declaredClass);

jobject JNICALL
Expand Down Expand Up @@ -1201,6 +1203,7 @@ Java_java_lang_Class_permittedSubclassesImpl(JNIEnv *env, jobject cls)
return permittedSubclassesHelper(env, cls);
}

#if JAVA_SPEC_VERSION < 24
static UDATA
frameIteratorGetAccSnapshotHelper(J9VMThread * currentThread, J9StackWalkState * walkState, j9object_t acc, j9object_t perm)
{
Expand Down Expand Up @@ -1423,13 +1426,11 @@ Java_java_security_AccessController_getAccSnapshot(JNIEnv* env, jclass jsAccessC
if (NULL != vmThread->currentException) {
goto _walkStateUninitialized;
}
#if JAVA_SPEC_VERSION < 24
/* AccessControlContext is allocated in the same space as the thread, so no exception can occur */
contextObject = vmThread->threadObject;
if (NULL != contextObject) {
contextObject = J9VMJAVALANGTHREAD_INHERITEDACCESSCONTROLCONTEXT(vmThread, contextObject);
}
#endif /* JAVA_SPEC_VERSION < 24 */
/* Walk the stack, caching the constant pools of the frames. */
walkState.skipCount = startingFrame + 1; /* skip this JNI frame as well */
walkState.userData1 = STACK_WALK_STATE_MAGIC; /* set to NULL when a limited doPrivileged frame is discovered */
Expand Down Expand Up @@ -1821,7 +1822,7 @@ storePDobjectsHelper(J9VMThread* vmThread, J9Class* arrayClass, J9StackWalkState
}
return arrayObject;
}

#endif /* JAVA_SPEC_VERSION < 24 */

jobject JNICALL
Java_java_lang_Class_getNestHostImpl(JNIEnv *env, jobject recv)
Expand Down

0 comments on commit 2bf463b

Please sign in to comment.