- private static Subject currentSubject() {
- Subject subject = Subject.getSubject(AccessController.getContext());
- if (subject != null)
- return subject;
- if (subject == null) {
- CmsView cmsView = CmsUtils.getCmsView();
- if (cmsView != null)
- return cmsView.getSubject();
- }
- throw new CmsException("Cannot find related subject");
+ public static boolean isAnonymous() {
+ return isAnonymous(currentSubject());
+ }
+
+ public static boolean isRegistered() {
+ return !isAnonymous();
+ }
+
+ public static boolean isAnonymous(Subject subject) {
+ if (subject == null)
+ return true;
+ String username = getUsername(subject);
+ return username == null
+ || username.equalsIgnoreCase(NodeConstants.ROLE_ANONYMOUS);
+ }
+
+ /**
+ * The node authenticated component (typically a CMS view) related to this
+ * display, or null if none is available from this call.
+ */
+ public static NodeAuthenticated getNodeAuthenticated() {
+ return UiContext.getData(NodeAuthenticated.KEY);