Skip to content

Commit

Permalink
Merge pull request #20430 from JinhangZhang/compat
Browse files Browse the repository at this point in the history
Update doPrivilegedWithCombinerHelper function
  • Loading branch information
keithc-ca authored Jan 31, 2025
2 parents ad482ed + eed4ec4 commit 24960fd
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -318,37 +318,49 @@ public AccessControlContext(ProtectionDomain[] fromContext) {
}

AccessControlContext(ProtectionDomain[] context, int authorizeState) {
super();
switch (authorizeState) {
default:
// authorizeState can't be STATE_UNKNOWN, callerPD always is NULL
throw new IllegalArgumentException();
case STATE_AUTHORIZED:
case STATE_NOT_AUTHORIZED:
break;
}
this.context = context;
this.authorizeState = authorizeState;
this.containPrivilegedContext = true;
this(context, null, null, authorizeState);
}

AccessControlContext(AccessControlContext acc, ProtectionDomain[] context, int authorizeState) {
this(context, null, acc, authorizeState);
}

AccessControlContext(ProtectionDomain[] context, AccessControlContext parentAcc, AccessControlContext acc, int authorizeState) {
super();
switch (authorizeState) {
default:
// authorizeState can't be STATE_UNKNOWN, callerPD always is NULL
// authorizeState can't be STATE_UNKNOWN, callerPD is always NULL
throw new IllegalArgumentException();
case STATE_AUTHORIZED:
if (null != acc) {
// inherit the domain combiner when authorized
this.domainCombiner = acc.domainCombiner;
if (acc != null) {
if (parentAcc == null) {
// inherit the domain combiner when authorized
this.domainCombiner = acc.domainCombiner;
this.context = context;
} else {
// when parent combiner is not null, use parent combiner to combine the current context
DomainCombiner parentCombiner = parentAcc.getCombiner();
if (parentCombiner != null) {
this.context = parentCombiner.combine(context, acc.context);
this.domainCombiner = parentCombiner;
} else {
this.context = combinePDObjs(context, acc.context);
this.domainCombiner = acc.domainCombiner;
}
}
} else {
if (parentAcc != null) {
this.domainCombiner = parentAcc.domainCombiner;
this.nextStackAcc = parentAcc;
}
this.context = context;
}
break;
case STATE_NOT_AUTHORIZED:
this.context = context;
break;
}
this.doPrivilegedAcc = acc;
this.context = context;
this.authorizeState = authorizeState;
this.containPrivilegedContext = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1088,21 +1088,17 @@ public static <T> T doPrivilegedWithCombiner(PrivilegedExceptionAction<T> action
/**
* Helper method to construct an AccessControlContext for doPrivilegedWithCombiner methods.
*
* @param context an AccessControlContext, if it is null, use getContextHelper() to construct a context.
* @param acc an AccessControlContext, if it is null, use getContextHelper() to construct a context.
*
* @return An AccessControlContext to be applied to the doPrivileged(action, context, perms).
*/
@CallerSensitive
private static AccessControlContext doPrivilegedWithCombinerHelper(AccessControlContext context) {
private static AccessControlContext doPrivilegedWithCombinerHelper(AccessControlContext acc) {
ProtectionDomain domain = getCallerPD(2);
ProtectionDomain[] pdArray = (domain == null) ? null : new ProtectionDomain[] { domain };
AccessControlContext fixedContext = new AccessControlContext(context, pdArray, getNewAuthorizedState(context, domain));
if (context == null) {
AccessControlContext parentContext = getContextHelper(true);
fixedContext.domainCombiner = parentContext.domainCombiner;
fixedContext.nextStackAcc = parentContext;
}
return fixedContext;
ProtectionDomain[] context = (domain == null) ? null : new ProtectionDomain[] { domain };
AccessControlContext parentAcc = getContextHelper(acc == null);

return new AccessControlContext(context, parentAcc, acc, getNewAuthorizedState(acc, domain));
}
/*[ENDIF] JAVA_SPEC_VERSION < 24 */

Expand Down

0 comments on commit 24960fd

Please sign in to comment.