X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=org.argeo.cms%2Fsrc%2Forg%2Fargeo%2Fcms%2Fauth%2FCurrentUser.java;h=b43bf98b5f707744591b26006535ca784d8252b7;hb=eb4cc3db3bf141c229f0f7ff929daff108bee6d2;hp=cbe4286921c527651e928eebc552d610d745f90e;hpb=c2366f32052deada7d96f635e86f745f438f094e;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.cms/src/org/argeo/cms/auth/CurrentUser.java b/org.argeo.cms/src/org/argeo/cms/auth/CurrentUser.java index cbe428692..b43bf98b5 100644 --- a/org.argeo.cms/src/org/argeo/cms/auth/CurrentUser.java +++ b/org.argeo.cms/src/org/argeo/cms/auth/CurrentUser.java @@ -9,6 +9,8 @@ import java.util.HashSet; import java.util.Locale; import java.util.Set; import java.util.UUID; +import java.util.concurrent.Callable; +import java.util.concurrent.CompletionException; import javax.security.auth.Subject; import javax.security.auth.x500.X500Principal; @@ -162,6 +164,29 @@ public final class CurrentUser { return true; } + /* + * PREPARE EVOLUTION OF JAVA APIs INTRODUCED IN JDK 18 + * The following static methods will be added to Subject + */ + public Subject current() { + return currentSubject(); + } + + public static T callAs(Subject subject, Callable action) { + try { + return Subject.doAs(subject, new PrivilegedExceptionAction() { + + @Override + public T run() throws Exception { + return action.call(); + } + + }); + } catch (PrivilegedActionException e) { + throw new CompletionException("Failed to execute action for " + subject, e.getCause()); + } + } + private CurrentUser() { } }