app: Consolidate and correct references to app ID and config keys

- Make Application::APP_ID lowercase.
- Replace hardcoded 'SCIMServiceProvider' references with Application::APP_ID.
- Replace config key 'ExternalId' with 'externalId' to match SCIM data.

Example SQL to make corresponding changes in the DB:

update oc_preferences set appid='scimserviceprovider' where appid='SCIMServiceProvider';
update oc_preferences set configkey='externalId' where lower(appid)='scimserviceprovider' and configkey='ExternalId';
This commit is contained in:
Leo R. Lundgren 2023-03-04 15:49:39 +01:00 committed by Hugo Renard
parent 50266601a7
commit e8b8c9e1dc
Signed by: hougo
GPG key ID: 3A285FD470209C59
5 changed files with 11 additions and 7 deletions

View file

@ -2,6 +2,7 @@
namespace OCA\SCIMServiceProvider\Adapter\Users; namespace OCA\SCIMServiceProvider\Adapter\Users;
use OCA\SCIMServiceProvider\AppInfo\Application;
use OCP\IConfig; use OCP\IConfig;
use OCP\IUser; use OCP\IUser;
use OCP\IUserManager; use OCP\IUserManager;
@ -63,7 +64,7 @@ class NextcloudUserAdapter extends AbstractAdapter
$coreUser->setDisplayName($ncUser->getDisplayName()); $coreUser->setDisplayName($ncUser->getDisplayName());
$coreUser->setActive($ncUser->isEnabled()); $coreUser->setActive($ncUser->isEnabled());
$ncUserExternalId = $this->config->getUserValue($ncUser->getUID(), 'SCIMServiceProvider', 'ExternalId', ''); $ncUserExternalId = $this->config->getUserValue($ncUser->getUID(), Application::APP_ID, 'externalId', '');
$coreUser->setExternalId($ncUserExternalId); $coreUser->setExternalId($ncUserExternalId);
if ($ncUser->getEMailAddress() !== null && !empty($ncUser->getEMailAddress())) { if ($ncUser->getEMailAddress() !== null && !empty($ncUser->getEMailAddress())) {
@ -106,7 +107,7 @@ class NextcloudUserAdapter extends AbstractAdapter
} }
if ($coreUser->getExternalId() !== null && !empty($coreUser->getExternalId())) { if ($coreUser->getExternalId() !== null && !empty($coreUser->getExternalId())) {
$this->config->setUserValue($ncUser->getUID(), 'SCIMServiceProvider', 'ExternalId', $coreUser->getExternalId()); $this->config->setUserValue($ncUser->getUID(), Application::APP_ID, 'externalId', $coreUser->getExternalId());
} }
if ($coreUser->getEmails() !== null && !empty($coreUser->getEmails())) { if ($coreUser->getEmails() !== null && !empty($coreUser->getEmails())) {

View file

@ -36,7 +36,7 @@ use Psr\Container\ContainerInterface;
*/ */
class Application extends App implements IBootstrap class Application extends App implements IBootstrap
{ {
public const APP_ID = 'SCIMServiceProvider'; public const APP_ID = 'scimserviceprovider';
public function __construct(array $urlParams = []) public function __construct(array $urlParams = [])
{ {

View file

@ -5,6 +5,7 @@ declare(strict_types=1);
namespace OCA\SCIMServiceProvider\Service; namespace OCA\SCIMServiceProvider\Service;
use Exception; use Exception;
use OCA\SCIMServiceProvider\AppInfo\Application;
use OCA\SCIMServiceProvider\Responses\SCIMErrorResponse; use OCA\SCIMServiceProvider\Responses\SCIMErrorResponse;
use OCA\SCIMServiceProvider\Responses\SCIMJSONResponse; use OCA\SCIMServiceProvider\Responses\SCIMJSONResponse;
use OCA\SCIMServiceProvider\Responses\SCIMListResponse; use OCA\SCIMServiceProvider\Responses\SCIMListResponse;
@ -102,7 +103,7 @@ class GroupService
return new SCIMErrorResponse(['message' => 'Creating group failed'], 400); return new SCIMErrorResponse(['message' => 'Creating group failed'], 400);
} }
} catch (Exception $e) { } catch (Exception $e) {
$this->logger->warning('Failed createGroup attempt with SCIMException exception.', ['app' => 'SCIMServiceProvider']); $this->logger->warning('Failed createGroup attempt with SCIMException exception.', ['app' => Application::APP_ID]);
throw $e; throw $e;
} }
} }

View file

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace OCA\SCIMServiceProvider\Service; namespace OCA\SCIMServiceProvider\Service;
use OCA\SCIMServiceProvider\AppInfo\Application;
use OCP\IConfig; use OCP\IConfig;
use OCP\IUserManager; use OCP\IUserManager;
@ -35,7 +36,7 @@ class SCIMUser {
} }
$enabled = $this->config->getUserValue($targetUserObject->getUID(), 'core', 'enabled', 'true') === 'true'; $enabled = $this->config->getUserValue($targetUserObject->getUID(), 'core', 'enabled', 'true') === 'true';
$externalId = $this->config->getUserValue($targetUserObject->getUID(), 'SCIMServiceProvider', 'ExternalId', ''); $externalId = $this->config->getUserValue($targetUserObject->getUID(), Application::APP_ID, 'externalId', '');
$email = $targetUserObject->getSystemEMailAddress(); $email = $targetUserObject->getSystemEMailAddress();
@ -78,7 +79,7 @@ class SCIMUser {
* @throws Exception * @throws Exception
*/ */
public function setExternalId(string $userId, string $externalId) { public function setExternalId(string $userId, string $externalId) {
$this->config->setUserValue($userId, 'SCIMServiceProvider', 'ExternalId', $externalId); $this->config->setUserValue($userId, Application::APP_ID, 'externalId', $externalId);
} }
} }

View file

@ -5,6 +5,7 @@ declare(strict_types=1);
namespace OCA\SCIMServiceProvider\Service; namespace OCA\SCIMServiceProvider\Service;
use Exception; use Exception;
use OCA\SCIMServiceProvider\AppInfo\Application;
use OCA\SCIMServiceProvider\Responses\SCIMErrorResponse; use OCA\SCIMServiceProvider\Responses\SCIMErrorResponse;
use OCA\SCIMServiceProvider\Responses\SCIMJSONResponse; use OCA\SCIMServiceProvider\Responses\SCIMJSONResponse;
use OCA\SCIMServiceProvider\Responses\SCIMListResponse; use OCA\SCIMServiceProvider\Responses\SCIMListResponse;
@ -94,7 +95,7 @@ class UserService
return new SCIMErrorResponse(['message' => 'Creating user failed'], 400); return new SCIMErrorResponse(['message' => 'Creating user failed'], 400);
} }
} catch (Exception $e) { } catch (Exception $e) {
$this->logger->warning('Failed createUser attempt with SCIMException exeption.', ['app' => 'SCIMServiceProvider']); $this->logger->warning('Failed createUser attempt with SCIMException exeption.', ['app' => Application::APP_ID]);
throw $e; throw $e;
} }
} }