Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
  • Loading branch information
blizzz committed Apr 23, 2020
1 parent ab550d6 commit 4babdc0
Show file tree
Hide file tree
Showing 8 changed files with 254 additions and 144 deletions.
133 changes: 83 additions & 50 deletions apps/user_ldap/lib/Access.php

Large diffs are not rendered by default.

96 changes: 59 additions & 37 deletions apps/user_ldap/lib/Group_LDAP.php

Large diffs are not rendered by default.

18 changes: 17 additions & 1 deletion apps/user_ldap/lib/Group_Proxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class Group_Proxy extends Proxy implements \OCP\GroupInterface, IGroupLDAP, IGet

/**
* Constructor
*
* @param string[] $serverConfigPrefixes array containing the config Prefixes
*/
public function __construct($serverConfigPrefixes, ILDAPWrapper $ldap, GroupPluginManager $groupPluginManager) {
Expand All @@ -51,6 +52,7 @@ public function __construct($serverConfigPrefixes, ILDAPWrapper $ldap, GroupPlug

/**
* Tries the backends one after the other until a positive result is returned from the specified method
*
* @param string $gid the gid connected to the request
* @param string $method the method of the group backend that shall be called
* @param array $parameters an array of parameters to be passed
Expand All @@ -60,7 +62,7 @@ protected function walkBackends($gid, $method, $parameters) {
$cacheKey = $this->getGroupCacheKey($gid);
foreach ($this->backends as $configPrefix => $backend) {
if ($result = call_user_func_array([$backend, $method], $parameters)) {
if(!$this->isSingleBackend()) {
if (!$this->isSingleBackend()) {
$this->writeToCache($cacheKey, $configPrefix);
}
return $result;
Expand All @@ -71,6 +73,7 @@ protected function walkBackends($gid, $method, $parameters) {

/**
* Asks the backend connected to the server that supposely takes care of the gid from the request.
*
* @param string $gid the gid connected to the request
* @param string $method the method of the group backend that shall be called
* @param array $parameters an array of parameters to be passed
Expand Down Expand Up @@ -107,6 +110,7 @@ protected function activeBackends(): int {

/**
* is user in group?
*
* @param string $uid uid of the user
* @param string $gid gid of the group
* @return bool
Expand All @@ -119,6 +123,7 @@ public function inGroup($uid, $gid) {

/**
* Get all groups a user belongs to
*
* @param string $uid Name of the user
* @return string[] with group names
*
Expand All @@ -140,6 +145,7 @@ public function getUserGroups($uid) {

/**
* get a list of all users in a group
*
* @return string[] with user ids
*/
public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0) {
Expand All @@ -166,6 +172,7 @@ public function createGroup($gid) {

/**
* delete a group
*
* @param string $gid gid of the group to delete
* @return bool
*/
Expand All @@ -176,6 +183,7 @@ public function deleteGroup($gid) {

/**
* Add a user to a group
*
* @param string $uid Name of the user to add to group
* @param string $gid Name of the group in which add the user
* @return bool
Expand All @@ -189,6 +197,7 @@ public function addToGroup($uid, $gid) {

/**
* Removes a user from a group
*
* @param string $uid Name of the user to remove from group
* @param string $gid Name of the group from which remove the user
* @return bool
Expand All @@ -202,6 +211,7 @@ public function removeFromGroup($uid, $gid) {

/**
* returns the number of users in a group, who match the search term
*
* @param string $gid the internal group name
* @param string $search optional, a search string
* @return int|bool
Expand All @@ -213,6 +223,7 @@ public function countUsersInGroup($gid, $search = '') {

/**
* get an array with group details
*
* @param string $gid
* @return array|false
*/
Expand All @@ -223,6 +234,7 @@ public function getGroupDetails($gid) {

/**
* get a list of all groups
*
* @return string[] with group names
*
* Returns a list with all groups
Expand All @@ -242,6 +254,7 @@ public function getGroups($search = '', $limit = -1, $offset = 0) {

/**
* check if a group exists
*
* @param string $gid
* @return bool
*/
Expand All @@ -251,6 +264,7 @@ public function groupExists($gid) {

/**
* Check if backend implements actions
*
* @param int $actions bitwise-or'ed actions
* @return boolean
*
Expand All @@ -264,6 +278,7 @@ public function implementsActions($actions) {

/**
* Return access for LDAP interaction.
*
* @param string $gid
* @return Access instance of Access for LDAP interaction
*/
Expand All @@ -274,6 +289,7 @@ public function getLDAPAccess($gid) {
/**
* Return a new LDAP connection for the specified group.
* The connection needs to be closed manually.
*
* @param string $gid
* @return resource of the LDAP connection
*/
Expand Down
25 changes: 16 additions & 9 deletions apps/user_ldap/lib/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public function __construct(IConfig $config) {

/**
* returns prefixes for each saved LDAP/AD server configuration.
*
* @param bool $activeConfigurations optional, whether only active configuration shall be
* retrieved, defaults to false
* @return array with a list of the available prefixes
Expand Down Expand Up @@ -97,6 +98,7 @@ public function getServerConfigurationPrefixes($activeConfigurations = false) {
/**
*
* determines the host for every configured connection
*
* @return array an array with configprefix as keys
*
*/
Expand Down Expand Up @@ -149,6 +151,7 @@ private function getServersConfig($value) {

/**
* deletes a given saved LDAP/AD server configuration.
*
* @param string $prefix the configuration prefix of the config to delete
* @return bool true on success, false otherwise
*/
Expand All @@ -166,11 +169,11 @@ public function deleteServerConfiguration($prefix) {
DELETE
FROM `*PREFIX*appconfig`
WHERE `configkey` LIKE ?
'.$saveOtherConfigurations.'
' . $saveOtherConfigurations . '
AND `appid` = \'user_ldap\'
AND `configkey` NOT IN (\'enabled\', \'installed_version\', \'types\', \'bgjUpdateGroupsLastRun\')
');
$delRows = $query->execute([$prefix.'%']);
$delRows = $query->execute([$prefix . '%']);

if ($delRows === null) {
return false;
Expand All @@ -185,8 +188,9 @@ public function deleteServerConfiguration($prefix) {

/**
* checks whether there is one or more disabled LDAP configurations
* @throws \Exception
*
* @return bool
* @throws \Exception
*/
public function haveDisabledConfigurations() {
$all = $this->getServerConfigurationPrefixes(false);
Expand All @@ -201,6 +205,7 @@ public function haveDisabledConfigurations() {

/**
* extracts the domain from a given URL
*
* @param string $url the URL
* @return string|false domain as string on success, false otherwise
*/
Expand Down Expand Up @@ -234,6 +239,7 @@ public function setLDAPProvider() {

/**
* sanitizes a DN received from the LDAP server
*
* @param array $dn the DN in question
* @return array|string the sanitized DN
*/
Expand All @@ -247,12 +253,12 @@ public function sanitizeDN($dn) {
return $result;
}

if(!is_string($dn)) {
if (!is_string($dn)) {
throw new \LogicException('String expected ' . \gettype($dn) . ' given');
}

if (($sanitizedDn = $this->sanitizeDnCache->get($dn)) !== null) {
return $sanitizedDn;
return $sanitizedDn;
}

//OID sometimes gives back DNs with whitespace after the comma
Expand All @@ -274,9 +280,9 @@ public function sanitizeDN($dn) {
'\;' => '\5c3B',
'\"' => '\5c22',
'\#' => '\5c23',
'(' => '\28',
')' => '\29',
'*' => '\2A',
'(' => '\28',
')' => '\29',
'*' => '\2A',
];
$sanitizedDn = str_replace(array_keys($replacements), array_values($replacements), $sanitizedDn);
$this->sanitizeDnCache->set($dn, $sanitizedDn);
Expand All @@ -286,6 +292,7 @@ public function sanitizeDN($dn) {

/**
* converts a stored DN so it can be used as base parameter for LDAP queries, internally we store them for usage in LDAP filters
*
* @param string $dn the DN
* @return string
*/
Expand Down Expand Up @@ -316,7 +323,7 @@ public static function loginName2UserName($param) {
$userSession = \OC::$server->getUserSession();
$userPluginManager = \OC::$server->query('LDAPUserPluginManager');

$userBackend = new User_Proxy(
$userBackend = new User_Proxy(
$configPrefixes, $ldapWrapper, $ocConfig, $notificationManager, $userSession, $userPluginManager
);
$uid = $userBackend->loginName2UserName($param['uid']);
Expand Down
Loading

0 comments on commit 4babdc0

Please sign in to comment.