X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=org.argeo.app.core%2Fsrc%2Forg%2Fargeo%2Fapp%2Fcore%2FSuiteUtils.java;h=da794cb0cd424aa74412a3b9a3d00102833d6bb3;hb=932dbdce11c1a862b6a7babcb91bfec8e491e0b8;hp=46cb5de43698b08cebac9364569fd29043f22332;hpb=330996fb36d95edaf30d0dc2086aa549155464c3;p=gpl%2Fargeo-suite.git diff --git a/org.argeo.app.core/src/org/argeo/app/core/SuiteUtils.java b/org.argeo.app.core/src/org/argeo/app/core/SuiteUtils.java index 46cb5de..da794cb 100644 --- a/org.argeo.app.core/src/org/argeo/app/core/SuiteUtils.java +++ b/org.argeo.app.core/src/org/argeo/app/core/SuiteUtils.java @@ -1,6 +1,7 @@ package org.argeo.app.core; import java.util.HashSet; +import java.util.Optional; import java.util.Set; import javax.jcr.Node; @@ -9,16 +10,17 @@ import javax.jcr.Session; import javax.jcr.nodetype.NodeType; import javax.jcr.security.Privilege; import javax.security.auth.x500.X500Principal; +import javax.xml.namespace.QName; +import org.argeo.api.acr.Content; +import org.argeo.api.acr.ldap.LdapAttr; +import org.argeo.api.acr.ldap.LdapObj; import org.argeo.api.cms.CmsConstants; import org.argeo.api.cms.CmsSession; import org.argeo.app.api.EntityType; -import org.argeo.app.api.SuiteRole; -import org.argeo.cms.auth.RoleNameUtils; -import org.argeo.jackrabbit.security.JackrabbitSecurityUtils; +import org.argeo.cms.RoleNameUtils; import org.argeo.jcr.JcrException; import org.argeo.jcr.JcrUtils; -import org.argeo.util.naming.LdapAttrs; /** Utilities around the Argeo Suite APIs. */ public class SuiteUtils { @@ -38,11 +40,11 @@ public class SuiteUtils { userNode = usersBase.addNode(uid, NodeType.NT_UNSTRUCTURED); userNode.addMixin(EntityType.user.get()); userNode.addMixin(NodeType.MIX_CREATED); - userNode.setProperty(LdapAttrs.distinguishedName.property(), userDn.toString()); - userNode.setProperty(LdapAttrs.uid.property(), uid); + userNode.setProperty(LdapAttr.distinguishedName.property(), userDn.toString()); + userNode.setProperty(LdapAttr.uid.property(), uid); adminSession.save(); - JackrabbitSecurityUtils.denyPrivilege(adminSession, userNode.getPath(), SuiteRole.coworker.dn(), - Privilege.JCR_READ); +// JackrabbitSecurityUtils.denyPrivilege(adminSession, userNode.getPath(), SuiteRole.coworker.dn(), +// Privilege.JCR_READ); JcrUtils.addPrivilege(adminSession, userNode.getPath(), new X500Principal(userDn.toString()).getName(), Privilege.JCR_READ); JcrUtils.addPrivilege(adminSession, userNode.getPath(), CmsConstants.ROLE_USER_ADMIN, @@ -98,11 +100,6 @@ public class SuiteUtils { } } - /** Singleton. */ - private SuiteUtils() { - - } - public static Set extractRoles(String[] semiColArr) { Set res = new HashSet<>(); // TODO factorize and make it more robust @@ -123,4 +120,33 @@ public class SuiteUtils { return res; } + synchronized static public long findNextId(Content hierarchyUnit, QName cclass) { + if (!hierarchyUnit.hasContentClass(LdapObj.posixGroup.qName())) + throw new IllegalArgumentException(hierarchyUnit + " is not a POSIX group"); + + long min = hierarchyUnit.get(LdapAttr.gidNumber.qName(), Long.class).orElseThrow(); + long currentMax = 0l; + for (Content childHu : hierarchyUnit) { + if (!childHu.hasContentClass(LdapObj.organizationalUnit.qName())) + continue; + // FIXME filter out functional hierarchy unit + for (Content role : childHu) { + if (role.hasContentClass(cclass)) { + + if (LdapObj.posixAccount.qName().equals(cclass)) { + Long id = role.get(LdapAttr.uidNumber.qName(), Long.class).orElseThrow(); + if (id > currentMax) + currentMax = id; + } + } + } + } + if (currentMax == 0l) + return min; + return currentMax + 1; + } + + /** Singleton. */ + private SuiteUtils() { + } }