Core\Ldap\Ad\GroupType::isSecurityGroup
$groupType->isSecurityGroup(): boolChecks if a group is a security group. A security group can be given permissions, for example to a folder or an application. The result is true or false.
A group where isSecurityGroup returns false is a distribution group. Active Directory uses it only as a mailing list, so a program that decides what a person may do should ignore it.
isSecurityGroup reads the bit 0x80000000 of groupType. That bit is the highest one, so the number that bits returns is negative when isSecurityGroup returns true.
Return value
Returns bool. true when the bit is set, and false when it is not.
Changelog
| Version | Change |
|---|---|
0.0.6 | Every Core\Ldap\Ad\GroupType method that checks a flag now starts with is, for example isGlobal() and isSecurityGroup(). The old names were system, global, domainLocal, universal, appBasic, appQuery and security. |
Examples
The examples below run with this configuration file.
# These examples use the LDAP directory server on this computer at port 16636.# `tls_ca_file` is the certificate that the server's certificate is checked against.[ldap.corp]url = "ldaps://127.0.0.1:16636"base = "DC=example,DC=test"user = "CN=Reader,OU=Company,DC=example,DC=test"password = "Novis-reader-1"tls_ca_file = "../../../../../tests/db/ca.crt"timeout = "5s"
# The program may open the `corp` directory.[capabilities.ldap]connect = ["corp"]Keep only security groups
<?nvs// Shows how to keep only the security groups from a search.// requires: samba-ad
var $corp = Core\Ldap::connect('corp');var $found = $corp->search( Core\Ldap\Filter::equals('objectClass', 'group'), { base: 'OU=Company,DC=example,DC=test', select: ['groupType'] },);
array<tainted string> $names = [];foreach ($found as Core\Ldap\Entry $group) { var $type = $group->groupType(); if ($type != null && $type->isSecurityGroup()) { $names[] = $group->dn()->rdnValue(); }}
// The server sends entries in no fixed order, so the names are sorted.// `Newsletter` is a mailing list, so this prints only `Employees` and `Managers`.foreach (Core\Arr::sort($names) as tainted string $name) { echo $name, "\n";}EmployeesManagersA mailing list
<?nvs// Shows that `isSecurityGroup` returns `false` for a distribution group, which is a mailing list.// requires: samba-ad
var $corp = Core\Ldap::connect('corp');var $group = $corp->read('CN=Newsletter,OU=Company,DC=example,DC=test', { select: ['groupType', 'mail'] });var $type = $group?->groupType();
if ($group != null && $type != null && !$type->isSecurityGroup()) { // A mailing list cannot be given permissions. It only has an address. // This prints `Newsletter is a mailing list: newsletter@example.test`. echo $group->dn()->rdnValue(), ' is a mailing list: ', $group->string('mail') ?? '', "\n";}Newsletter is a mailing list: newsletter@example.testSecurity of a changed copy
<?nvs// Shows that `isSecurityGroup` also works on a copy made with `with`, and the original does not change.// requires: samba-ad
var $corp = Core\Ldap::connect('corp');var $type = $corp->read('CN=Employees,OU=Company,DC=example,DC=test', { select: ['groupType'] })?->groupType();
if ($type != null) { // `with` returns a copy without the security flag. var $list = $type->with({ security: false });
// This prints `true` and then `false`. echo $type->isSecurityGroup() ? 'true' : 'false', "\n"; echo $list->isSecurityGroup() ? 'true' : 'false', "\n";}truefalse