davide.cucurnia@vola.it
2024-02-07 68b84d1f652aae4644c2dde96d9bb99e358294e8
commit | author | age
9f6455 1 <?php
DC 2
3 namespace App\Http\Controllers\FakeResponder;
4
5 use App\Http\Controllers\Controller;
24347e 6 use App\Http\Requests\genericPicasso;
9f6455 7 use App\Vola\Services\VolaFakeHTTPResponder\VolaFakeHTTPResponder;
DC 8 use Illuminate\Http\Request;
398fc7 9 use App\Vola\Classes\Utils;
9f6455 10
DC 11 class FakeResponder extends Controller
12 {
13
14     public string $cookieFakeSSOName = "CAuthCookie";
15     public string $cookieFakePicassoName = "SSOSESSIONID";
16     public array $headers;
17     public VolaFakeHTTPResponder $VolaFakeSSO;
18
19     function __construct()
20     {
21         $this->VolaFakeSSO = new VolaFakeHTTPResponder();
22         $this->headers = [
23             "Content-Type" => 'text/xml',
24         ];
cc9b73 25         if (config('custom.compressed_responses',false) === TRUE) {
D 26             $this->headers['content-encoding'] = 'gzip';
27         }
9f6455 28     }
DC 29
59b068 30     public function modelBasedRequest(Request $request)
91fb11 31     {
59b068 32         $this->logReceivedRequest($request);
91fb11 33
68b84d 34         $picassoRequest = (str_starts_with($request->getRequestUri(), '/picasso/',));
D 35         $profile = Utils::getRequestedUser($request);
91fb11 36
59b068 37         if (isset($profile)) {
D 38             $responseContent = $this->VolaFakeSSO->getModelBasedResponses($request, $profile, $picassoRequest);
68b84d 39             $this->logProcessedRequest($request, $responseContent,  (($picassoRequest) ? "SSO v2 Legacy" : "SSO v2 Picasso"));
59b068 40             $responseContent = $this->compressIfRequested($request, $responseContent);
D 41             return response($responseContent, 200, $this->headers);
42         } else {
43             $this->logRejectedRequest($request);
44             return response('No cookie, no logged', 400, $this->headers);
45         }
91fb11 46     }
D 47
9f6455 48     public function manageLegacyRequest(Request $request)
DC 49     {
398fc7 50         $this->logReceivedRequest($request);
cc9b73 51
68b84d 52         $picassoRequest = (str_starts_with($request->getRequestUri(), '/picasso/',));
D 53         $profile = Utils::getRequestedUser($request);
54
55         if (isset($profile)) {
56             $responseContent = $this->VolaFakeSSO->getResponses($request, $profile, $picassoRequest);
57             $this->logProcessedRequest($request, $responseContent, (($picassoRequest) ? "SSO Legacy" : "SSO Picasso"));
398fc7 58             $responseContent = $this->compressIfRequested($request, $responseContent);
9f6455 59             return response($responseContent, 200, $this->headers);
DC 60         } else {
7c54fa 61             $this->logRejectedRequest($request);
D 62             return response('No cookie, no logged', 400, $this->headers);
63         }
64     }
65
9f6455 66 }