1 package org
.argeo
.app
.core
;
3 import java
.util
.HashSet
;
6 import javax
.xml
.namespace
.QName
;
8 import org
.argeo
.api
.acr
.Content
;
9 import org
.argeo
.api
.acr
.ldap
.LdapAttr
;
10 import org
.argeo
.api
.acr
.ldap
.LdapObj
;
11 import org
.argeo
.app
.api
.EntityType
;
12 import org
.argeo
.cms
.RoleNameUtils
;
14 /** Utilities around the Argeo Suite APIs. */
15 public class SuiteUtils
{
16 public final static String USER_STATE_NODE_NAME
= "state";
17 public final static String USER_DEVICES_NODE_NAME
= "devices";
18 public final static String USER_SESSIONS_NODE_NAME
= "sessions";
20 public static String
getUserNodePath(String userDn
) {
21 String uid
= RoleNameUtils
.getLastRdnValue(userDn
);
22 return EntityType
.user
.basePath() + '/' + uid
;
25 public static Set
<String
> extractRoles(String
[] semiColArr
) {
26 Set
<String
> res
= new HashSet
<>();
27 // TODO factorize and make it more robust
28 final String rolesPrefix
= "roles:=\"";
29 // first one is layer id
30 for (int i
= 1; i
< semiColArr
.length
; i
++) {
31 if (semiColArr
[i
].startsWith(rolesPrefix
)) {
32 String rolesStr
= semiColArr
[i
].substring(rolesPrefix
.length());
34 rolesStr
= rolesStr
.substring(0, rolesStr
.lastIndexOf('\"'));
35 // TODO support AND (&) as well
36 String
[] roles
= rolesStr
.split("\\|");// OR (|)
37 for (String role
: roles
) {
45 synchronized static public long findNextId(Content hierarchyUnit
, QName cclass
) {
46 if (!hierarchyUnit
.hasContentClass(LdapObj
.posixGroup
.qName()))
47 throw new IllegalArgumentException(hierarchyUnit
+ " is not a POSIX group");
49 long min
= hierarchyUnit
.get(LdapAttr
.gidNumber
.qName(), Long
.class).orElseThrow();
51 for (Content childHu
: hierarchyUnit
) {
52 if (!childHu
.hasContentClass(LdapObj
.organizationalUnit
.qName()))
54 // FIXME filter out functional hierarchy unit
55 for (Content role
: childHu
) {
56 if (role
.hasContentClass(cclass
)) {
58 if (LdapObj
.posixAccount
.qName().equals(cclass
)) {
59 Long id
= role
.get(LdapAttr
.uidNumber
.qName(), Long
.class).orElseThrow();
68 return currentMax
+ 1;
72 private SuiteUtils() {