X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=org.argeo.app.core%2Fsrc%2Forg%2Fargeo%2Fapp%2Fcore%2FSuiteUtils.java;h=ad4e2ac5e6caf3c7e9e5f90d8c5b2ef546e4b469;hb=170e45e64f3e4cc39ffb92e7a37467bfc879ccad;hp=6b63cdb4d30115e21db16267eb1afd2c5b191cbe;hpb=fabd973af0f3a08b55640a152526eaeba177b128;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 6b63cdb..ad4e2ac 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 @@ -9,24 +9,25 @@ 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.cms.auth.RoleNameUtils; +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 { - @Deprecated public static String getUserNodePath(String userDn) { String uid = RoleNameUtils.getLastRdnValue(userDn); return EntityType.user.basePath() + '/' + uid; } - @Deprecated private static Node getOrCreateUserNode(Session adminSession, String userDn) { try { Node usersBase = adminSession.getNode(EntityType.user.basePath()); @@ -36,8 +37,8 @@ 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.get(), userDn.toString()); + userNode.setProperty(LdapAttr.uid.get(), uid); adminSession.save(); // JackrabbitSecurityUtils.denyPrivilege(adminSession, userNode.getPath(), SuiteRole.coworker.dn(), // Privilege.JCR_READ); @@ -54,7 +55,6 @@ public class SuiteUtils { } } - @Deprecated public static Node getCmsSessionNode(Session session, CmsSession cmsSession) { try { return session.getNode(getUserNodePath(cmsSession.getUserDn()) + '/' + cmsSession.getUuid().toString()); @@ -63,7 +63,6 @@ public class SuiteUtils { } } - @Deprecated public static Node getOrCreateCmsSessionNode(Session adminSession, CmsSession cmsSession) { try { String userDn = cmsSession.getUserDn(); @@ -96,11 +95,6 @@ public class SuiteUtils { } } - /** Singleton. */ - private SuiteUtils() { - - } - public static Set extractRoles(String[] semiColArr) { Set res = new HashSet<>(); // TODO factorize and make it more robust @@ -121,4 +115,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() { + } }