Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 5 additions & 16 deletions lib/Controller/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,6 @@ public function __construct(
parent::__construct(Application::APP_ID, $request);
}

/**
* @param int $providerId
* @param string $userId
* @param string|null $displayName
* @param string|null $email
* @param string|null $quota
* @return DataResponse
*/
#[NoCSRFRequired]
public function createUser(int $providerId, string $userId, ?string $displayName = null,
?string $email = null, ?string $quota = null): DataResponse {
Expand All @@ -59,25 +51,22 @@ public function createUser(int $providerId, string $userId, ?string $displayName
$user->setQuota($quota);
}

$userFolder = $this->root->getUserFolder($user->getUID());
$userId = $user->getUID();
$userFolder = $this->root->getUserFolder($userId);
try {
// copy skeleton
\OC_Util::copySkeleton($user->getUID(), $userFolder);
\OC_Util::copySkeleton($userId, $userFolder);
} catch (NotPermittedException $ex) {
// read only uses
}

return new DataResponse(['user_id' => $user->getUID()]);
return new DataResponse(['user_id' => $userId]);
}

/**
* @param string $userId
* @return DataResponse
*/
#[NoCSRFRequired]
public function deleteUser(string $userId): DataResponse {
$user = $this->userManager->get($userId);
if (is_null($user) || $user->getBackendClassName() !== Application::APP_ID) {
if ($user === null || $user->getBackendClassName() !== Application::APP_ID) {
return new DataResponse(['message' => 'User not found'], Http::STATUS_NOT_FOUND);
}

Expand Down
68 changes: 13 additions & 55 deletions lib/Controller/BaseOidcController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,60 +26,39 @@ public function __construct(
parent::__construct(Application::APP_ID, $request);
}

/**
* @return bool
*/
protected function isDebugModeEnabled(): bool {
return $this->config->getSystemValueBool('debug', false);
}

/**
* @param string $message
* @param int $statusCode
* @param array $throttleMetadata
* @param bool|null $throttle
* @return TemplateResponse
*/
protected function buildErrorTemplateResponse(string $message, int $statusCode, array $throttleMetadata = [], ?bool $throttle = null): TemplateResponse {
protected function buildErrorTemplateResponse(
string $message, int $statusCode, array $throttleMetadata = [], ?bool $throttle = null
): TemplateResponse {
$params = [
'message' => $message,
'title' => $this->l->t('Error'),
];
return $this->buildFailureTemplateResponse($params, $statusCode, $throttleMetadata, $throttle);
}

/**
* @param string $message
* @param int $statusCode
* @param array $throttleMetadata
* @param bool|null $throttle
* @return TemplateResponse
*/
protected function build403TemplateResponse(string $message, int $statusCode, array $throttleMetadata = [], ?bool $throttle = null): TemplateResponse {
protected function build403TemplateResponse(string $message, int $statusCode, array $throttleMetadata = [],
?bool $throttle = null): TemplateResponse {
$params = [
'message' => $message,
'title' => $this->l->t('Access forbidden'),
];
return $this->buildFailureTemplateResponse($params, $statusCode, $throttleMetadata, $throttle);
}

/**
* @param array $params
* @param int $statusCode
* @param array $throttleMetadata
* @param bool|null $throttle
* @return TemplateResponse
*/
protected function buildFailureTemplateResponse(
array $params, int $statusCode, array $throttleMetadata = [], ?bool $throttle = null,
): TemplateResponse {
protected function buildFailureTemplateResponse(array $params, int $statusCode, array $throttleMetadata = [],
?bool $throttle = null): TemplateResponse {
$response = new TemplateResponse(
Application::APP_ID,
'error',
$params,
TemplateResponse::RENDER_AS_ERROR
);
$response->setStatus($statusCode);

// if not specified, throttle if debug mode is off
if (($throttle === null && !$this->isDebugModeEnabled()) || $throttle) {
$response->throttle($throttleMetadata);
Expand All @@ -89,15 +68,8 @@ protected function buildFailureTemplateResponse(

// TODO: use the following methods only when 32 is the min supported version
// as it includes the "back to NC" button

/**
* @param string $message
* @param int $statusCode
* @param array $throttleMetadata
* @param bool|null $throttle
* @return TemplateResponse
*/
protected function buildCoreErrorTemplateResponse(string $message, int $statusCode, array $throttleMetadata = [], ?bool $throttle = null): TemplateResponse {
protected function buildCoreErrorTemplateResponse(string $message, int $statusCode, array $throttleMetadata = [],
?bool $throttle = null): TemplateResponse {
$params = [
'errors' => [
['error' => $message],
Expand All @@ -106,27 +78,12 @@ protected function buildCoreErrorTemplateResponse(string $message, int $statusCo
return $this->buildCoreFailureTemplateResponse('', 'error', $params, $statusCode, $throttleMetadata, $throttle);
}

/**
* @param string $message
* @param int $statusCode
* @param array $throttleMetadata
* @param bool|null $throttle
* @return TemplateResponse
*/
protected function buildCore403TemplateResponse(string $message, int $statusCode, array $throttleMetadata = [], ?bool $throttle = null): TemplateResponse {
protected function buildCore403TemplateResponse(string $message, int $statusCode, array $throttleMetadata = [],
?bool $throttle = null): TemplateResponse {
$params = ['message' => $message];
return $this->buildCoreFailureTemplateResponse('core', '403', $params, $statusCode, $throttleMetadata, $throttle);
}

/**
* @param string $appName
* @param string $templateName
* @param array $params
* @param int $statusCode
* @param array $throttleMetadata
* @param bool|null $throttle
* @return TemplateResponse
*/
protected function buildCoreFailureTemplateResponse(string $appName, string $templateName, array $params, int $statusCode,
array $throttleMetadata = [], ?bool $throttle = null): TemplateResponse {
$response = new TemplateResponse(
Expand All @@ -136,6 +93,7 @@ protected function buildCoreFailureTemplateResponse(string $appName, string $tem
TemplateResponse::RENDER_AS_ERROR
);
$response->setStatus($statusCode);

// if not specified, throttle if debug mode is off
if (($throttle === null && !$this->isDebugModeEnabled()) || $throttle) {
$response->throttle($throttleMetadata);
Expand Down
30 changes: 13 additions & 17 deletions lib/Controller/Id4meController.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,33 +55,33 @@

public function __construct(
IRequest $request,
private ISecureRandom $random,
private ISession $session,
private readonly ISecureRandom $random,

Check failure on line 58 in lib/Controller/Id4meController.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

ParseError

lib/Controller/Id4meController.php:58:20: ParseError: Syntax error, unexpected T_STRING, expecting T_VARIABLE on line 58 (see https://psalm.dev/173)

Check failure on line 58 in lib/Controller/Id4meController.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

InvalidDocblock

lib/Controller/Id4meController.php:58:3: InvalidDocblock: Param2 of OCA\UserOIDC\Controller\Id4meController::__construct has invalid syntax (see https://psalm.dev/008)
private readonly ISession $session,
IConfig $config,
private IL10N $l10n,
private ITimeFactory $timeFactory,
private IClientService $clientService,
private IURLGenerator $urlGenerator,
private UserMapper $userMapper,
private IUserSession $userSession,
private IUserManager $userManager,
private readonly IL10N $l10n,
private readonly ITimeFactory $timeFactory,
private readonly IClientService $clientService,
private readonly IURLGenerator $urlGenerator,
private readonly UserMapper $userMapper,
private readonly IUserSession $userSession,
private readonly IUserManager $userManager,
HttpClientHelper $clientHelper,
private Id4MeMapper $id4MeMapper,
private ID4MeService $id4MeService,
private LoggerInterface $logger,
private ICrypto $crypto,
private readonly Id4MeMapper $id4MeMapper,
private readonly ID4MeService $id4MeService,
private readonly LoggerInterface $logger,
private readonly ICrypto $crypto,
) {
parent::__construct($request, $config, $l10n);

Check failure on line 74 in lib/Controller/Id4meController.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

UndefinedVariable

lib/Controller/Id4meController.php:74:42: UndefinedVariable: Cannot find referenced variable $l10n (see https://psalm.dev/024)

Check failure on line 74 in lib/Controller/Id4meController.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

UndefinedVariable

lib/Controller/Id4meController.php:74:33: UndefinedVariable: Cannot find referenced variable $config (see https://psalm.dev/024)

$this->id4me = new Service($clientHelper);

Check failure on line 76 in lib/Controller/Id4meController.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

UndefinedVariable

lib/Controller/Id4meController.php:76:30: UndefinedVariable: Cannot find referenced variable $clientHelper (see https://psalm.dev/024)
}

#[PublicPage]
#[NoCSRFRequired]
#[UseSession]
public function showLogin() {
if (!$this->id4MeService->getID4ME()) {

Check failure on line 83 in lib/Controller/Id4meController.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

UndefinedThisPropertyFetch

lib/Controller/Id4meController.php:83:8: UndefinedThisPropertyFetch: Instance property OCA\UserOIDC\Controller\Id4meController::$id4MeService is not defined (see https://psalm.dev/041)
$message = $this->l10n->t('ID4Me is disabled');

Check failure on line 84 in lib/Controller/Id4meController.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

UndefinedThisPropertyFetch

lib/Controller/Id4meController.php:84:15: UndefinedThisPropertyFetch: Instance property OCA\UserOIDC\Controller\Id4meController::$l10n is not defined (see https://psalm.dev/041)
return $this->build403TemplateResponse($message, Http::STATUS_FORBIDDEN, [], false);
}

Expand All @@ -97,22 +97,21 @@
}

/**
* @param string $domain
* @return RedirectResponse|TemplateResponse
*/
#[PublicPage]
#[UseSession]
#[BruteForceProtection(action: 'userOidcId4MeLogin')]
public function login(string $domain) {
if (!$this->id4MeService->getID4ME()) {

Check failure on line 106 in lib/Controller/Id4meController.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

UndefinedThisPropertyFetch

lib/Controller/Id4meController.php:106:8: UndefinedThisPropertyFetch: Instance property OCA\UserOIDC\Controller\Id4meController::$id4MeService is not defined (see https://psalm.dev/041)
$message = $this->l10n->t('ID4Me is disabled');

Check failure on line 107 in lib/Controller/Id4meController.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

UndefinedThisPropertyFetch

lib/Controller/Id4meController.php:107:15: UndefinedThisPropertyFetch: Instance property OCA\UserOIDC\Controller\Id4meController::$l10n is not defined (see https://psalm.dev/041)
return $this->build403TemplateResponse($message, Http::STATUS_FORBIDDEN, [], false);
}

try {
$authorityName = $this->id4me->discover($domain);
} catch (InvalidOpenIdDomainException|OpenIdDnsRecordNotFoundException $e) {
$message = $this->l10n->t('Invalid OpenID domain');

Check failure on line 114 in lib/Controller/Id4meController.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

UndefinedThisPropertyFetch

lib/Controller/Id4meController.php:114:15: UndefinedThisPropertyFetch: Instance property OCA\UserOIDC\Controller\Id4meController::$l10n is not defined (see https://psalm.dev/041)
return $this->buildErrorTemplateResponse($message, Http::STATUS_BAD_REQUEST, ['invalid_openid_domain' => $domain]);
}
try {
Expand Down Expand Up @@ -166,9 +165,6 @@
}

/**
* @param string $state
* @param string $code
* @param string $scope
* @return JSONResponse|RedirectResponse|TemplateResponse
* @throws \Exception
*/
Expand Down
Loading
Loading