Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
80.00% |
8 / 10 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| AuthenticateSenior | |
80.00% |
8 / 10 |
|
0.00% |
0 / 1 |
4.13 | |
0.00% |
0 / 1 |
| login | |
80.00% |
8 / 10 |
|
0.00% |
0 / 1 |
4.13 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Domain\Login\Integrations; |
| 4 | |
| 5 | |
| 6 | use Domain\Shared\Integrations\Senior\Exceptions\IntegrationSoapSeniorException; |
| 7 | use Domain\Shared\Integrations\Senior\SeniorSoapClient; |
| 8 | use Illuminate\Auth\AuthenticationException; |
| 9 | use SoapFault; |
| 10 | use function config; |
| 11 | use function is_soap_fault; |
| 12 | |
| 13 | readonly class AuthenticateSenior |
| 14 | { |
| 15 | |
| 16 | /** |
| 17 | * @param string $user |
| 18 | * @param string $password |
| 19 | * @throws AuthenticationException |
| 20 | * @throws IntegrationSoapSeniorException |
| 21 | * @throws SoapFault |
| 22 | */ |
| 23 | public static function login(string $user, string $password): void |
| 24 | { |
| 25 | $soap = new SeniorSoapClient(config('integration.url') . '/sapiens_SyncMCWFUsers?wsdl'); |
| 26 | |
| 27 | $response = $soap->authenticateJAAS(config('integration.user'), config('integration.user_password'), 0, [ |
| 28 | "pmUserName" => $user, |
| 29 | "pmUserPassword" => $password, |
| 30 | 'pmEncrypted' => 0 |
| 31 | ]); |
| 32 | if (is_soap_fault($response) || $response->erroExecucao) { |
| 33 | throw new IntegrationSoapSeniorException(__('Failed to consume webservice:'). $response->faultcode - $response->faultstring); |
| 34 | } |
| 35 | |
| 36 | if ($response->pmLogged == -1) { |
| 37 | throw new AuthenticationException(__('Unable to authenticate to ERP Senior. Invalid user or password')); |
| 38 | } |
| 39 | |
| 40 | } |
| 41 | |
| 42 | } |