Update files to PSR-2 standards
This commit is contained in:
parent
d640cc1eee
commit
37aa8b05f8
|
@ -100,7 +100,7 @@ class LoginController extends Controller
|
||||||
// ldap groups refresh
|
// ldap groups refresh
|
||||||
if (config('services.ldap.user_to_groups') !== false && $request->filled('username')) {
|
if (config('services.ldap.user_to_groups') !== false && $request->filled('username')) {
|
||||||
$ldapRepo = new LdapRepo($this->userRepo);
|
$ldapRepo = new LdapRepo($this->userRepo);
|
||||||
$ldapRepo->syncGroups($user,$request->input('username'));
|
$ldapRepo->syncGroups($user, $request->input('username'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,7 @@ class LdapRepo
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return call_user_func_array(array($this,$method),$arguments);
|
return call_user_func_array(array($this,$method), $arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -47,12 +47,12 @@ class LdapRepo
|
||||||
* @param string $userName
|
* @param string $userName
|
||||||
* @throws \BookStack\Exceptions\NotFoundException
|
* @throws \BookStack\Exceptions\NotFoundException
|
||||||
*/
|
*/
|
||||||
public function syncGroups($user,$userName)
|
public function syncGroups($user, $userName)
|
||||||
{
|
{
|
||||||
$userLdapGroups = $this->ldapService->getUserGroups($userName);
|
$userLdapGroups = $this->ldapService->getUserGroups($userName);
|
||||||
$userLdapGroups = $this->groupNameFilter($userLdapGroups);
|
$userLdapGroups = $this->groupNameFilter($userLdapGroups);
|
||||||
// get the ids for the roles from the names
|
// get the ids for the roles from the names
|
||||||
$ldapGroupsAsRoles = Role::whereIn('name',$userLdapGroups)->pluck('id');
|
$ldapGroupsAsRoles = Role::whereIn('name', $userLdapGroups)->pluck('id');
|
||||||
// sync groups
|
// sync groups
|
||||||
if ($this->config['remove_from_groups']) {
|
if ($this->config['remove_from_groups']) {
|
||||||
$user->roles()->sync($ldapGroupsAsRoles);
|
$user->roles()->sync($ldapGroupsAsRoles);
|
||||||
|
@ -62,8 +62,8 @@ class LdapRepo
|
||||||
}
|
}
|
||||||
|
|
||||||
// make the user an admin?
|
// make the user an admin?
|
||||||
if (in_array($this->config['admin'],$userLdapGroups)) {
|
if (in_array($this->config['admin'], $userLdapGroups)) {
|
||||||
$this->userRepo->attachSystemRole($user,'admin');
|
$this->userRepo->attachSystemRole($user, 'admin');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,7 @@ class LdapService
|
||||||
* @return null|array
|
* @return null|array
|
||||||
* @throws LdapException
|
* @throws LdapException
|
||||||
*/
|
*/
|
||||||
private function getUserWithAttributes($userName,$attributes)
|
private function getUserWithAttributes($userName, $attributes)
|
||||||
{
|
{
|
||||||
$ldapConnection = $this->getConnection();
|
$ldapConnection = $this->getConnection();
|
||||||
$this->bindSystemUser($ldapConnection);
|
$this->bindSystemUser($ldapConnection);
|
||||||
|
@ -196,7 +196,7 @@ class LdapService
|
||||||
}
|
}
|
||||||
|
|
||||||
$userGroups = $this->groupFilter($user);
|
$userGroups = $this->groupFilter($user);
|
||||||
$userGroups = $this->getGroupsRecursive($userGroups,[]);
|
$userGroups = $this->getGroupsRecursive($userGroups, []);
|
||||||
return $userGroups;
|
return $userGroups;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -206,19 +206,22 @@ class LdapService
|
||||||
* @param array $checked
|
* @param array $checked
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
private function getGroupsRecursive($groupsArray,$checked) {
|
private function getGroupsRecursive($groupsArray, $checked)
|
||||||
|
{
|
||||||
$groups_to_add = [];
|
$groups_to_add = [];
|
||||||
foreach ($groupsArray as $groupName) {
|
foreach ($groupsArray as $groupName) {
|
||||||
if (in_array($groupName,$checked)) continue;
|
if (in_array($groupName, $checked)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
$groupsToAdd = $this->getGroupGroups($groupName);
|
$groupsToAdd = $this->getGroupGroups($groupName);
|
||||||
$groups_to_add = array_merge($groups_to_add,$groupsToAdd);
|
$groups_to_add = array_merge($groups_to_add, $groupsToAdd);
|
||||||
$checked[] = $groupName;
|
$checked[] = $groupName;
|
||||||
}
|
}
|
||||||
$groupsArray = array_unique(array_merge($groupsArray,$groups_to_add), SORT_REGULAR);
|
$groupsArray = array_unique(array_merge($groupsArray, $groups_to_add), SORT_REGULAR);
|
||||||
|
|
||||||
if (!empty($groups_to_add)) {
|
if (!empty($groups_to_add)) {
|
||||||
return $this->getGroupsRecursive($groupsArray,$checked);
|
return $this->getGroupsRecursive($groupsArray, $checked);
|
||||||
} else {
|
} else {
|
||||||
return $groupsArray;
|
return $groupsArray;
|
||||||
}
|
}
|
||||||
|
@ -260,14 +263,15 @@ class LdapService
|
||||||
$groupsAttr = strtolower($this->config['group_attribute']);
|
$groupsAttr = strtolower($this->config['group_attribute']);
|
||||||
$ldapGroups = [];
|
$ldapGroups = [];
|
||||||
$count = 0;
|
$count = 0;
|
||||||
if (isset($ldapSearchReturn[$groupsAttr]['count'])) $count = (int) $ldapSearchReturn[$groupsAttr]['count'];
|
if (isset($ldapSearchReturn[$groupsAttr]['count'])) {
|
||||||
for ($i=0;$i<$count;$i++) {
|
$count = (int) $ldapSearchReturn[$groupsAttr]['count'];
|
||||||
$dnComponents = ldap_explode_dn($ldapSearchReturn[$groupsAttr][$i],1);
|
}
|
||||||
if (!in_array($dnComponents[0],$ldapGroups)) {
|
for ($i=0; $i<$count; $i++) {
|
||||||
|
$dnComponents = ldap_explode_dn($ldapSearchReturn[$groupsAttr][$i], 1);
|
||||||
|
if (!in_array($dnComponents[0], $ldapGroups)) {
|
||||||
$ldapGroups[] = $dnComponents[0];
|
$ldapGroups[] = $dnComponents[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $ldapGroups;
|
return $ldapGroups;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue