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;
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();