Commit 223fbb56 authored by Jacob Priddy's avatar Jacob Priddy 👌

fix namespace conflict bug and disable saml for the time being

parent 846a741d
Pipeline #3651 failed with stages
in 2 minutes and 2 seconds
<?php
namespace Source\Exceptions;
use Exception;
use Throwable;
class NotImplementedException extends Exception
{
public function __construct($message = 'Not Implemented', $code = 500, Throwable $previous = null)
{
parent::__construct($message, $code, $previous);
}
}
......@@ -10,6 +10,7 @@ use Source\Gateways\Saml\SamlRepository;
use Source\Gateways\Users\UsersRepository;
use Source\Gateways\Tokens\TokensRepository;
use Source\Exceptions\AuthenticationException;
use Source\Exceptions\NotImplementedException;
class Authenticate implements AuthenticateUseCase
{
......@@ -23,19 +24,17 @@ class Authenticate implements AuthenticateUseCase
*/
protected TokensRepository $tokens;
/**
* @var \Source\Gateways\Saml\SamlRepository
*/
protected SamlRepository $saml;
// /**
// * @var \Source\Gateways\Saml\SamlRepository
// */
// protected SamlRepository $saml;
/**
* @param \Source\Gateways\Users\UsersRepository $users
* @param \Source\Gateways\Saml\SamlRepository $saml
* @param \Source\Gateways\Tokens\TokensRepository $tokens
*/
public function __construct(UsersRepository $users, SamlRepository $saml, TokensRepository $tokens)
public function __construct(UsersRepository $users, TokensRepository $tokens)
{
$this->saml = $saml;
$this->users = $users;
$this->tokens = $tokens;
}
......@@ -77,70 +76,76 @@ class Authenticate implements AuthenticateUseCase
/**
* @inheritDoc
* @throws \Source\Exceptions\NotImplementedException
*/
public function handToSaml(array $options = []): string
{
return $this->saml->login($options);
throw new NotImplementedException();
// return $this->saml->login($options);
}
/**
* @inheritDoc
* @throws \Source\Exceptions\NotImplementedException
*/
public function handleSamlLogin(Presenter $presenter): void
{
$samlUser = $this->saml->handleLogin();
if (!$samlUser) {
throw new UserCreationException();
}
// First check to see if the user exists in the database.
$user = $this->users->findByEmail($samlUser->getEmail());
// If the user does not exist, create them.
if (!$user) {
$user = $this->users->create(
new User(
0,
$samlUser->getFirstName(),
$samlUser->getLastName(),
$samlUser->getDisplayName(),
$samlUser->getEmail(),
$samlUser->getEmplid(),
null,
null
)
);
}
if (!$user) {
throw new UserCreationException();
}
$token = $this->tokens->create(
new Token(
0,
$user->getId(),
Str::random(60),
null,
Carbon::now()->addDays(2)
)
);
$response = new ResponseModel($user, $token);
$presenter->present($response);
throw new NotImplementedException();
// $samlUser = $this->saml->handleLogin();
//
// if (!$samlUser) {
// throw new UserCreationException();
// }
//
// // First check to see if the user exists in the database.
// $user = $this->users->findByEmail($samlUser->getEmail());
//
// // If the user does not exist, create them.
// if (!$user) {
// $user = $this->users->create(
// new User(
// 0,
// $samlUser->getFirstName(),
// $samlUser->getLastName(),
// $samlUser->getDisplayName(),
// $samlUser->getEmail(),
// $samlUser->getEmplid(),
// null,
// null
// )
// );
// }
//
// if (!$user) {
// throw new UserCreationException();
// }
//
// $token = $this->tokens->create(
// new Token(
// 0,
// $user->getId(),
// Str::random(60),
// null,
// Carbon::now()->addDays(2)
// )
// );
//
// $response = new ResponseModel($user, $token);
//
// $presenter->present($response);
}
/**
* @inheritDoc
* @throws \Source\Exceptions\NotImplementedException
*/
public function samlLogout(?string $token): string
{
if ($token) {
$this->tokens->invalidateToken($token);
}
return $this->saml->logout();
throw new NotImplementedException();
// if ($token) {
// $this->tokens->invalidateToken($token);
// }
//
// return $this->saml->logout();
}
}
......@@ -25,7 +25,6 @@ class AuthenticateUseCaseServiceProvider extends ServiceProvider implements Defe
$this->app->bind(AuthenticateUseCase::class, static function (Application $app) {
return new Authenticate(
$app->make(UsersRepository::class),
$app->make(SamlRepository::class),
$app->make(TokensRepository::class)
);
});
......
......@@ -11,7 +11,7 @@ use Tests\Doubles\InMemoryUsersRepositoryStub;
use Source\UseCases\Users\Authenticate\Authenticate;
use Source\UseCases\Users\Authenticate\UserCreationException;
class SamlUseCaseTest extends UseCaseBaseTest
class SamlUseCaseTestNotUsed extends UseCaseBaseTest
{
protected const VALID_EMAIL = 'email';
......
......@@ -59,7 +59,7 @@ abstract class UseCaseBaseTest extends TestCase
$this->users = new InMemoryUsersRepository();
$this->tokens = new InMemoryTokensRepository();
$this->saml = new InMemorySamlRepository($this->loginUrl, $this->logoutUrl);
$this->useCase = new Authenticate($this->users, $this->saml, $this->tokens);
$this->useCase = new Authenticate($this->users, $this->tokens);
$this->presenter = new PresenterStub();
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment