Commit a33671a3 authored by Sven Greiner's avatar Sven Greiner
Browse files

Just copy & paste without testing

parent 2c761cce
...@@ -16,7 +16,7 @@ namespace OCA\user_wcf; ...@@ -16,7 +16,7 @@ namespace OCA\user_wcf;
* $wcfPath parameter. * $wcfPath parameter.
*/ */
class Group_WCF extends \OC_Group_Backend { class Group_WCF implements \OCP\GroupInterface {
protected $db; protected $db;
public function __construct() { public function __construct() {
...@@ -25,23 +25,27 @@ class Group_WCF extends \OC_Group_Backend { ...@@ -25,23 +25,27 @@ class Group_WCF extends \OC_Group_Backend {
$this->db = lib\WCF_DB::getInstance($wcfPath); $this->db = lib\WCF_DB::getInstance($wcfPath);
$this->db->setAuthorizedGroups($authorizedGroups); $this->db->setAuthorizedGroups($authorizedGroups);
} }
/** /**
* @brief Check if backend implements actions * Check if backend implements actions
* @param int $actions bitwise-or'ed actions * @param int $actions bitwise-or'ed actions
* @return boolean * @return boolean
* @since 4.5.0
* *
* Returns the supported actions as int to be * Returns the supported actions as int to be
* compared with OC_GROUP_BACKEND_CREATE_GROUP etc. * compared with \OC_Group_Backend::CREATE_GROUP etc.
*/ */
public function getSupportedActions() { public function implementsActions($actions) {
return OC_GROUP_BACKEND_GET_DISPLAYNAME; return (bool)(GROUP_DETAILS
& $actions);
} }
/** /**
* @brief is user in group? * is user in group?
* @param string $uid uid of the user * @param string $uid uid of the user
* @param string $gid gid of the group * @param string $gid gid of the group
* @return bool * @return bool
* @since 4.5.0
* *
* Checks whether the user is member of a group or not. * Checks whether the user is member of a group or not.
*/ */
...@@ -59,9 +63,10 @@ class Group_WCF extends \OC_Group_Backend { ...@@ -59,9 +63,10 @@ class Group_WCF extends \OC_Group_Backend {
} }
/** /**
* @brief Get all groups a user belongs to * Get all groups a user belongs to
* @param string $uid Name of the user * @param string $uid Name of the user
* @return array with group names * @return array an array of group names
* @since 4.5.0
* *
* This function fetches all groups a user belongs to. It does not check * This function fetches all groups a user belongs to. It does not check
* if the user exists at all. * if the user exists at all.
...@@ -80,15 +85,16 @@ class Group_WCF extends \OC_Group_Backend { ...@@ -80,15 +85,16 @@ class Group_WCF extends \OC_Group_Backend {
} }
/** /**
* @brief get a list of all groups * get a list of all groups
* @param string $search * @param string $search
* @param int $limit * @param int $limit
* @param int $offset * @param int $offset
* @return array with group names * @return array an array of group names
* @since 4.5.0
* *
* Returns a list with all groups * Returns a list with all groups
*/ */
public function getGroups($search = '', $limit=null, $offset=null) { public function getGroups($search = '', $limit = -1, $offset = 0) {
$groups = array(); $groups = array();
$params = array(); $params = array();
$where = NULL; $where = NULL;
...@@ -127,6 +133,7 @@ class Group_WCF extends \OC_Group_Backend { ...@@ -127,6 +133,7 @@ class Group_WCF extends \OC_Group_Backend {
* check if a group exists * check if a group exists
* @param string $gid * @param string $gid
* @return bool * @return bool
* @since 4.5.0
*/ */
public function groupExists($gid) { public function groupExists($gid) {
$exists = FALSE; $exists = FALSE;
...@@ -140,12 +147,13 @@ class Group_WCF extends \OC_Group_Backend { ...@@ -140,12 +147,13 @@ class Group_WCF extends \OC_Group_Backend {
} }
/** /**
* @brief get a list of all users in a group * get a list of all users in a group
* @param string $gid * @param string $gid
* @param string $search * @param string $search
* @param int $limit * @param int $limit
* @param int $offset * @param int $offset
* @return array with user ids * @return array an array of user ids
* @since 4.5.0
*/ */
public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0) { public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0) {
$users = array(); $users = array();
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
namespace OCA\user_wcf; namespace OCA\user_wcf;
use OC\User\Backend;
/** /**
* This class authenticates users against a WCF database if they belong to * This class authenticates users against a WCF database if they belong to
...@@ -15,7 +16,7 @@ namespace OCA\user_wcf; ...@@ -15,7 +16,7 @@ namespace OCA\user_wcf;
* database configuration is imported from the WCF configuration file of * database configuration is imported from the WCF configuration file of
* the WCF installation given in the $wcfPath paramter. * the WCF installation given in the $wcfPath paramter.
*/ */
class User_WCF extends \OC_User_Backend { class User_WCF implements \OCP\IUserBackend, \OCP\UserInterface {
protected $authorizedGroups; protected $authorizedGroups;
protected $groupsCondition; protected $groupsCondition;
protected $db = NULL; protected $db = NULL;
...@@ -28,63 +29,49 @@ class User_WCF extends \OC_User_Backend { ...@@ -28,63 +29,49 @@ class User_WCF extends \OC_User_Backend {
$this->db->setAuthorizedGroups($authorizedGroups); $this->db->setAuthorizedGroups($authorizedGroups);
} }
public function getSupportedActions() { /**
return OC_USER_BACKEND_CHECK_PASSWORD | OC_USER_BACKEND_GET_DISPLAYNAME; * Backend name to be shown in user management
* @return string the name of the backend to be shown
* @since 8.0.0
*/
public function getBackendName() {
return "WCF";
} }
/** /**
* @brief Check if the password is correct * Check if backend implements actions
* @param $uid The username * @param int $actions bitwise-or'ed actions
* @param $password The password * @return boolean
* @returns string
* *
* Check if the password is correct without logging in the user * Returns the supported actions as int to be
* returns the user id or false * compared with \OC_User_Backend::CREATE_USER etc.
* @since 4.5.0
*/ */
public function checkPassword($uid, $password) { public function implementsActions($actions) {
$authenticatedAs = FALSE; return (bool)((Backend::CHECK_PASSWORD
| Backend::GET_DISPLAYNAME)
$where = 'LOWER(username)=LOWER(?)'; & $actions);
$result = $this->db->prepare('username, password, salt', $where);
if ($result !== FALSE and $result->execute(array($uid))) {
if (($row = $result->fetch()) !== FALSE) {
$doubleSalted = lib\StringUtil::getDoubleSaltedHash(
$password, $row['salt']);
if ($doubleSalted === $row['password']) {
$authenticatedAs = $row['username'];
$this->debug('User "'.$authenticatedAs.
'" logged in successfully.');
}
else {
$this->info('Invalid password for user '.$uid.'.');
}
}
else {
$this->info('User '.$uid.' is not in any authorized group.');
}
$result->closeCursor();
}
else {
$this->warn('Error while checking password for user '.$uid);
} }
return $authenticatedAs; /**
} * delete a user
* @param string $uid The username of the user to delete
public function userExists($uid) { * @return bool
$exists = FALSE; * @since 4.5.0
$result = $this->db->prepare('1', 'username=?'); * @todo
*/
if ($result !== FALSE and $result->execute(array($uid))) { public function deleteUser($uid);
$exists = ($result->fetch() !== FALSE);
$result->closeCursor();
}
return $exists;
}
public function getUsers($search='', $limit=null, $offset=null) { /**
* Get a list of all users
*
* @param string $search
* @param null|int $limit
* @param null|int $offset
* @return string[] an array of all uids
* @since 4.5.0
*/
public function getUsers($search = '', $limit = null, $offset = null) {
$users = array(); $users = array();
$params = array(); $params = array();
$where = NULL; $where = NULL;
...@@ -118,32 +105,103 @@ class User_WCF extends \OC_User_Backend { ...@@ -118,32 +105,103 @@ class User_WCF extends \OC_User_Backend {
return $users; return $users;
} }
public static function info($text) { /**
\OCP\Util::writeLog('user_wcf', $text, \OCP\Util::INFO); * check if a user exists
} * @param string $uid the username
* @return boolean
* @since 4.5.0
*/
public function userExists($uid) {
$exists = FALSE;
$result = $this->db->prepare('1', 'username=?');
public static function warn($text) { if ($result !== FALSE and $result->execute(array($uid))) {
\OCP\Util::writeLog('user_wcf', $text, \OCP\Util::WARN); $exists = ($result->fetch() !== FALSE);
$result->closeCursor();
} }
return $exists;
public static function debug($text) {
\OCP\Util::writeLog('user_wcf', $text, \OCP\Util::DEBUG);
} }
/** /**
* Backend name to be shown in user management * get display name of the user
* @return string the name of the backend to be shown * @param string $uid user ID of the user
* @return string display name
* @since 4.5.0
* @todo
*/ */
public function getBackendName(){ public function getDisplayName($uid);
return 'WCF';
} /**
* Get a list of all display names and user ids.
*
* @param string $search
* @param string|null $limit
* @param string|null $offset
* @return array an array of all displayNames (value) and the corresponding uids (key)
* @since 4.5.0
* @todo
*/
public function getDisplayNames($search = '', $limit = null, $offset = null);
/** /**
* Check if a user list is available or not * Check if a user list is available or not
* @return boolean if users can be listed or not * @return boolean if users can be listed or not
* @since 4.5.0
*/ */
public function hasUserListings() { public function hasUserListings() {
return true; return true;
} }
/**
* @brief Check if the password is correct
* @param $uid The username
* @param $password The password
* @returns string
*
* Check if the password is correct without logging in the user
* returns the user id or false
*/
public function checkPassword($uid, $password) {
$authenticatedAs = FALSE;
$where = 'LOWER(username)=LOWER(?)';
$result = $this->db->prepare('username, password, salt', $where);
if ($result !== FALSE and $result->execute(array($uid))) {
if (($row = $result->fetch()) !== FALSE) {
$doubleSalted = lib\StringUtil::getDoubleSaltedHash(
$password, $row['salt']);
if ($doubleSalted === $row['password']) {
$authenticatedAs = $row['username'];
$this->debug('User "'.$authenticatedAs.
'" logged in successfully.');
}
else {
$this->info('Invalid password for user '.$uid.'.');
}
}
else {
$this->info('User '.$uid.' is not in any authorized group.');
}
$result->closeCursor();
}
else {
$this->warn('Error while checking password for user '.$uid);
}
return $authenticatedAs;
}
public static function info($text) {
\OCP\Util::writeLog('user_wcf', $text, \OCP\Util::INFO);
}
public static function warn($text) {
\OCP\Util::writeLog('user_wcf', $text, \OCP\Util::WARN);
}
public static function debug($text) {
\OCP\Util::writeLog('user_wcf', $text, \OCP\Util::DEBUG);
}
} }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment