- Move 12 markdown files from root to docs/ subdirectories - Organize documentation by category: • docs/troubleshooting/ (1 file) - Technical troubleshooting guides • docs/deployment/ (4 files) - Deployment and security documentation • docs/guides/ (3 files) - Feature-specific guides • docs/planning/ (4 files) - Planning and improvement proposals Root directory cleanup: - Reduced from 16 to 4 markdown files in root - Only essential project files remain: • CLAUDE.md (AI instructions) • README.md (Main project readme) • CLEANUP_PLAN.md (Current cleanup plan) • SRC_STRUCTURE_IMPROVEMENTS.md (Structure improvements) This improves: ✅ Documentation discoverability ✅ Logical organization by purpose ✅ Clean root directory ✅ Better maintainability
97 lines
2.8 KiB
PHP
97 lines
2.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Framework\Console\Security;
|
|
|
|
use App\Framework\Environment\Environment;
|
|
use App\Framework\Environment\EnvKey;
|
|
|
|
final readonly class EnvironmentUserProvider implements UserProvider
|
|
{
|
|
public function __construct(
|
|
private Environment $environment
|
|
) {
|
|
}
|
|
|
|
public function getCurrentUser(): ConsoleUser
|
|
{
|
|
$userId = $this->environment->get(EnvKey::CONSOLE_USER_ID);
|
|
$userName = $this->environment->get(EnvKey::CONSOLE_USER_NAME);
|
|
$userRole = $this->environment->get(EnvKey::CONSOLE_USER_ROLE, 'user');
|
|
|
|
if (! $userId || ! $userName) {
|
|
return ConsoleUser::anonymous();
|
|
}
|
|
|
|
$permissions = $this->getPermissionsForRole($userRole);
|
|
$roles = [$userRole];
|
|
|
|
return new ConsoleUser(
|
|
id: $userId,
|
|
name: $userName,
|
|
permissions: $permissions,
|
|
roles: $roles
|
|
);
|
|
}
|
|
|
|
public function getUserById(string $id): ?ConsoleUser
|
|
{
|
|
$currentUser = $this->getCurrentUser();
|
|
|
|
return $currentUser->id === $id ? $currentUser : null;
|
|
}
|
|
|
|
public function authenticateUser(array $credentials): ?ConsoleUser
|
|
{
|
|
// For environment-based auth, we just return the current user
|
|
// In a real implementation, this might validate API keys or tokens
|
|
return $this->getCurrentUser();
|
|
}
|
|
|
|
public function isAuthenticated(): bool
|
|
{
|
|
$userId = $this->environment->get(EnvKey::CONSOLE_USER_ID);
|
|
|
|
return ! empty($userId) && $userId !== 'anonymous';
|
|
}
|
|
|
|
private function getPermissionsForRole(string $role): array
|
|
{
|
|
return match (strtolower($role)) {
|
|
'admin', 'administrator' => Permission::cases(), // All permissions
|
|
'developer', 'dev' => [
|
|
Permission::READ,
|
|
Permission::WRITE,
|
|
Permission::EXECUTE,
|
|
Permission::ANALYTICS_READ,
|
|
Permission::HEALTH_CHECK,
|
|
Permission::DATABASE_READ,
|
|
Permission::PERFORMANCE_READ,
|
|
],
|
|
'operator', 'ops' => [
|
|
Permission::READ,
|
|
Permission::EXECUTE,
|
|
Permission::ANALYTICS_READ,
|
|
Permission::HEALTH_CHECK,
|
|
Permission::PERFORMANCE_READ,
|
|
Permission::CACHE_MANAGE,
|
|
],
|
|
'readonly', 'reader' => [
|
|
Permission::READ,
|
|
Permission::ANALYTICS_READ,
|
|
Permission::HEALTH_CHECK,
|
|
Permission::PERFORMANCE_READ,
|
|
],
|
|
'guest', 'anonymous' => [
|
|
Permission::READ,
|
|
Permission::EXECUTE,
|
|
],
|
|
default => [
|
|
Permission::READ,
|
|
Permission::EXECUTE,
|
|
]
|
|
};
|
|
}
|
|
}
|