From: Mathieu Baudier Date: Fri, 10 Jul 2020 10:13:31 +0000 (+0200) Subject: Introduce CMS Ego app, providing canonical information on any logged-in X-Git-Tag: argeo-commons-2.1.89~107 X-Git-Url: https://git.argeo.org/?p=lgpl%2Fargeo-commons.git;a=commitdiff_plain;h=1e077d22f485d504491e65579258925b53bf1a3c Introduce CMS Ego app, providing canonical information on any logged-in user. --- diff --git a/org.argeo.cms.e4.rap/src/org/argeo/cms/e4/rap/CmsE4AdminApp.java b/org.argeo.cms.e4.rap/src/org/argeo/cms/e4/rap/CmsE4AdminApp.java index 0650274c5..66be1e8e9 100644 --- a/org.argeo.cms.e4.rap/src/org/argeo/cms/e4/rap/CmsE4AdminApp.java +++ b/org.argeo.cms.e4.rap/src/org/argeo/cms/e4/rap/CmsE4AdminApp.java @@ -1,10 +1,17 @@ package org.argeo.cms.e4.rap; +import org.eclipse.rap.rwt.application.Application; + +/** + * Access to canonical views of the core CMS concepts, useful for devleopers and + * operators. + */ public class CmsE4AdminApp extends AbstractRapE4App { - public CmsE4AdminApp() { - setPageTitle("Argeo CMS DevOps"); - setE4Xmi("org.argeo.cms.e4/e4xmi/cms-devops.e4xmi"); - setPath("/devops"); + @Override + protected void addEntryPoints(Application application) { + addE4EntryPoint(application, "/devops", "org.argeo.cms.e4/e4xmi/cms-devops.e4xmi", + customise("Argeo CMS DevOps")); + addE4EntryPoint(application, "/ego", "org.argeo.cms.e4/e4xmi/cms-ego.e4xmi", customise("Argeo CMS Ego")); } } diff --git a/org.argeo.cms.e4/e4xmi/cms-ego.e4xmi b/org.argeo.cms.e4/e4xmi/cms-ego.e4xmi new file mode 100644 index 000000000..ef659fcc7 --- /dev/null +++ b/org.argeo.cms.e4/e4xmi/cms-ego.e4xmi @@ -0,0 +1,67 @@ + + + + + shellMaximized + auth.cn=user,ou=roles,ou=node + + + + + + + + + + + ViewMenu + + + + + + + + + + dataExplorer + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.argeo.cms.e4/src/org/argeo/cms/e4/handlers/ChangePassword.java b/org.argeo.cms.e4/src/org/argeo/cms/e4/handlers/ChangePassword.java index 51528abd4..52756376b 100644 --- a/org.argeo.cms.e4/src/org/argeo/cms/e4/handlers/ChangePassword.java +++ b/org.argeo.cms.e4/src/org/argeo/cms/e4/handlers/ChangePassword.java @@ -6,24 +6,22 @@ import static org.argeo.cms.CmsMsg.newPassword; import static org.argeo.cms.CmsMsg.passwordChanged; import static org.argeo.cms.CmsMsg.repeatNewPassword; -import java.security.AccessController; import java.util.Arrays; import javax.inject.Inject; import javax.naming.InvalidNameException; import javax.naming.ldap.LdapName; -import javax.security.auth.Subject; -import javax.security.auth.x500.X500Principal; import javax.transaction.UserTransaction; import org.argeo.api.security.CryptoKeyring; import org.argeo.cms.CmsException; +import org.argeo.cms.auth.CurrentUser; import org.argeo.cms.ui.dialogs.CmsMessageDialog; import org.argeo.eclipse.ui.dialogs.ErrorFeedback; import org.eclipse.e4.core.di.annotations.Execute; +import org.eclipse.e4.core.di.annotations.Optional; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Point; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; @@ -35,12 +33,14 @@ import org.eclipse.swt.widgets.Text; import org.osgi.service.useradmin.User; import org.osgi.service.useradmin.UserAdmin; +/** Change the password of the logged-in user. */ public class ChangePassword { @Inject private UserAdmin userAdmin; @Inject private UserTransaction userTransaction; @Inject + @Optional private CryptoKeyring keyring = null; @Execute @@ -53,8 +53,7 @@ public class ChangePassword { } protected void changePassword(char[] oldPassword, char[] newPassword) { - Subject subject = Subject.getSubject(AccessController.getContext()); - String name = subject.getPrincipals(X500Principal.class).iterator().next().toString(); + String name = CurrentUser.getUsername(); LdapName dn; try { dn = new LdapName(name); @@ -94,9 +93,9 @@ public class ChangePassword { super(parentShell, changePassword.lead(), CONFIRM); } - protected Point getInitialSize() { - return new Point(400, 450); - } +// protected Point getInitialSize() { +// return new Point(400, 450); +// } protected Control createDialogArea(Composite parent) { Composite dialogarea = (Composite) super.createDialogArea(parent); @@ -108,7 +107,7 @@ public class ChangePassword { newPassword1 = createLP(composite, newPassword.lead()); newPassword2 = createLP(composite, repeatNewPassword.lead()); - parent.pack(); +// parent.pack(); oldPassword.setFocus(); return composite; } diff --git a/org.argeo.cms.e4/src/org/argeo/cms/e4/parts/EgoDashboard.java b/org.argeo.cms.e4/src/org/argeo/cms/e4/parts/EgoDashboard.java new file mode 100644 index 000000000..8499356dc --- /dev/null +++ b/org.argeo.cms.e4/src/org/argeo/cms/e4/parts/EgoDashboard.java @@ -0,0 +1,47 @@ +package org.argeo.cms.e4.parts; + +import static org.argeo.cms.ui.util.CmsUiUtils.lbl; +import static org.argeo.cms.ui.util.CmsUiUtils.txt; + +import java.security.AccessController; +import java.time.ZonedDateTime; + +import javax.annotation.PostConstruct; +import javax.security.auth.Subject; + +import org.argeo.cms.auth.CmsSession; +import org.argeo.cms.auth.CurrentUser; +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(); + + lbl(p, "" + CurrentUser.getDisplayName() + ""); + txt(p, username); + lbl(p, "Roles:"); + roles: for (String role : CurrentUser.roles()) { + if (username.equals(role)) + continue roles; + txt(p, role); + } + + Subject subject = Subject.getSubject(AccessController.getContext()); + if (subject != null) { + CmsSession cmsSession = CmsSession.getCmsSession(bc, subject); + ZonedDateTime loggedIndSince = cmsSession.getCreationTime(); + lbl(p, "Session:"); + txt(p, cmsSession.getUuid().toString()); + lbl(p, "Logged in since:"); + txt(p, loggedIndSince.toString()); + } + } +} diff --git a/org.argeo.cms.ui.theme/icons/actions/edit.png b/org.argeo.cms.ui.theme/icons/actions/edit.png new file mode 100644 index 000000000..ad3db9f42 Binary files /dev/null and b/org.argeo.cms.ui.theme/icons/actions/edit.png differ diff --git a/org.argeo.cms.ui/src/org/argeo/cms/ui/dialogs/CmsMessageDialog.java b/org.argeo.cms.ui/src/org/argeo/cms/ui/dialogs/CmsMessageDialog.java index eb50ef2f3..ba04b645b 100644 --- a/org.argeo.cms.ui/src/org/argeo/cms/ui/dialogs/CmsMessageDialog.java +++ b/org.argeo.cms.ui/src/org/argeo/cms/ui/dialogs/CmsMessageDialog.java @@ -18,6 +18,7 @@ import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Shell; +/** Base class for dialogs displaying messages or small forms. */ public class CmsMessageDialog extends LightweightDialog { public final static int INFORMATION = 2; public final static int QUESTION = 3; diff --git a/org.argeo.cms.ui/src/org/argeo/cms/ui/jcr/JcrImages.java b/org.argeo.cms.ui/src/org/argeo/cms/ui/jcr/JcrImages.java index d86edb537..4ac70a9c3 100644 --- a/org.argeo.cms.ui/src/org/argeo/cms/ui/jcr/JcrImages.java +++ b/org.argeo.cms.ui/src/org/argeo/cms/ui/jcr/JcrImages.java @@ -24,7 +24,7 @@ public class JcrImages { public final static Image FOLDER = CmsImages.createIcon("folder.gif"); public final static Image FILE = CmsImages.createIcon("file.gif"); public final static Image BINARY = CmsImages.createIcon("binary.png"); - public final static Image HOME = CmsImages.createIcon("home.gif"); + public final static Image HOME = CmsImages.createIcon("person-logged-in.png"); public final static Image SORT = CmsImages.createIcon("sort.gif"); public final static Image REMOVE = CmsImages.createIcon("remove.gif"); diff --git a/org.argeo.cms.ui/src/org/argeo/cms/ui/jcr/model/WorkspaceElem.java b/org.argeo.cms.ui/src/org/argeo/cms/ui/jcr/model/WorkspaceElem.java index 45cda80ee..b989b9106 100644 --- a/org.argeo.cms.ui/src/org/argeo/cms/ui/jcr/model/WorkspaceElem.java +++ b/org.argeo.cms.ui/src/org/argeo/cms/ui/jcr/model/WorkspaceElem.java @@ -15,6 +15,7 @@ */ package org.argeo.cms.ui.jcr.model; +import javax.jcr.AccessDeniedException; import javax.jcr.Node; import javax.jcr.NodeIterator; import javax.jcr.RepositoryException; @@ -55,8 +56,7 @@ public class WorkspaceElem extends TreeParent { else return null; } catch (RepositoryException e) { - throw new EclipseUiException("Cannot get root node of workspace " - + getName(), e); + throw new EclipseUiException("Cannot get root node of workspace " + getName(), e); } } @@ -64,8 +64,7 @@ public class WorkspaceElem extends TreeParent { try { session = ((RepositoryElem) getParent()).repositoryLogin(getName()); } catch (RepositoryException e) { - throw new EclipseUiException("Cannot connect to repository " - + getName(), e); + throw new EclipseUiException("Cannot connect to repository " + getName(), e); } } @@ -93,13 +92,16 @@ public class WorkspaceElem extends TreeParent { public synchronized boolean hasChildren() { try { if (isConnected()) - return session.getRootNode().hasNodes(); + try { + return session.getRootNode().hasNodes(); + } catch (AccessDeniedException e) { + // current user may not have access to the root node + return false; + } else return false; } catch (RepositoryException re) { - throw new EclipseUiException( - "Unexpected error while checking children node existence", - re); + throw new EclipseUiException("Unexpected error while checking children node existence", re); } } @@ -123,9 +125,7 @@ public class WorkspaceElem extends TreeParent { } return super.getChildren(); } catch (RepositoryException e) { - throw new EclipseUiException( - "Cannot initialize WorkspaceNode UI object." - + getName(), e); + throw new EclipseUiException("Cannot initialize WorkspaceNode UI object." + getName(), e); } } } diff --git a/org.argeo.cms.ui/src/org/argeo/cms/ui/util/CmsUiUtils.java b/org.argeo.cms.ui/src/org/argeo/cms/ui/util/CmsUiUtils.java index 39df49ebf..c96e77b62 100644 --- a/org.argeo.cms.ui/src/org/argeo/cms/ui/util/CmsUiUtils.java +++ b/org.argeo.cms.ui/src/org/argeo/cms/ui/util/CmsUiUtils.java @@ -133,21 +133,39 @@ public class CmsUiUtils implements CmsConstants { /** * Apply markup and set text on {@link Label}, {@link Button}, {@link Text}. * + * @param widget the widget to style and to use in order to display text + * @param txt the object to display via its toString() method. + * This argument should not be null, but if it is null and + * assertions are disabled "" is displayed instead; if + * assertions are enabled the call will fail. + * * @see #markup(Widget) */ - public static T text(T widget, String txt) { + public static T text(T widget, Object txt) { + assert txt != null; + String str = txt != null ? txt.toString() : ""; markup(widget); if (widget instanceof Label) - ((Label) widget).setText(txt); + ((Label) widget).setText(str); else if (widget instanceof Button) - ((Button) widget).setText(txt); + ((Button) widget).setText(str); else if (widget instanceof Text) - ((Text) widget).setText(txt); + ((Text) widget).setText(str); else throw new IllegalArgumentException("Unsupported widget type " + widget.getClass()); return widget; } + /** A {@link Label} with markup activated. */ + public static Label lbl(Composite parent, Object txt) { + return text(new Label(parent, SWT.NONE), txt); + } + + /** A read-only {@link Text} whose content can be copy/pasted. */ + public static Text txt(Composite parent, Object txt) { + return text(new Text(parent, SWT.NONE), txt); + } + public static void setItemHeight(Table table, int height) { table.setData(CmsConstants.ITEM_HEIGHT, height); }