Improvements
testing/ogcore-api/pipeline/head This commit looks good Details

pull/33/head
Manuel Aranda Rosales 2025-05-19 16:13:08 +02:00
parent 6425e4aaa6
commit 6c1b28176a
3 changed files with 62 additions and 10 deletions

View File

@ -2,7 +2,53 @@
namespace App\Controller;
class AuthValidatorController
{
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Lexik\Bundle\JWTAuthenticationBundle\Services\JWTTokenManagerInterface;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
}
class AuthValidatorController extends AbstractController
{
private JWTTokenManagerInterface $jwtManager;
public function __construct(JWTTokenManagerInterface $jwtManager)
{
$this->jwtManager = $jwtManager;
}
#[Route('/validate', name: 'auth_validate', methods: ['POST'])]
public function validate(Request $request): Response
{
$sslClientVerify = $request->headers->get('SSL_CLIENT_VERIFY');
$clientCertOk = $sslClientVerify === 'SUCCESS';
$authHeader = $request->headers->get('Authorization');
$hasValidJwt = $this->validateJwtToken($authHeader);
if ($clientCertOk || $hasValidJwt) {
return new Response('Authorized', Response::HTTP_OK);
}
return new Response('Unauthorized', Response::HTTP_UNAUTHORIZED);
}
private function validateJwtToken(?string $authHeader): bool
{
if (!$authHeader || !str_starts_with($authHeader, 'Bearer ')) {
return false;
}
$token = substr($authHeader, 7);
try {
$payload = $this->jwtManager->parse($token);
return true;
} catch (\Exception $e) {
return false;
}
}
}

View File

@ -51,6 +51,7 @@ class SyncAction extends AbstractOgRepositoryController
$imageEntity->setName($image['name']);
$imageEntity->setRemotePc(false);
$imageEntity->setIsGlobal(false);
$imageEntity->setType('monolithic');
$this->entityManager->persist($imageEntity);
}
@ -59,6 +60,7 @@ class SyncAction extends AbstractOgRepositoryController
$imageImageRepositoryEntity = new ImageImageRepository();
}
$imageImageRepositoryEntity->setName($image['name']);
$imageImageRepositoryEntity->setImageFullsum($image['fullsum']);
$imageImageRepositoryEntity->setDatasize($image['datasize']);
$imageImageRepositoryEntity->setStatus(ImageStatus::SUCCESS);

View File

@ -49,15 +49,19 @@ class CreatePartitionService
$partitionEntity->setOperativeSystem(null);
if (isset($cfg['soi']) && $cfg['soi'] !== '') {
$operativeSystem = $this->entityManager->getRepository(OperativeSystem::class)
->findOneBy(['name' => $cfg['soi']]);
if ($cfg['soi'] === 'DATA') {
$partitionEntity->setImage(null);
} else {
$operativeSystem = $this->entityManager->getRepository(OperativeSystem::class)
->findOneBy(['name' => $cfg['soi']]);
if (!$operativeSystem) {
$operativeSystem = new OperativeSystem();
$operativeSystem->setName($cfg['soi']);
$this->entityManager->persist($operativeSystem);
if (!$operativeSystem) {
$operativeSystem = new OperativeSystem();
$operativeSystem->setName($cfg['soi']);
$this->entityManager->persist($operativeSystem);
}
$partitionEntity->setOperativeSystem($operativeSystem);
}
$partitionEntity->setOperativeSystem($operativeSystem);
}
$partitionEntity->setClient($clientEntity);