Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
196 changes: 196 additions & 0 deletions app/plugins/CoreServer/src/Lib/Enum/LdapMatchingRuleEnum.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
<?php
/**
* COmanage Registry LDAP Matching Rule Enum
*
* Portions licensed to the University Corporation for Advanced Internet
* Development, Inc. ("UCAID") under one or more contributor license agreements.
* See the NOTICE file distributed with this work for additional information
* regarding copyright ownership.
*
* UCAID licenses this file to you under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @link https://www.internet2.edu/comanage COmanage Project
* @package registry-plugins
* @since COmanage Registry v5.4.0
* @license Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
*/

declare(strict_types = 1);

namespace CoreServer\Lib\Enum;

use App\Lib\Enum\StandardEnum;

/**
* LDAP equality matching rule names (RFC 4517 section 4.2) and the equality
* matching rule of each attribute emitted by Registry.
*
* Used by \CoreServer\Lib\Traits\LdapMatchingRulesTrait.
*/
class LdapMatchingRuleEnum extends StandardEnum
{
/**
* RFC 4517 section 4.2.11: Directory Strings, case and insignificant spaces ignored.
*/
const string CASE_IGNORE = 'caseIgnoreMatch';

/**
* RFC 4517 section 4.2.13: IA5 (ASCII) strings, case and insignificant spaces ignored.
*/
const string CASE_IGNORE_IA5 = 'caseIgnoreIA5Match';

/**
* RFC 4517 section 4.2.4: Directory Strings, case significant.
*/
const string CASE_EXACT = 'caseExactMatch';

/**
* RFC 4517 section 4.2.3: IA5 (ASCII) strings, case significant.
*/
const string CASE_EXACT_IA5 = 'caseExactIA5Match';

/**
* RFC 4517 section 4.2.27: byte for byte comparison.
*/
const string OCTET_STRING = 'octetStringMatch';

/**
* RFC 4517 section 4.2.15: RDN by RDN comparison of Distinguished Names.
*/
const string DN = 'distinguishedNameMatch';

/**
* RFC 4517 section 4.2.19: values denoting the same integer.
*/
const string INTEGER = 'integerMatch';

/**
* RFC 4517 section 4.2.22: Numeric Strings, spaces ignored.
*/
const string NUMERIC_STRING = 'numericStringMatch';

/**
* RFC 4517 section 4.2.29: like caseIgnoreMatch, spaces and hyphens ignored.
*/
const string TELEPHONE_NUMBER = 'telephoneNumberMatch';

/**
* RFC 4517 section 4.2.16: values denoting the same point in time.
*/
const string GENERALIZED_TIME = 'generalizedTimeMatch';

/**
* Equality matching rule per attribute, keyed on the lowercased base attribute
* name (without options). The EQUALITY rule is taken from the attribute itself or,
* when it has none, from its SUP chain. Attributes not listed here fall back to
* caseIgnoreMatch.
*
* Attributes with no EQUALITY rule at all (eg facsimileTelephoneNumber) are mapped
* to octetStringMatch, so only byte-identical values are treated as duplicates.
*
* Note: this is the only array constant of the enum, so the StandardEnum
* reflection helpers (getConstValues() etc) should not be used on this class.
*
* @var array<string,string>
*/
const array ATTRIBUTE_MATCHING_RULES = [
// RFC 4512 / RFC 4519 (core)
'name' => self::CASE_IGNORE,
'cn' => self::CASE_IGNORE, // SUP name
'sn' => self::CASE_IGNORE, // SUP name
'givenname' => self::CASE_IGNORE, // SUP name
'title' => self::CASE_IGNORE, // SUP name
'o' => self::CASE_IGNORE, // SUP name
'ou' => self::CASE_IGNORE, // SUP name
'l' => self::CASE_IGNORE, // SUP name
'st' => self::CASE_IGNORE, // SUP name
'street' => self::CASE_IGNORE,
'postalcode' => self::CASE_IGNORE,
'description' => self::CASE_IGNORE,
'uid' => self::CASE_IGNORE,
'objectclass' => self::CASE_IGNORE, // objectIdentifierMatch, descriptors compare case-insensitively
'telephonenumber' => self::TELEPHONE_NUMBER,
'facsimiletelephonenumber' => self::OCTET_STRING, // no EQUALITY rule (Facsimile Telephone Number syntax)
'userpassword' => self::OCTET_STRING,
'distinguishedname' => self::DN,
'member' => self::DN, // SUP distinguishedName
'owner' => self::DN, // SUP distinguishedName
'roleoccupant' => self::DN, // SUP distinguishedName
'seealso' => self::DN, // SUP distinguishedName

// cosine (RFC 4524)
'mail' => self::CASE_IGNORE_IA5,
'roomnumber' => self::CASE_IGNORE,
'manager' => self::DN,
'mobile' => self::TELEPHONE_NUMBER,
'homephone' => self::TELEPHONE_NUMBER,
'pager' => self::TELEPHONE_NUMBER,

// inetOrgPerson (RFC 2798) and labeledURI (RFC 2079)
'displayname' => self::CASE_IGNORE,
'employeenumber' => self::CASE_IGNORE,
'employeetype' => self::CASE_IGNORE,
'labeleduri' => self::CASE_EXACT,

// nis (RFC 2307)
'uidnumber' => self::INTEGER,
'gidnumber' => self::INTEGER,
'homedirectory' => self::CASE_EXACT_IA5,
'loginshell' => self::CASE_EXACT_IA5,

// Password Policy (draft-behera-ldap-password-policy)
'pwdaccountlockedtime' => self::GENERALIZED_TIME,

// openssh-lpk
'sshpublickey' => self::OCTET_STRING,

// eduMember
'ismemberof' => self::CASE_EXACT,
'hasmember' => self::CASE_EXACT,

// eduPerson
'edupersonaffiliation' => self::CASE_IGNORE,
'edupersonassurance' => self::CASE_IGNORE,
'edupersonanalyticstag' => self::CASE_EXACT,
'edupersondisplaypronouns' => self::OCTET_STRING, // no EQUALITY rule
'edupersonentitlement' => self::CASE_EXACT,
'edupersonnickname' => self::CASE_IGNORE,
'edupersonorcid' => self::CASE_IGNORE,
'edupersonorgdn' => self::DN,
'edupersonorgunitdn' => self::DN,
'edupersonprimaryaffiliation' => self::CASE_IGNORE,
'edupersonprimaryorgunitdn' => self::DN,
'edupersonprincipalname' => self::CASE_IGNORE,
'edupersonprincipalnameprior' => self::CASE_IGNORE,
'edupersonscopedaffiliation' => self::CASE_IGNORE,
'edupersontargetedid' => self::CASE_IGNORE,
'edupersonuniqueid' => self::CASE_IGNORE,

// voPerson
'vopersonaffiliation' => self::CASE_IGNORE,
'vopersonapplicationpassword' => self::OCTET_STRING,
'vopersonapplicationuid' => self::CASE_IGNORE,
'vopersonauthorname' => self::CASE_IGNORE,
'vopersoncertificatedn' => self::DN,
'vopersoncertificateissuerdn' => self::DN,
'vopersonexternalaffiliation' => self::CASE_IGNORE,
'vopersonexternalid' => self::CASE_IGNORE,
'vopersonid' => self::CASE_IGNORE,
'vopersonpolicyagreement' => self::CASE_IGNORE,
'vopersonscopedaffiliation' => self::CASE_IGNORE,
'vopersonsorid' => self::CASE_IGNORE,
'vopersonstatus' => self::CASE_IGNORE,
'vopersontoken' => self::CASE_EXACT,
'vopersonverifiedemail' => self::CASE_IGNORE,
];
}
Loading