Moves SCIM to service.
This commit is contained in:
parent
0c5164f917
commit
69120adc10
4 changed files with 39 additions and 93 deletions
|
@ -4,40 +4,39 @@ declare(strict_types=1);
|
|||
|
||||
namespace OCA\SCIMServiceProvider\Controller;
|
||||
|
||||
use OCP\Accounts\IAccountManager;
|
||||
use OCP\AppFramework\ApiController;
|
||||
use OCP\AppFramework\Http\Response;
|
||||
use OCP\IConfig;
|
||||
use OCP\IGroupManager;
|
||||
use OCP\IRequest;
|
||||
use OCP\IUserManager;
|
||||
use OCP\IUserSession;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use OCA\SCIMServiceProvider\Responses\SCIMListResponse;
|
||||
use OCA\SCIMServiceProvider\Responses\SCIMJSONResponse;
|
||||
use OCA\SCIMServiceProvider\Responses\SCIMErrorResponse;
|
||||
|
||||
class GroupController extends ASCIMGroup {
|
||||
use OCA\SCIMServiceProvider\Service\SCIMGroup;
|
||||
|
||||
class GroupController extends ApiController {
|
||||
|
||||
/** @var LoggerInterface */
|
||||
private $logger;
|
||||
private $SCIMGroup;
|
||||
|
||||
public function __construct(string $appName,
|
||||
IRequest $request,
|
||||
IUserManager $userManager,
|
||||
IConfig $config,
|
||||
IGroupManager $groupManager,
|
||||
IUserSession $userSession,
|
||||
IAccountManager $accountManager,
|
||||
LoggerInterface $logger) {
|
||||
LoggerInterface $logger,
|
||||
SCIMGroup $SCIMGroup) {
|
||||
parent::__construct($appName,
|
||||
$request,
|
||||
$userManager,
|
||||
$config,
|
||||
$groupManager,
|
||||
$userSession,
|
||||
$accountManager);
|
||||
$groupManager);
|
||||
|
||||
$this->logger = $logger;
|
||||
$this->SCIMGroup = $SCIMGroup;
|
||||
$this->groupManager = $groupManager;
|
||||
$this->userManager = $userManager;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -48,7 +47,7 @@ class GroupController extends ASCIMGroup {
|
|||
public function index(): SCIMListResponse {
|
||||
$SCIMGroups = $this->groupManager->search('', null, 0);
|
||||
$SCIMGroups = array_map(function ($group) {
|
||||
return $this->getSCIMGroup($group->getGID());
|
||||
return $this->SCIMGroup->get($group->getGID());
|
||||
}, $SCIMGroups);
|
||||
return new SCIMListResponse($SCIMGroups);
|
||||
}
|
||||
|
@ -63,8 +62,7 @@ class GroupController extends ASCIMGroup {
|
|||
* @throws Exception
|
||||
*/
|
||||
public function show(string $id): SCIMJSONResponse {
|
||||
$group = $this->getSCIMGroup($id);
|
||||
// getUserData returns empty array if not enough permissions
|
||||
$group = $this->SCIMGroup->get($id);
|
||||
if (empty($group)) {
|
||||
return new SCIMErrorResponse(['message' => 'Group not found'], 404);
|
||||
}
|
||||
|
@ -101,7 +99,7 @@ class GroupController extends ASCIMGroup {
|
|||
$targetUser = $this->userManager->get($member['value']);
|
||||
$group->addUser($targetUser);
|
||||
}
|
||||
return new SCIMJSONResponse($this->getSCIMGroup($id));
|
||||
return new SCIMJSONResponse($this->SCIMGroup->get($id));
|
||||
}
|
||||
|
||||
|
||||
|
@ -127,7 +125,7 @@ class GroupController extends ASCIMGroup {
|
|||
$group->addUser($targetUser);
|
||||
// todo implement member removal (:
|
||||
}
|
||||
return new SCIMJSONResponse($this->getSCIMGroup($id));
|
||||
return new SCIMJSONResponse($this->SCIMGroup->get($id));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -4,46 +4,42 @@ declare(strict_types=1);
|
|||
|
||||
namespace OCA\SCIMServiceProvider\Controller;
|
||||
|
||||
use OCP\Accounts\IAccountManager;
|
||||
use OCP\AppFramework\ApiController;
|
||||
use OCP\AppFramework\Http\Response;
|
||||
use OCP\IConfig;
|
||||
use OCP\IGroupManager;
|
||||
use OCP\IRequest;
|
||||
use OCP\IUserManager;
|
||||
use OCP\IUserSession;
|
||||
use OCP\Security\ISecureRandom;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use OCA\SCIMServiceProvider\Responses\SCIMListResponse;
|
||||
use OCA\SCIMServiceProvider\Responses\SCIMJSONResponse;
|
||||
use OCA\SCIMServiceProvider\Responses\SCIMErrorResponse;
|
||||
|
||||
class UserController extends ASCIMUser {
|
||||
use OCA\SCIMServiceProvider\Service\SCIMUser;
|
||||
|
||||
|
||||
class UserController extends ApiController {
|
||||
|
||||
/** @var LoggerInterface */
|
||||
private $logger;
|
||||
/** @var ISecureRandom */
|
||||
private $secureRandom;
|
||||
private $SCIMUser;
|
||||
|
||||
|
||||
public function __construct(string $appName,
|
||||
IRequest $request,
|
||||
IUserManager $userManager,
|
||||
IConfig $config,
|
||||
IGroupManager $groupManager,
|
||||
IUserSession $userSession,
|
||||
IAccountManager $accountManager,
|
||||
LoggerInterface $logger,
|
||||
ISecureRandom $secureRandom) {
|
||||
ISecureRandom $secureRandom,
|
||||
SCIMUser $SCIMUser) {
|
||||
parent::__construct($appName,
|
||||
$request,
|
||||
$userManager,
|
||||
$config,
|
||||
$groupManager,
|
||||
$userSession,
|
||||
$accountManager);
|
||||
$userManager);
|
||||
|
||||
$this->logger = $logger;
|
||||
$this->secureRandom = $secureRandom;
|
||||
$this->SCIMUser = $SCIMUser;
|
||||
$this->userManager = $userManager;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -59,7 +55,7 @@ class UserController extends ASCIMUser {
|
|||
$SCIMUsers = array();
|
||||
foreach ($userIds as $userId) {
|
||||
$userId = (string) $userId;
|
||||
$SCIMUser = $this->getSCIMUser($userId);
|
||||
$SCIMUser = $this->SCIMUser->get($userId);
|
||||
// Do not insert empty entry
|
||||
if (!empty($SCIMUser)) {
|
||||
$SCIMUsers[] = $SCIMUser;
|
||||
|
@ -79,7 +75,7 @@ class UserController extends ASCIMUser {
|
|||
* @throws Exception
|
||||
*/
|
||||
public function show(string $id): SCIMJSONResponse {
|
||||
$user = $this->getSCIMUser($id);
|
||||
$user = $this->SCIMUser->get($id);
|
||||
// getUserData returns empty array if not enough permissions
|
||||
if (empty($user)) {
|
||||
return new SCIMErrorResponse(['message' => 'User not found'], 404);
|
||||
|
@ -116,7 +112,7 @@ class UserController extends ASCIMUser {
|
|||
}
|
||||
}
|
||||
$newUser->setEnabled($active);
|
||||
return new SCIMJSONResponse($this->getSCIMUser($userName));
|
||||
return new SCIMJSONResponse($this->SCIMUser->get($userName));
|
||||
} catch (Exception $e) {
|
||||
$this->logger->warning('Failed createUser attempt with SCIMException exeption.', ['app' => 'SCIMServiceProvider']);
|
||||
throw $e;
|
||||
|
@ -151,7 +147,7 @@ class UserController extends ASCIMUser {
|
|||
if (isset($active)) {
|
||||
$targetUser->setEnabled($active);
|
||||
}
|
||||
return new SCIMJSONResponse($this->getSCIMUser($id));
|
||||
return new SCIMJSONResponse($this->SCIMUser->get($id));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -2,43 +2,17 @@
|
|||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace OCA\SCIMServiceProvider\Controller;
|
||||
namespace OCA\SCIMServiceProvider\Service;
|
||||
|
||||
use OC\Group\Manager;
|
||||
use OCP\Accounts\IAccountManager;
|
||||
use OCP\AppFramework\ApiController;
|
||||
use OCP\IConfig;
|
||||
use OCP\IGroupManager;
|
||||
use OCP\IRequest;
|
||||
use OCP\IUserManager;
|
||||
use OCP\IUserSession;
|
||||
|
||||
abstract class ASCIMGroup extends ApiController {
|
||||
/** @var IUserManager */
|
||||
protected $userManager;
|
||||
/** @var IConfig */
|
||||
protected $config;
|
||||
class SCIMGroup {
|
||||
/** @var IGroupManager|Manager */ // FIXME Requires a method that is not on the interface
|
||||
protected $groupManager;
|
||||
/** @var IUserSession */
|
||||
protected $userSession;
|
||||
/** @var IAccountManager */
|
||||
protected $accountManager;
|
||||
|
||||
public function __construct(string $appName,
|
||||
IRequest $request,
|
||||
IUserManager $userManager,
|
||||
IConfig $config,
|
||||
IGroupManager $groupManager,
|
||||
IUserSession $userSession,
|
||||
IAccountManager $accountManager) {
|
||||
parent::__construct($appName, $request);
|
||||
|
||||
$this->userManager = $userManager;
|
||||
$this->config = $config;
|
||||
public function __construct(IGroupManager $groupManager) {
|
||||
$this->groupManager = $groupManager;
|
||||
$this->userSession = $userSession;
|
||||
$this->accountManager = $accountManager;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -49,7 +23,7 @@ abstract class ASCIMGroup extends ApiController {
|
|||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function getSCIMGroup(string $groupId): array {
|
||||
public function get(string $groupId): array {
|
||||
$groupId = urldecode($groupId);
|
||||
|
||||
// Check the group exists
|
|
@ -2,43 +2,21 @@
|
|||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace OCA\SCIMServiceProvider\Controller;
|
||||
namespace OCA\SCIMServiceProvider\Service;
|
||||
|
||||
use OC\Group\Manager;
|
||||
use OCP\Accounts\IAccountManager;
|
||||
use OCP\AppFramework\ApiController;
|
||||
use OCP\IConfig;
|
||||
use OCP\IGroupManager;
|
||||
use OCP\IRequest;
|
||||
use OCP\IUserManager;
|
||||
use OCP\IUserSession;
|
||||
|
||||
abstract class ASCIMUser extends ApiController {
|
||||
class SCIMUser {
|
||||
/** @var IUserManager */
|
||||
protected $userManager;
|
||||
/** @var IConfig */
|
||||
protected $config;
|
||||
/** @var IGroupManager|Manager */ // FIXME Requires a method that is not on the interface
|
||||
protected $groupManager;
|
||||
/** @var IUserSession */
|
||||
protected $userSession;
|
||||
/** @var IAccountManager */
|
||||
protected $accountManager;
|
||||
|
||||
public function __construct(string $appName,
|
||||
IRequest $request,
|
||||
IUserManager $userManager,
|
||||
IConfig $config,
|
||||
IGroupManager $groupManager,
|
||||
IUserSession $userSession,
|
||||
IAccountManager $accountManager) {
|
||||
parent::__construct($appName, $request);
|
||||
|
||||
public function __construct(IUserManager $userManager,
|
||||
IConfig $config) {
|
||||
$this->userManager = $userManager;
|
||||
$this->config = $config;
|
||||
$this->groupManager = $groupManager;
|
||||
$this->userSession = $userSession;
|
||||
$this->accountManager = $accountManager;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -49,7 +27,7 @@ abstract class ASCIMUser extends ApiController {
|
|||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function getSCIMUser(string $userId): array {
|
||||
public function get(string $userId): array {
|
||||
// Check if the target user exists
|
||||
$targetUserObject = $this->userManager->get($userId);
|
||||
if ($targetUserObject === null) {
|
Loading…
Reference in a new issue