refactor(kernel): unify HTTP and CLI application lifecycle

Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
2026-07-27 00:48:11 -04:00
parent 98826143a8
commit 65c1b5fb75
67 changed files with 2737 additions and 1070 deletions
+10 -10
View File
@@ -10,7 +10,7 @@ use KTXC\Security\Authentication\AuthenticationRequest;
use KTXC\Security\Authentication\AuthenticationResponse;
use KTXC\Service\TokenService;
use KTXC\Service\UserAccountsService;
use KTXC\SessionTenant;
use KTXC\Context\TenantContextInterface;
use KTXF\Cache\CacheScope;
use KTXF\Cache\EphemeralCacheInterface;
use KTXF\Security\Authentication\AuthenticationProviderInterface;
@@ -26,13 +26,13 @@ class AuthenticationManager
private string $securityCode;
public function __construct(
private readonly SessionTenant $tenant,
private readonly TenantContextInterface $tenantContext,
private readonly EphemeralCacheInterface $cache,
private readonly ProviderManager $providerManager,
private readonly TokenService $tokenService,
private readonly UserAccountsService $userService,
) {
$this->securityCode = $this->tenant->configuration()->security()->code();
$this->securityCode = $this->tenantContext->configuration()->security()->code();
}
// =========================================================================
@@ -75,7 +75,7 @@ class AuthenticationManager
$methods = $this->methodsConfigured();
$session = AuthenticationSession::create(
$this->tenant->identifier(),
$this->tenantContext->identifier(),
AuthenticationSession::STATE_FRESH
);
@@ -103,7 +103,7 @@ class AuthenticationManager
// Filter to non-redirect methods since redirects don't need identity first
$methods = $this->methodsConfigured();
$methods = array_values(array_filter($methods, fn($m) => $m['method'] !== 'redirect'));
$require = $this->tenant->configuration()->authentication()->methodsMinimal();
$require = $this->tenantContext->configuration()->authentication()->methodsMinimal();
// Store identity in session without validating to prevent enumeration
$session->setMethods(array_column($methods, 'id'), $require);
@@ -429,7 +429,7 @@ class AuthenticationManager
$session->methodCompleted($method);
// Check if MFA is required
$require = $this->tenant->configuration()->authentication()->methodsMinimal();
$require = $this->tenantContext->configuration()->authentication()->methodsMinimal();
if ($require > 1) {
$remainingMethods = $this->methodsConfigured([$method]);
// Filter out redirect methods - they can't be used as secondary factors
@@ -523,7 +523,7 @@ class AuthenticationManager
$accessToken = $this->tokenService->createToken(
[
'tenant' => $this->tenant->identifier(),
'tenant' => $this->tenantContext->identifier(),
'identifier' => $user->getId(),
'identity' => $user->getIdentity(),
'label' => $user->getLabel(),
@@ -585,7 +585,7 @@ class AuthenticationManager
*/
private function getProviderConfig(string $method): array
{
$providers = $this->tenant->configuration()->authentication()->providers();
$providers = $this->tenantContext->configuration()->authentication()->providers();
return $providers[$method]['config'] ?? [];
}
@@ -635,7 +635,7 @@ class AuthenticationManager
*/
private function methodsConfigured(array $methodsCompleted = []): array
{
$tenantProviders = $this->tenant->configuration()->authentication()->providers();
$tenantProviders = $this->tenantContext->configuration()->authentication()->providers();
$methods = [];
foreach ($tenantProviders as $providerId => $providerConfiguration) {
@@ -669,7 +669,7 @@ class AuthenticationManager
private function createTokens(User $user, bool $mfaVerified = false): array
{
$payload = [
'tenant' => $this->tenant->identifier(),
'tenant' => $this->tenantContext->identifier(),
'identifier' => $user->getId(),
'identity' => $user->getIdentity(),
'label' => $user->getLabel(),
@@ -2,7 +2,7 @@
namespace KTXC\Security\Authorization;
use KTXC\SessionIdentity;
use KTXC\Context\IdentityContextInterface;
/**
* Permission Checker
@@ -11,7 +11,7 @@ use KTXC\SessionIdentity;
class PermissionChecker
{
public function __construct(
private readonly SessionIdentity $sessionIdentity
private readonly IdentityContextInterface $identityContext
) {}
/**
@@ -24,7 +24,7 @@ class PermissionChecker
*/
public function can(string $permission, mixed $resource = null): bool
{
$identity = $this->sessionIdentity->identity();
$identity = $this->identityContext->identity();
if (!$identity) {
return false;
@@ -113,7 +113,7 @@ class PermissionChecker
*/
public function getUserPermissions(): array
{
$identity = $this->sessionIdentity->identity();
$identity = $this->identityContext->identity();
if (!$identity) {
return [];