Put Eclipse and JCR components in subdirs in order to clarify indirect
[lgpl/argeo-commons.git] / eclipse / org.argeo.cms.e4 / src / org / argeo / cms / e4 / parts / EgoDashboard.java
diff --git a/eclipse/org.argeo.cms.e4/src/org/argeo/cms/e4/parts/EgoDashboard.java b/eclipse/org.argeo.cms.e4/src/org/argeo/cms/e4/parts/EgoDashboard.java
new file mode 100644 (file)
index 0000000..5a805d1
--- /dev/null
@@ -0,0 +1,46 @@
+package org.argeo.cms.e4.parts;
+
+import java.security.AccessController;
+import java.time.ZonedDateTime;
+
+import javax.annotation.PostConstruct;
+import javax.security.auth.Subject;
+
+import org.argeo.api.cms.CmsSession;
+import org.argeo.cms.auth.CurrentUser;
+import org.argeo.cms.osgi.CmsOsgiUtils;
+import org.argeo.cms.swt.CmsSwtUtils;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.FrameworkUtil;
+
+/** A canonical view of the logged in user. */
+public class EgoDashboard {
+       private BundleContext bc = FrameworkUtil.getBundle(EgoDashboard.class).getBundleContext();
+
+       @PostConstruct
+       public void createPartControl(Composite p) {
+               p.setLayout(new GridLayout());
+               String username = CurrentUser.getUsername();
+
+               CmsSwtUtils.lbl(p, "<strong>" + CurrentUser.getDisplayName() + "</strong>");
+               CmsSwtUtils.txt(p, username);
+               CmsSwtUtils.lbl(p, "Roles:");
+               roles: for (String role : CurrentUser.roles()) {
+                       if (username.equals(role))
+                               continue roles;
+                       CmsSwtUtils.txt(p, role);
+               }
+
+               Subject subject = Subject.getSubject(AccessController.getContext());
+               if (subject != null) {
+                       CmsSession cmsSession = CmsOsgiUtils.getCmsSession(bc, subject);
+                       ZonedDateTime loggedIndSince = cmsSession.getCreationTime();
+                       CmsSwtUtils.lbl(p, "Session:");
+                       CmsSwtUtils.txt(p, cmsSession.getUuid().toString());
+                       CmsSwtUtils.lbl(p, "Logged in since:");
+                       CmsSwtUtils.txt(p, loggedIndSince.toString());
+               }
+       }
+}