RFR: 8267108: Alternate Subject.getSubject and doAs APIs that do not depend on Security Manager APIs
Sean Mullan
mullan at openjdk.java.net
Fri Oct 22 21:18:07 UTC 2021
On Thu, 5 Aug 2021 20:10:44 GMT, Weijun Wang <weijun at openjdk.org> wrote:
> New `Subject` APIs `current()` and `callAs()` are created to be replacements of `getSubject()` and `doAs()` since the latter two methods are now deprecated for removal.
>
> In this implementation, by default, `current()` returns the same value as `getSubject(AccessController.getCurrent())` and `callAs()` is implemented based on `doAs()`. This behavior is subject to change in the future once `SecurityManager` is removed.
>
> User can experiment a possible future mechanism by setting the system property `jdk.security.auth.subject.useTL` to `true`, where the `callAs()` method stores the subject into a `ThreadLocal` object and the `current()` method returns it (Note: this mechanism does not work with principal-based permissions).
>
> Inside JDK, we’ve switched from `getSubject()` to `current()` in JGSS and user can start switching to `callAs()` in their applications. Users can also switch to `current()` but please note that if you used to call `getSubject(acc)` in a `doPrivileged` call you might need to try calling `current()` in a `doPrivilegedWithCombiner` call to see if the `AccessControlContext` inside the call inherits the subject from the outer one.
Still reviewing but here are some initial minor comments.
src/java.security.jgss/share/classes/sun/security/jgss/krb5/Krb5Util.java line 67:
> 65:
> 66: @SuppressWarnings("removal")
> 67: Subject accSubj = Subject.current();
Change variable name to `currentSubj` or `currSubj`?
src/java.security.jgss/share/classes/sun/security/jgss/krb5/Krb5Util.java line 68:
> 66: @SuppressWarnings("removal") AccessControlContext acc) throws LoginException {
> 67:
> 68: // Try to get ticket from acc's Subject
Is this comment still helpful? Maybe just change it to `// Try to get ticket from current Subject`
test/jdk/java/security/AccessController/PreserveCombiner.java line 46:
> 44:
> 45: // get subject from current ACC - this always worked
> 46: Subject doAsSubject = Subject.current();
Nit: change variable name to `callAsSubject`.
test/jdk/sun/security/krb5/auto/Context.java line 114:
> 112: }
> 113: });
> 114: } catch (CompletionException pae) {
Maybe rename the variable to `ce`. Same comment below.
-------------
PR: https://git.openjdk.java.net/jdk/pull/5024
More information about the security-dev
mailing list