55use UnityWebPortal \lib \exceptions \EntryNotFoundException ;
66use PHPOpenLDAPer \LDAPConn ;
77use PHPOpenLDAPer \LDAPEntry ;
8+ use UnityWebPortal \lib \PosixGroup ;
9+
10+ enum UserFlag: string
11+ {
12+ case ADMIN = "admin " ;
13+ case GHOST = "ghost " ;
14+ case IDLELOCKED = "idlelocked " ;
15+ case LOCKED = "locked " ;
16+ case QUALIFIED = "qualified " ;
17+ }
818
919/**
1020 * An LDAP connection class which extends LDAPConn tailored for the UnityHPC Platform
@@ -35,8 +45,8 @@ class UnityLDAP extends LDAPConn
3545 private LDAPEntry $ groupOU ;
3646 private LDAPEntry $ pi_groupOU ;
3747 private LDAPEntry $ org_groupOU ;
38- private LDAPEntry $ adminGroup ;
39- private LDAPEntry $ qualifiedUserGroup ;
48+
49+ public array $ userFlagGroups ;
4050
4151 public function __construct ()
4252 {
@@ -46,8 +56,11 @@ public function __construct()
4656 $ this ->groupOU = $ this ->getEntry (CONFIG ["ldap " ]["group_ou " ]);
4757 $ this ->pi_groupOU = $ this ->getEntry (CONFIG ["ldap " ]["pigroup_ou " ]);
4858 $ this ->org_groupOU = $ this ->getEntry (CONFIG ["ldap " ]["orggroup_ou " ]);
49- $ this ->adminGroup = $ this ->getEntry (CONFIG ["ldap " ]["admin_group " ]);
50- $ this ->qualifiedUserGroup = $ this ->getEntry (CONFIG ["ldap " ]["qualified_user_group " ]);
59+ $ this ->userFlagGroups = [];
60+ foreach (UserFlag::cases () as $ flag ) {
61+ $ dn = CONFIG ["ldap " ]["user_flag_groups " ][$ flag ->value ];
62+ $ this ->userFlagGroups [$ flag ->value ] = new PosixGroup (new LDAPEntry ($ this ->conn , $ dn ));
63+ }
5164 }
5265
5366 public function getUserOU (): LDAPEntry
@@ -70,16 +83,6 @@ public function getOrgGroupOU(): LDAPEntry
7083 return $ this ->org_groupOU ;
7184 }
7285
73- public function getAdminGroup (): LDAPEntry
74- {
75- return $ this ->adminGroup ;
76- }
77-
78- public function getQualifiedUserGroup (): LDAPEntry
79- {
80- return $ this ->qualifiedUserGroup ;
81- }
82-
8386 public function getDefUserShell (): string
8487 {
8588 return $ this ->def_user_shell ;
@@ -187,31 +190,11 @@ private function getAllGIDNumbersInUse(): array
187190 );
188191 }
189192
190- public function getQualifiedUsersUIDs (): array
191- {
192- // should not use $user_ou->getChildren or $base_ou->getChildren(objectClass=posixAccount)
193- // qualified users might be outside user ou, and not all users in LDAP tree are qualified users
194- return $ this ->qualifiedUserGroup ->getAttribute ("memberuid " );
195- }
196-
197- public function getQualifiedUsers ($ UnitySQL , $ UnityMailer , $ UnityWebhook ): array
198- {
199- $ out = [];
200-
201- $ qualifiedUsers = $ this ->getQualifiedUsersUIDs ();
202- sort ($ qualifiedUsers );
203- foreach ($ qualifiedUsers as $ user ) {
204- $ params = [$ user , $ this , $ UnitySQL , $ UnityMailer , $ UnityWebhook ];
205- array_push ($ out , new UnityUser (...$ params ));
206- }
207- return $ out ;
208- }
209-
210193 public function getQualifiedUsersAttributes (
211194 array $ attributes ,
212195 array $ default_values = [],
213196 ): array {
214- $ include_uids = $ this ->getQualifiedUsersUIDs ();
197+ $ include_uids = $ this ->userFlagGroups [UserFlag:: QUALIFIED -> value ]-> getMemberUIDs ();
215198 $ user_attributes = $ this ->baseOU ->getChildrenArrayStrict (
216199 $ attributes ,
217200 true , // recursive
@@ -308,7 +291,7 @@ public function getAllPIGroupOwnerAttributes(
308291 public function getQualifiedUID2PIGIDs (): array
309292 {
310293 // initialize output so each UID is a key with an empty array as its value
311- $ uids = $ this ->getQualifiedUsersUIDs ();
294+ $ uids = $ this ->userFlagGroups [UserFlag:: QUALIFIED -> value ]-> getMemberUIDs ();
312295 $ uid2pigids = array_combine ($ uids , array_fill (0 , count ($ uids ), []));
313296 // for each PI group, append that GID to the member list for each of its member UIDs
314297 foreach (
0 commit comments