aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMurtaza Sultani <sultani@data-quest.de>2026-03-03 16:18:46 +0100
committerMurtaza Sultani <sultani@data-quest.de>2026-03-19 17:36:05 +0100
commit42fca0679add6403b423c1e939da6104f79ddc4c (patch)
tree1d1501e23ea1569cc89e925c8bc7800679114c5e
parentf56b58cc63fc56ba7cad99f83e71d64b1a74b964 (diff)
Use DI
-rw-r--r--app/controllers/enroll/lti/jwks.php4
-rw-r--r--app/controllers/lti/1p3/ags/line_item.php2
-rw-r--r--app/controllers/lti/1p3/ags/line_items.php2
-rw-r--r--app/controllers/lti/1p3/jwks.php6
-rw-r--r--app/controllers/lti/1p3/login.php2
-rw-r--r--app/controllers/lti/1p3/token.php2
-rw-r--r--lib/bootstrap-definitions.php37
-rw-r--r--lib/classes/Lti/LTI1p3/PlatformManager.php9
-rw-r--r--lib/classes/Lti/LTI1p3/RegistrationRepository.php4
-rw-r--r--lib/classes/Lti/LTI1p3/RepositoryRegistry.php39
-rw-r--r--lib/classes/Lti/LTI1p3/ToolManager.php9
11 files changed, 64 insertions, 52 deletions
diff --git a/app/controllers/enroll/lti/jwks.php b/app/controllers/enroll/lti/jwks.php
index 6690260..9027a24 100644
--- a/app/controllers/enroll/lti/jwks.php
+++ b/app/controllers/enroll/lti/jwks.php
@@ -20,10 +20,10 @@ final class Enroll_Lti_JwksController extends LtiBaseController
public function index_action(): void
{
- $toolKeyring = ToolManager::getKeyring();
+ $toolKeyring = ToolManager::getKeyChain();
$this->renderPsrResponse(
- $this->jwksRequestHandler->handle($toolKeyring->range_id)
+ $this->jwksRequestHandler->handle($toolKeyring->getKeySetName())
);
}
}
diff --git a/app/controllers/lti/1p3/ags/line_item.php b/app/controllers/lti/1p3/ags/line_item.php
index 3e42aa8..6432bb0 100644
--- a/app/controllers/lti/1p3/ags/line_item.php
+++ b/app/controllers/lti/1p3/ags/line_item.php
@@ -10,7 +10,7 @@ use OAT\Library\Lti1p3Ags\Service\LineItem\Server\Handler\GetLineItemServiceServ
use OAT\Library\Lti1p3Ags\Service\LineItem\Server\Handler\DeleteLineItemServiceServerRequestHandler;
use OAT\Library\Lti1p3Ags\Service\LineItem\Server\Handler\UpdateLineItemServiceServerRequestHandler;
-class Lti_1p3_Ags_LineItemController extends AuthenticatedController
+final class Lti_1p3_Ags_LineItemController extends AuthenticatedController
{
protected $allow_nobody = true;
protected $with_session = false;
diff --git a/app/controllers/lti/1p3/ags/line_items.php b/app/controllers/lti/1p3/ags/line_items.php
index a4b6c27..11d83de 100644
--- a/app/controllers/lti/1p3/ags/line_items.php
+++ b/app/controllers/lti/1p3/ags/line_items.php
@@ -8,7 +8,7 @@ use OAT\Library\Lti1p3Core\Security\OAuth2\Validator\RequestAccessTokenValidator
use OAT\Library\Lti1p3Ags\Service\LineItem\Server\Handler\ListLineItemsServiceServerRequestHandler;
use OAT\Library\Lti1p3Ags\Service\LineItem\Server\Handler\CreateLineItemServiceServerRequestHandler;
-class Lti_1p3_Ags_LineItemsController extends AuthenticatedController
+final class Lti_1p3_Ags_LineItemsController extends AuthenticatedController
{
protected $allow_nobody = true;
protected $with_session = false;
diff --git a/app/controllers/lti/1p3/jwks.php b/app/controllers/lti/1p3/jwks.php
index 2ebdd06..9b78110 100644
--- a/app/controllers/lti/1p3/jwks.php
+++ b/app/controllers/lti/1p3/jwks.php
@@ -5,7 +5,7 @@ use Studip\OAuth2\NegotiatesWithPsr7;
use Studip\Lti\LTI1p3\PlatformManager;
use OAT\Library\Lti1p3Core\Security\Jwks\Server\JwksRequestHandler;
-class Lti_1p3_JwksController extends AuthenticatedController
+final class Lti_1p3_JwksController extends AuthenticatedController
{
protected $allow_nobody = true;
protected $with_session = false;
@@ -21,10 +21,10 @@ class Lti_1p3_JwksController extends AuthenticatedController
public function index_action(): void
{
- $platformKeyring = PlatformManager::getKeyring();
+ $platformKeyring = PlatformManager::getKeyChain();
$this->renderPsrResponse(
- $this->jwksRequestHandler->handle($platformKeyring->range_id)
+ $this->jwksRequestHandler->handle($platformKeyring->getKeySetName())
);
}
}
diff --git a/app/controllers/lti/1p3/login.php b/app/controllers/lti/1p3/login.php
index 609bed3..c9d3e03 100644
--- a/app/controllers/lti/1p3/login.php
+++ b/app/controllers/lti/1p3/login.php
@@ -4,7 +4,7 @@ use Trails\Dispatcher;
use Studip\OAuth2\NegotiatesWithPsr7;
use OAT\Library\Lti1p3Core\Security\Oidc\Server\OidcAuthenticationRequestHandler;
-class Lti_1p3_LoginController extends AuthenticatedController
+final class Lti_1p3_LoginController extends AuthenticatedController
{
protected $allow_nobody = true;
protected $with_session = false;
diff --git a/app/controllers/lti/1p3/token.php b/app/controllers/lti/1p3/token.php
index 135ed49..6cc0faf 100644
--- a/app/controllers/lti/1p3/token.php
+++ b/app/controllers/lti/1p3/token.php
@@ -14,7 +14,7 @@ use OAT\Library\Lti1p3Core\Security\OAuth2\Factory\AuthorizationServerFactory;
use OAT\Library\Lti1p3Core\Security\Oidc\Server\OidcAuthenticationRequestHandler;
use OAT\Library\Lti1p3Core\Security\OAuth2\Generator\AccessTokenResponseGenerator;
-class Lti_1p3_TokenController extends AuthenticatedController
+final class Lti_1p3_TokenController extends AuthenticatedController
{
protected $allow_nobody = true;
protected $with_session = false;
diff --git a/lib/bootstrap-definitions.php b/lib/bootstrap-definitions.php
index 2163308..9c11a82 100644
--- a/lib/bootstrap-definitions.php
+++ b/lib/bootstrap-definitions.php
@@ -10,30 +10,13 @@ use Monolog\Handler\StreamHandler;
use Monolog\Logger;
use Nyholm\Psr7\Factory\Psr17Factory;
use Nyholm\Psr7Server\ServerRequestCreator;
-use OAT\Library\Lti1p3Ags\Repository\LineItemRepositoryInterface;
-use OAT\Library\Lti1p3Core\Message\Launch\Validator\Platform\PlatformLaunchValidator;
-use OAT\Library\Lti1p3Core\Message\Launch\Validator\Platform\PlatformLaunchValidatorInterface;
-use OAT\Library\Lti1p3Core\Message\Launch\Validator\Tool\ToolLaunchValidator;
-use OAT\Library\Lti1p3Core\Message\Launch\Validator\Tool\ToolLaunchValidatorInterface;
-use OAT\Library\Lti1p3Core\Registration\RegistrationRepositoryInterface;
-use OAT\Library\Lti1p3Core\Security\Key\KeyChainRepository;
-use OAT\Library\Lti1p3Core\Security\Key\KeyChainRepositoryInterface;
-use OAT\Library\Lti1p3Core\Security\Nonce\NonceRepository;
-use OAT\Library\Lti1p3Core\Security\Nonce\NonceRepositoryInterface;
-use OAT\Library\Lti1p3Core\Security\OAuth2\Validator\RequestAccessTokenValidator;
-use OAT\Library\Lti1p3Core\Security\OAuth2\Validator\RequestAccessTokenValidatorInterface;
-use OAT\Library\Lti1p3Core\Security\User\UserAuthenticatorInterface;
+
use Psr\Cache\CacheItemPoolInterface;
use Psr\Container\ContainerInterface;
use Psr\Log\LoggerInterface;
use Studip\Cache\Factory as CacheFactory;
-use Studip\Lti\LTI1p3\LineItemRepository;
-use Studip\Lti\LTI1p3\PlatformManager;
-use Studip\Lti\LTI1p3\RegistrationManager;
-use Studip\Lti\LTI1p3\ToolManager;
-
-use Studip\Lti\LTI1p3\UserAuthenticator;
+use Studip\Lti\LTI1p3\RepositoryRegistry as LtiRepositoryRegistry;
use function DI\create;
@@ -119,20 +102,8 @@ return [
\Psr\Http\Message\UriFactoryInterface::class => DI\get(Psr17Factory::class),
\Psr\Http\Message\ServerRequestInterface::class => DI\factory([ServerRequestCreator::class, 'fromGlobals']),
+ CacheItemPoolInterface::class => DI\factory(fn() => CacheFactory::getCache()),
// LTI
- RegistrationRepositoryInterface::class => DI\get(RegistrationManager::class),
- NonceRepositoryInterface::class => DI\get(NonceRepository::class),
- PlatformLaunchValidatorInterface::class => DI\get(PlatformLaunchValidator::class),
- ToolLaunchValidatorInterface::class => DI\get(ToolLaunchValidator::class),
- UserAuthenticatorInterface::class => DI\get(UserAuthenticator::class),
- CacheItemPoolInterface::class => DI\factory(fn() => CacheFactory::getCache()),
- LineItemRepositoryInterface::class => DI\factory(fn() => LineItemRepository::class),
- RequestAccessTokenValidatorInterface::class => DI\factory(fn() => RequestAccessTokenValidator::class),
- KeyChainRepositoryInterface::class => DI\factory(function() {
- return new KeyChainRepository([
- PlatformManager::getKeyring()->toKeyChain(),
- ToolManager::getKeyring()->toKeyChain()
- ]);
- }),
+ ...LtiRepositoryRegistry::definitions(),
];
diff --git a/lib/classes/Lti/LTI1p3/PlatformManager.php b/lib/classes/Lti/LTI1p3/PlatformManager.php
index c954fa6..53e97d7 100644
--- a/lib/classes/Lti/LTI1p3/PlatformManager.php
+++ b/lib/classes/Lti/LTI1p3/PlatformManager.php
@@ -3,6 +3,7 @@ namespace Studip\Lti\LTI1p3;
use Config;
use Keyring;
+use OAT\Library\Lti1p3Core\Security\Key\KeyChain;
use URLHelper;
use OAT\Library\Lti1p3Core\Platform\Platform;
use OAT\Library\Lti1p3Core\Security\Key\KeyInterface;
@@ -39,24 +40,24 @@ final class PlatformManager
);
}
- public static function getKeyring(): ?Keyring
+ public static function getKeyChain(): KeyChain
{
$keyring = Keyring::findOneBySQL("`range_type` = 'global' AND `range_id` = 'lti13a_platform'");
if (!$keyring) {
$keyring = Keyring::generate('lti13a_platform', 'global');
}
- return $keyring;
+ return $keyring->toKeyChain();
}
public static function getPrivateKey(): KeyInterface
{
- return self::getKeyring()->toKeyChain()->getPrivateKey();
+ return self::getKeyChain()->getPrivateKey();
}
public static function getPublicKey(): KeyInterface
{
- return self::getKeyring()->toKeyChain()->getPublicKey();
+ return self::getKeyChain()->getPublicKey();
}
public static function getDeepLinkingReturnUrl(string $linkId, string $courseId = ''): string
diff --git a/lib/classes/Lti/LTI1p3/RegistrationRepository.php b/lib/classes/Lti/LTI1p3/RegistrationRepository.php
index d1527b8..5714998 100644
--- a/lib/classes/Lti/LTI1p3/RegistrationRepository.php
+++ b/lib/classes/Lti/LTI1p3/RegistrationRepository.php
@@ -95,7 +95,7 @@ final class RegistrationRepository implements RegistrationInterface
return $this->registration->getKeyChain();
}
- return PlatformManager::getKeyring()->toKeyChain();
+ return PlatformManager::getKeyChain();
}
public function getToolKeyChain(): ?KeyChainInterface
@@ -108,7 +108,7 @@ final class RegistrationRepository implements RegistrationInterface
return $this->registration->getKeyChain();
}
- return ToolManager::getKeyring()->toKeyChain();
+ return ToolManager::getKeyChain();
}
public function getPlatformJwksUrl(): ?string
diff --git a/lib/classes/Lti/LTI1p3/RepositoryRegistry.php b/lib/classes/Lti/LTI1p3/RepositoryRegistry.php
new file mode 100644
index 0000000..18abc4e
--- /dev/null
+++ b/lib/classes/Lti/LTI1p3/RepositoryRegistry.php
@@ -0,0 +1,39 @@
+<?php
+namespace Studip\Lti\LTI1p3;
+
+use DI;
+use OAT\Library\Lti1p3Core\Security\Nonce\NonceRepository;
+use OAT\Library\Lti1p3Core\Security\Key\KeyChainRepository;
+use OAT\Library\Lti1p3Ags\Repository\LineItemRepositoryInterface;
+use OAT\Library\Lti1p3Core\Security\Nonce\NonceRepositoryInterface;
+use OAT\Library\Lti1p3Core\Security\User\UserAuthenticatorInterface;
+use OAT\Library\Lti1p3Core\Security\Key\KeyChainRepositoryInterface;
+use OAT\Library\Lti1p3Core\Registration\RegistrationRepositoryInterface;
+use OAT\Library\Lti1p3Core\Message\Launch\Validator\Tool\ToolLaunchValidator;
+use OAT\Library\Lti1p3Core\Security\OAuth2\Validator\RequestAccessTokenValidator;
+use OAT\Library\Lti1p3Core\Message\Launch\Validator\Platform\PlatformLaunchValidator;
+use OAT\Library\Lti1p3Core\Message\Launch\Validator\Tool\ToolLaunchValidatorInterface;
+use OAT\Library\Lti1p3Core\Security\OAuth2\Validator\RequestAccessTokenValidatorInterface;
+use OAT\Library\Lti1p3Core\Message\Launch\Validator\Platform\PlatformLaunchValidatorInterface;
+
+final class RepositoryRegistry
+{
+ public static function definitions(): array
+ {
+ return [
+ RegistrationRepositoryInterface::class => DI\get(RegistrationManager::class),
+ NonceRepositoryInterface::class => DI\get(NonceRepository::class),
+ PlatformLaunchValidatorInterface::class => DI\get(PlatformLaunchValidator::class),
+ ToolLaunchValidatorInterface::class => DI\get(ToolLaunchValidator::class),
+ UserAuthenticatorInterface::class => DI\get(UserAuthenticator::class),
+ LineItemRepositoryInterface::class => DI\get(LineItemRepository::class),
+ RequestAccessTokenValidatorInterface::class => DI\get(RequestAccessTokenValidator::class),
+ KeyChainRepositoryInterface::class => DI\factory(function() {
+ return new KeyChainRepository([
+ PlatformManager::getKeyChain(),
+ ToolManager::getKeyChain()
+ ]);
+ }),
+ ];
+ }
+}
diff --git a/lib/classes/Lti/LTI1p3/ToolManager.php b/lib/classes/Lti/LTI1p3/ToolManager.php
index 1ad0f53..de0ac8a 100644
--- a/lib/classes/Lti/LTI1p3/ToolManager.php
+++ b/lib/classes/Lti/LTI1p3/ToolManager.php
@@ -6,6 +6,7 @@ use Keyring;
use URLHelper;
use OAT\Library\Lti1p3Core\Tool\Tool;
use OAT\Library\Lti1p3Core\Tool\ToolInterface;
+use OAT\Library\Lti1p3Core\Security\Key\KeyChain;
use OAT\Library\Lti1p3Core\Security\Key\KeyInterface;
final class ToolManager
@@ -24,24 +25,24 @@ final class ToolManager
);
}
- public static function getKeyring(): ?Keyring
+ public static function getKeyChain(): KeyChain
{
$keyring = Keyring::findOneBySQL("`range_type` = 'global' AND `range_id` = 'lti13a_tool'");
if (!$keyring) {
$keyring = Keyring::generate('lti13a_tool', 'global');
}
- return $keyring;
+ return $keyring->toKeyChain();
}
public static function getPrivateKey(): KeyInterface
{
- return self::getKeyring()->toKeyChain()->getPrivateKey();
+ return self::getKeyChain()->getPrivateKey();
}
public static function getPublicKey(): KeyInterface
{
- return self::getKeyring()->toKeyChain()->getPublicKey();
+ return self::getKeyChain()->getPublicKey();
}
public static function getJwksUrl(): string