import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.util.HashSet;
+import java.util.Iterator;
import java.util.Locale;
import java.util.Set;
import java.util.UUID;
return roles.contains(role);
}
+ /** Implies this {@link SystemRole} in this context. */
+ public final static boolean implies(SystemRole role, String context) {
+ return role.implied(currentSubject(), context);
+ }
+
/** Executes as the current user */
public final static <T> T doAs(PrivilegedAction<T> action) {
return Subject.doAs(currentSubject(), action);
public static CmsSession getCmsSession() {
Subject subject = currentSubject();
- CmsSessionId cmsSessionId = subject.getPrivateCredentials(CmsSessionId.class).iterator().next();
+ Iterator<CmsSessionId> it = subject.getPrivateCredentials(CmsSessionId.class).iterator();
+ if (!it.hasNext())
+ throw new IllegalStateException("No CMS session id available for " + subject);
+ CmsSessionId cmsSessionId = it.next();
+ if (it.hasNext())
+ throw new IllegalStateException("More than one CMS session id available for " + subject);
return CmsContextImpl.getCmsContext().getCmsSessionByUuid(cmsSessionId.getUuid());
}
}
/*
- * PREPARE EVOLUTION OF JAVA APIs INTRODUCED IN JDK 18
- * The following static methods will be added to Subject
+ * PREPARE EVOLUTION OF JAVA APIs INTRODUCED IN JDK 18 The following static
+ * methods will be added to Subject
*/
public Subject current() {
return currentSubject();