From 242098dba4f7b96f4b120f8a7aa151b7e4b2ce77 Mon Sep 17 00:00:00 2001 From: Mathieu Baudier Date: Fri, 17 Jun 2022 12:12:51 +0200 Subject: [PATCH] People management based on ACR --- org.argeo.app.ui/OSGI-INF/peopleEntryArea.xml | 1 + .../config/peopleLayer.properties | 2 +- .../config/personUiProvider.properties | 2 +- .../src/org/argeo/app/ui/SuiteApp.java | 43 ++++++++--- .../argeo/app/ui/people/PersonUiProvider.java | 71 ++++++++++--------- .../argeo/app/ui/people/UsersEntryArea.java | 7 ++ 6 files changed, 83 insertions(+), 43 deletions(-) diff --git a/org.argeo.app.ui/OSGI-INF/peopleEntryArea.xml b/org.argeo.app.ui/OSGI-INF/peopleEntryArea.xml index 6cf2f9a..45c8efc 100644 --- a/org.argeo.app.ui/OSGI-INF/peopleEntryArea.xml +++ b/org.argeo.app.ui/OSGI-INF/peopleEntryArea.xml @@ -7,4 +7,5 @@ + diff --git a/org.argeo.app.ui/config/peopleLayer.properties b/org.argeo.app.ui/config/peopleLayer.properties index adadb7b..3bc6d8b 100644 --- a/org.argeo.app.ui/config/peopleLayer.properties +++ b/org.argeo.app.ui/config/peopleLayer.properties @@ -4,4 +4,4 @@ icon=people weights=5000,5000 title=%people -entity.type=entity:person \ No newline at end of file +entity.type=ldap:inetOrgPerson,ldap:groupOfNames \ No newline at end of file diff --git a/org.argeo.app.ui/config/personUiProvider.properties b/org.argeo.app.ui/config/personUiProvider.properties index 8c40c7d..249b453 100644 --- a/org.argeo.app.ui/config/personUiProvider.properties +++ b/org.argeo.app.ui/config/personUiProvider.properties @@ -1,3 +1,3 @@ service.pid=argeo.people.ui.personUiProvider -entity.type=entity:person \ No newline at end of file +entity.type=ldap:inetOrgPerson,ldap:groupOfNames \ No newline at end of file diff --git a/org.argeo.app.ui/src/org/argeo/app/ui/SuiteApp.java b/org.argeo.app.ui/src/org/argeo/app/ui/SuiteApp.java index 8bbe7d3..2298145 100644 --- a/org.argeo.app.ui/src/org/argeo/app/ui/SuiteApp.java +++ b/org.argeo.app.ui/src/org/argeo/app/ui/SuiteApp.java @@ -1,6 +1,7 @@ package org.argeo.app.ui; import static org.argeo.api.cms.CmsView.CMS_VIEW_UID_PROPERTY; +import static org.argeo.cms.acr.ContentUtils.SLASH; import java.util.Collections; import java.util.HashMap; @@ -18,6 +19,7 @@ import javax.jcr.RepositoryException; import javax.jcr.nodetype.NodeType; import javax.naming.InvalidNameException; import javax.naming.ldap.LdapName; +import javax.xml.namespace.QName; import org.argeo.api.acr.Content; import org.argeo.api.acr.ContentRepository; @@ -37,6 +39,8 @@ import org.argeo.cms.AbstractCmsApp; import org.argeo.cms.CmsUserManager; import org.argeo.cms.LocaleUtils; import org.argeo.cms.Localized; +import org.argeo.cms.acr.CmsContentRepository; +import org.argeo.cms.acr.ContentUtils; import org.argeo.cms.jcr.CmsJcrUtils; import org.argeo.cms.jcr.acr.JcrContent; import org.argeo.cms.swt.CmsSwtUtils; @@ -45,6 +49,8 @@ import org.argeo.cms.ui.CmsUiProvider; import org.argeo.cms.ux.CmsUxUtils; import org.argeo.eclipse.ui.specific.UiContext; import org.argeo.jcr.JcrException; +import org.argeo.osgi.useradmin.LdapNameUtils; +import org.argeo.osgi.useradmin.UserDirectory; import org.argeo.util.LangUtils; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Composite; @@ -351,7 +357,22 @@ public class SuiteApp extends AbstractCmsApp implements EventHandler { } } else { - throw new UnsupportedOperationException("Content " + content.getClass().getName() + " is not supported."); + + List objectClasses = content.getTypes(); + Set types = new TreeSet<>(); + for (QName cc : objectClasses) { + String type = cc.getPrefix() + ":" + cc.getLocalPart(); + if (byType.containsKey(type)) + types.add(type); + } + if (types.size() == 0) + throw new IllegalArgumentException("No type found for " + content + " (" + objectClasses + ")"); + String type = types.iterator().next(); + if (!byType.containsKey(type)) + throw new IllegalArgumentException("No component found for " + content + " with type " + type); + return byType.get(type).get(); + // throw new UnsupportedOperationException("Content " + + // content.getClass().getName() + " is not supported."); } } @@ -558,15 +579,19 @@ public class SuiteApp extends AbstractCmsApp implements EventHandler { User user = cmsUserManager.getUser(username); if (user == null) return null; - LdapName userDn; - try { - userDn = new LdapName(user.getName()); - } catch (InvalidNameException e) { - throw new IllegalArgumentException("Badly formatted username", e); - } - String userNodePath = SuiteUtils.getUserNodePath(userDn); + UserDirectory userDirectory = cmsUserManager.getUserDirectory(user); + path = CmsContentRepository.DIRECTORY_BASE + SLASH + userDirectory.getBasePath() + SLASH + + LdapNameUtils.toRevertPath(username, userDirectory.getBasePath()); + node = contentSession.get(path); +// LdapName userDn; +// try { +// userDn = new LdapName(user.getName()); +// } catch (InvalidNameException e) { +// throw new IllegalArgumentException("Badly formatted username", e); +// } +// String userNodePath = SuiteUtils.getUserNodePath(userDn); // FIXME deal with home path - return null; +// return null; // if (Jcr.itemExists(session, userNodePath)) // node = Jcr.getNode(session, userNodePath); // else { diff --git a/org.argeo.app.ui/src/org/argeo/app/ui/people/PersonUiProvider.java b/org.argeo.app.ui/src/org/argeo/app/ui/people/PersonUiProvider.java index 24b0893..4cf2294 100644 --- a/org.argeo.app.ui/src/org/argeo/app/ui/people/PersonUiProvider.java +++ b/org.argeo.app.ui/src/org/argeo/app/ui/people/PersonUiProvider.java @@ -4,23 +4,21 @@ import java.util.Arrays; import java.util.List; import java.util.Map; -import javax.jcr.Node; -import javax.jcr.RepositoryException; - +import org.argeo.api.acr.Content; import org.argeo.app.ui.SuiteMsg; import org.argeo.app.ui.SuiteUiUtils; import org.argeo.cms.CmsUserManager; import org.argeo.cms.swt.CmsSwtUtils; +import org.argeo.cms.swt.widgets.SwtSection; import org.argeo.cms.ui.CmsUiProvider; -import org.argeo.cms.ui.viewers.Section; import org.argeo.util.naming.LdapAttrs; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Text; +import org.osgi.service.useradmin.Group; import org.osgi.service.useradmin.User; /** Edit a suite user. */ @@ -29,45 +27,54 @@ public class PersonUiProvider implements CmsUiProvider { private CmsUserManager cmsUserManager; @Override - public Control createUi(Composite parent, Node context) throws RepositoryException { - Section main = new Section(parent, SWT.NONE, context); + public Control createUiPart(Composite parent, Content context) { + SwtSection main = new SwtSection(parent, SWT.NONE, context); main.setLayoutData(CmsSwtUtils.fillAll()); - String uid = context.getName(); - User user = cmsUserManager.getUserFromLocalId(uid); + User user = context.adapt(User.class); + + if (user instanceof Group) { + String cn = context.getName().getLocalPart().split("=")[1]; + Text cnT = SuiteUiUtils.addFormLine(main, "uid", getUserProperty(user, LdapAttrs.uid.name())); + cnT.setText(cn); + + } else { + String uid = context.getName().getLocalPart().split("=")[1]; // Text givenName = new Text(main, SWT.SINGLE); // givenName.setText(getUserProperty(user, LdapAttrs.givenName.name())); - Text givenName = SuiteUiUtils.addFormInput(main, SuiteMsg.firstName.lead(), - getUserProperty(user, LdapAttrs.givenName.name())); + Text givenName = SuiteUiUtils.addFormInput(main, SuiteMsg.firstName.lead(), + getUserProperty(user, LdapAttrs.givenName.name())); - Text sn = SuiteUiUtils.addFormInput(main, SuiteMsg.lastName.lead(), getUserProperty(user, LdapAttrs.sn.name())); - // sn.setText(getUserProperty(user, LdapAttrs.sn.name())); + Text sn = SuiteUiUtils.addFormInput(main, SuiteMsg.lastName.lead(), + getUserProperty(user, LdapAttrs.sn.name())); + // sn.setText(getUserProperty(user, LdapAttrs.sn.name())); - Text email = SuiteUiUtils.addFormInput(main, SuiteMsg.email.lead(), - getUserProperty(user, LdapAttrs.mail.name())); - // email.setText(getUserProperty(user, LdapAttrs.mail.name())); + Text email = SuiteUiUtils.addFormInput(main, SuiteMsg.email.lead(), + getUserProperty(user, LdapAttrs.mail.name())); + // email.setText(getUserProperty(user, LdapAttrs.mail.name())); - Text uidT = SuiteUiUtils.addFormLine(main, "uid", getUserProperty(user, LdapAttrs.uid.name())); - uidT.setText(uid); + Text uidT = SuiteUiUtils.addFormLine(main, "uid", getUserProperty(user, LdapAttrs.uid.name())); + uidT.setText(uid); // Label dnL = new Label(main, SWT.NONE); // dnL.setText(user.getName()); - // roles - // Section rolesSection = new Section(main, SWT.NONE, context); - Group rolesSection = new Group(main, SWT.NONE); - rolesSection.setText("Roles"); - rolesSection.setLayoutData(CmsSwtUtils.fillWidth()); - rolesSection.setLayout(new GridLayout()); - // new Label(rolesSection, SWT.NONE).setText("Roles:"); - List roles = Arrays.asList(cmsUserManager.getUserRoles(user.getName())); - for (String role : availableRoles) { - // new Label(rolesSection, SWT.NONE).setText(role); - Button radio = new Button(rolesSection, SWT.CHECK); - radio.setText(role); - if (roles.contains(role)) - radio.setSelection(true); + // roles + // Section rolesSection = new Section(main, SWT.NONE, context); + Composite rolesSection = new Composite(main, SWT.NONE); + // rolesSection.setText("Roles"); + rolesSection.setLayoutData(CmsSwtUtils.fillWidth()); + rolesSection.setLayout(new GridLayout()); + // new Label(rolesSection, SWT.NONE).setText("Roles:"); + List roles = Arrays.asList(cmsUserManager.getUserRoles(user.getName())); + for (String role : availableRoles) { + // new Label(rolesSection, SWT.NONE).setText(role); + Button radio = new Button(rolesSection, SWT.CHECK); + radio.setText(role); + if (roles.contains(role)) + radio.setSelection(true); + } } return main; diff --git a/org.argeo.app.ui/src/org/argeo/app/ui/people/UsersEntryArea.java b/org.argeo.app.ui/src/org/argeo/app/ui/people/UsersEntryArea.java index 14e4b26..6d64fbc 100644 --- a/org.argeo.app.ui/src/org/argeo/app/ui/people/UsersEntryArea.java +++ b/org.argeo.app.ui/src/org/argeo/app/ui/people/UsersEntryArea.java @@ -7,6 +7,7 @@ import javax.jcr.Node; import javax.jcr.RepositoryException; import org.argeo.api.acr.Content; +import org.argeo.api.acr.ContentRepository; import org.argeo.api.cms.CmsTheme; import org.argeo.api.cms.CmsView; import org.argeo.app.ui.SuiteEvent; @@ -45,6 +46,8 @@ public class UsersEntryArea implements SwtUiProvider, CmsUiProvider { private CmsUserManager cmsUserManager; + private ContentRepository contentRepository; + @Override public Control createUiPart(Composite parent, Content context) { CmsTheme theme = CmsSwtUtils.getCmsTheme(parent); @@ -175,4 +178,8 @@ public class UsersEntryArea implements SwtUiProvider, CmsUiProvider { return createUiPart(parent, JcrContent.nodeToContent(context)); } + public void setContentRepository(ContentRepository contentRepository) { + this.contentRepository = contentRepository; + } + } -- 2.30.2