Skip to content

Commit b6115db

Browse files
author
EDVler
authored
Changed self to static to make inheritance work
1 parent 7cb6e9a commit b6115db

File tree

1 file changed

+26
-26
lines changed

1 file changed

+26
-26
lines changed

src/model/UserDbLdap.php

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -340,8 +340,8 @@ public function behaviors()
340340
public function rules()
341341
{
342342
return [
343-
['status', 'default', 'value' => self::STATUS_ENABLED],
344-
['status', 'in', 'range' => [self::STATUS_ENABLED, self::STATUS_DISABLED]],
343+
['status', 'default', 'value' => static::STATUS_ENABLED],
344+
['status', 'in', 'range' => [static::STATUS_ENABLED, static::STATUS_DISABLED]],
345345
];
346346
}
347347

@@ -361,7 +361,7 @@ public static function findIdentity($id)
361361
//Database check. If no dataset is found then the only possible return value is null.
362362
$userObjectDb = static::findOne(['id' => $id]);
363363

364-
return self::checkAllowedToLogin($userObjectDb);
364+
return static::checkAllowedToLogin($userObjectDb);
365365
}
366366

367367
/**
@@ -398,9 +398,9 @@ public static function findByUsername($username)
398398
//Create user if not found in db?
399399
if ($userObjectDb == null) {
400400
//Just create to get synchronisation options
401-
$userObjectDb = new static;
401+
$userObjectDb = new static();
402402

403-
if(self::getSyncOptions("ON_LOGIN_CREATE_USER", $userObjectDb->individualSyncOptions) == true) {
403+
if(static::getSyncOptions("ON_LOGIN_CREATE_USER", $userObjectDb->individualSyncOptions) == true) {
404404
$userObjectDb = static::createNewUser($username);
405405
} else {
406406
$userObjectDb = null;
@@ -409,16 +409,16 @@ public static function findByUsername($username)
409409
}
410410

411411
//Refresh group assignments of user if found in database?
412-
if ($userObjectDb->username != null && self::getSyncOptions("ON_LOGIN_REFRESH_GROUP_ASSIGNMENTS", $userObjectDb->individualSyncOptions) == true) {
412+
if ($userObjectDb->username != null && static::getSyncOptions("ON_LOGIN_REFRESH_GROUP_ASSIGNMENTS", $userObjectDb->individualSyncOptions) == true) {
413413
$userObjectDb->updateGroupAssignment();
414414
}
415415

416416
//Refresh account status of user if found in database?
417-
if ($userObjectDb->username != null && self::getSyncOptions("ON_LOGIN_REFRESH_LDAP_ACCOUNT_STATUS", $userObjectDb->individualSyncOptions) == true && self::getSyncOptions("ON_REQUEST_REFRESH_LDAP_ACCOUNT_STATUS", $userObjectDb->individualSyncOptions) == false) {
417+
if ($userObjectDb->username != null && static::getSyncOptions("ON_LOGIN_REFRESH_LDAP_ACCOUNT_STATUS", $userObjectDb->individualSyncOptions) == true && static::getSyncOptions("ON_REQUEST_REFRESH_LDAP_ACCOUNT_STATUS", $userObjectDb->individualSyncOptions) == false) {
418418
$userObjectDb->updateAccountStatus();
419419
}
420420

421-
return self::checkAllowedToLogin($userObjectDb);
421+
return static::checkAllowedToLogin($userObjectDb);
422422
}
423423

424424
/**
@@ -441,23 +441,23 @@ public static function checkAllowedToLogin($userObjectDb) {
441441
}
442442

443443
//Refresh account status on every request?
444-
if ($userObjectDb->username != null && self::getSyncOptions("ON_REQUEST_REFRESH_LDAP_ACCOUNT_STATUS", $userObjectDb->individualSyncOptions) == true) {
444+
if ($userObjectDb->username != null && static::getSyncOptions("ON_REQUEST_REFRESH_LDAP_ACCOUNT_STATUS", $userObjectDb->individualSyncOptions) == true) {
445445
$userObjectDb->updateAccountStatus();
446446
}
447447

448448
//Login only possible if a role is assigned which matches the LOGIN_POSSIBLE_WITH_ROLE_ASSIGNED_MATCHING_REGEX regex
449-
if ($userObjectDb->status == self::STATUS_ENABLED && self::getGroupAssigmentOptions("LOGIN_POSSIBLE_WITH_ROLE_ASSIGNED_MATCHING_REGEX",$userObjectDb->individualGroupAssignmentOptions) != null) {
449+
if ($userObjectDb->status == static::STATUS_ENABLED && static::getGroupAssigmentOptions("LOGIN_POSSIBLE_WITH_ROLE_ASSIGNED_MATCHING_REGEX",$userObjectDb->individualGroupAssignmentOptions) != null) {
450450
$rolesAssignedToUser = \Yii::$app->authManager->getRolesByUser($userObjectDb->getId());
451451

452452
foreach ($rolesAssignedToUser as $role) {
453-
if(preg_match(self::getGroupAssigmentOptions("LOGIN_POSSIBLE_WITH_ROLE_ASSIGNED_MATCHING_REGEX",$userObjectDb->individualGroupAssignmentOptions),$role->name) == true) {
453+
if(preg_match(static::getGroupAssigmentOptions("LOGIN_POSSIBLE_WITH_ROLE_ASSIGNED_MATCHING_REGEX",$userObjectDb->individualGroupAssignmentOptions),$role->name) == true) {
454454
return $userObjectDb;
455455
}
456456
}
457457
}
458458

459459
//Login possible if no role is assigned
460-
if ($userObjectDb->status == self::STATUS_ENABLED && self::getGroupAssigmentOptions("LOGIN_POSSIBLE_WITH_ROLE_ASSIGNED_MATCHING_REGEX",$userObjectDb->individualGroupAssignmentOptions) == null) {
460+
if ($userObjectDb->status == static::STATUS_ENABLED && static::getGroupAssigmentOptions("LOGIN_POSSIBLE_WITH_ROLE_ASSIGNED_MATCHING_REGEX",$userObjectDb->individualGroupAssignmentOptions) == null) {
461461
return $userObjectDb;
462462
}
463463

@@ -537,7 +537,7 @@ public static function getSyncOptions($getOptionByName, $individualSyncOptions =
537537
} else if(isset(\Yii::$app->params["LDAP-User-Sync-Options"]) && $individualSyncOptions == null ) {
538538
$syncOptionsUsed = \Yii::$app->params["LDAP-User-Sync-Options"];
539539
} else {
540-
$syncOptionsUsed = self::SYNC_OPTIONS_TEMPLATE_WITHOUT_BACKEND_TASK;
540+
$syncOptionsUsed = static::SYNC_OPTIONS_TEMPLATE_WITHOUT_BACKEND_TASK;
541541
}
542542

543543
if (array_key_exists($getOptionByName,$syncOptionsUsed) == true) {
@@ -573,7 +573,7 @@ public static function getGroupAssigmentOptions($getOptionByName, $individualGro
573573
} else if(isset(\Yii::$app->params["LDAP-Group-Assignment-Options"]) && $individualGroupAssignmentOptions == null ) {
574574
$groupOptionsUsed = \Yii::$app->params["LDAP-Group-Assignment-Options"];
575575
} else {
576-
$groupOptionsUsed = self::GROUP_ASSIGNMENT_TOUCH_ONLY_MATCHING_REGEX;
576+
$groupOptionsUsed = static::GROUP_ASSIGNMENT_TOUCH_ONLY_MATCHING_REGEX;
577577
}
578578

579579
if (array_key_exists($getOptionByName,$groupOptionsUsed) == true) {
@@ -590,7 +590,7 @@ public static function getGroupAssigmentOptions($getOptionByName, $individualGro
590590
* @return Edvlerblog\Adldap2\model\UserDbLdapDbLdap object. Null if the username is not found in LDAP.
591591
*/
592592
public static function createNewUser($username,$individualGroupAssignmentOptions = null) {
593-
$userObjectDb = new static;
593+
$userObjectDb = new static();
594594

595595
//Username has to be set before a LDAP query
596596
$userObjectDb->username = $username;
@@ -604,7 +604,7 @@ public static function createNewUser($username,$individualGroupAssignmentOptions
604604

605605
$roles = $userObjectDb->updateGroupAssignment();
606606

607-
if (count($roles) > 0 || self::getGroupAssigmentOptions("LOGIN_POSSIBLE_WITH_ROLE_ASSIGNED_MATCHING_REGEX",$userObjectDb->individualGroupAssignmentOptions) == null) {
607+
if (count($roles) > 0 || static::getGroupAssigmentOptions("LOGIN_POSSIBLE_WITH_ROLE_ASSIGNED_MATCHING_REGEX",$userObjectDb->individualGroupAssignmentOptions) == null) {
608608
$userObjectDb->generateAuthKey();
609609
$userObjectDb->updateAccountStatus();
610610
$userObjectDb->save();
@@ -628,7 +628,7 @@ public static function createOrRefreshUser($username,$individualGroupAssignmentO
628628

629629
//Create user if not found in db
630630
if ($userObjectDb == null) {
631-
return self::createNewUser($username, $individualGroupAssignmentOptions);
631+
return static::createNewUser($username, $individualGroupAssignmentOptions);
632632
}
633633

634634
$userObjectDb->setIndividualGroupAssignmentOptions($individualGroupAssignmentOptions);
@@ -650,7 +650,7 @@ public function updateAccountStatus() {
650650

651651
if ($ldapUser == null) {
652652
//If no user is found in LDAP, disable in database.
653-
$this->status = self::STATUS_DISABLED;
653+
$this->status = static::STATUS_DISABLED;
654654
} else {
655655
//Query account status from active directory
656656
$ldapAccountState = $ldapUser->getUserAccountControl();
@@ -660,9 +660,9 @@ public function updateAccountStatus() {
660660
$pwExpired = ($ldapAccountState & AccountControl::PASSWORD_EXPIRED) === AccountControl::PASSWORD_EXPIRED;
661661

662662
if($disabledUser == true || $lockedUser == true || $pwExpired == true) {
663-
$this->status = self::STATUS_DISABLED;
663+
$this->status = static::STATUS_DISABLED;
664664
} else {
665-
$this->status = self::STATUS_ENABLED;
665+
$this->status = static::STATUS_ENABLED;
666666
}
667667
}
668668

@@ -717,9 +717,9 @@ public function updateGroupAssignment() {
717717
$rolesAssignedToUser = \Yii::$app->authManager->getRolesByUser($this->getId());
718718

719719
//Map groups from LDAP to roles and add to user object.
720-
if (self::getGroupAssigmentOptions("ADD_GROUPS_FROM_LDAP_MATCHING_REGEX",$this->individualGroupAssignmentOptions) == true) {
720+
if (static::getGroupAssigmentOptions("ADD_GROUPS_FROM_LDAP_MATCHING_REGEX",$this->individualGroupAssignmentOptions) == true) {
721721
foreach ($ldapGroupsConverted as $gn) {
722-
if(preg_match(self::getGroupAssigmentOptions("REGEX_GROUP_MATCH_IN_LDAP",$this->individualGroupAssignmentOptions),$gn) == true) {
722+
if(preg_match(static::getGroupAssigmentOptions("REGEX_GROUP_MATCH_IN_LDAP",$this->individualGroupAssignmentOptions),$gn) == true) {
723723
if(array_key_exists($gn,$yiiAviliableRoles) && !array_key_exists($gn,$rolesAssignedToUser)) {
724724
if ($this->isNewRecord) {
725725
$this->generateAuthKey();
@@ -735,7 +735,7 @@ public function updateGroupAssignment() {
735735
}
736736

737737
//Remove all roles from user object which are not in LDAP
738-
if (self::getGroupAssigmentOptions("REMOVE_ALL_GROUPS_NOT_FOUND_IN_LDAP",$this->individualGroupAssignmentOptions) == true && self::getGroupAssigmentOptions("REMOVE_ONLY_GROUPS_MATCHING_REGEX",$this->individualGroupAssignmentOptions) == false) {
738+
if (static::getGroupAssigmentOptions("REMOVE_ALL_GROUPS_NOT_FOUND_IN_LDAP",$this->individualGroupAssignmentOptions) == true && static::getGroupAssigmentOptions("REMOVE_ONLY_GROUPS_MATCHING_REGEX",$this->individualGroupAssignmentOptions) == false) {
739739
foreach ($rolesAssignedToUser as $role) {
740740
if(in_array($role->name,$ldapGroupsConverted) == false) {
741741
$auth = \Yii::$app->authManager;
@@ -745,11 +745,11 @@ public function updateGroupAssignment() {
745745
}
746746

747747
//Remove all roles from user object which are matching the regex and are not in LDAP
748-
if (self::getGroupAssigmentOptions("REMOVE_ONLY_GROUPS_MATCHING_REGEX",$this->individualGroupAssignmentOptions) == true) {
748+
if (static::getGroupAssigmentOptions("REMOVE_ONLY_GROUPS_MATCHING_REGEX",$this->individualGroupAssignmentOptions) == true) {
749749
foreach ($rolesAssignedToUser as $role) {
750750
$roleName = $role->name;
751751

752-
if(preg_match(self::getGroupAssigmentOptions("REGEX_GROUP_MATCH_IN_LDAP",$this->individualGroupAssignmentOptions),$roleName) == true && in_array($roleName,$ldapGroupsConverted) == false) {
752+
if(preg_match(static::getGroupAssigmentOptions("REGEX_GROUP_MATCH_IN_LDAP",$this->individualGroupAssignmentOptions),$roleName) == true && in_array($roleName,$ldapGroupsConverted) == false) {
753753
$auth = \Yii::$app->authManager;
754754
$auth->revoke($role, $this->getId());
755755
}
@@ -811,7 +811,7 @@ private function getAdldap2Provider() {
811811
*/
812812
public function getPasswordExpiryDate() {
813813
if ($this->username == null) {
814-
throw new \yii\base\Exception("Please set username attribute before calling getPasswordExpiryDate() function.");
814+
throw new \yii\base\Exception("Please set username attribute before calling getPasswordExpiryDate() function.");
815815
}
816816

817817
$provider = $this->getAdldap2Provider();

0 commit comments

Comments
 (0)