Commit 82442ade authored by Jacob Priddy's avatar Jacob Priddy 👌

get authorization all working :D

parent b022b93c
Pipeline #2218 failed with stages
in 1 minute and 54 seconds
......@@ -20,18 +20,15 @@ Route::post('login', [AuthController::class, 'login']);
Route::post('logout', [AuthController::class, 'logout']);
Route::group(['middleware' => 'auth:api'], static function () {
Route::group(
[
'prefix' => 'users',
],
static function () {
Route::get('/', [UsersController::class, 'index']);
Route::post('/', [UsersController::class, 'store']);
Route::get('{userId}', [UsersController::class, 'get']);
Route::put('{userId}', [UsersController::class, 'update']);
Route::delete('{userId}', [UsersController::class, 'delete']);
}
);
Route::group([
'prefix' => 'users',
], static function () {
Route::get('/', [UsersController::class, 'index']);
Route::post('/', [UsersController::class, 'store']);
Route::get('{userId}', [UsersController::class, 'get']);
Route::put('{userId}', [UsersController::class, 'update']);
Route::delete('{userId}', [UsersController::class, 'delete']);
});
Route::get('/user', static function (Request $request) {
return $request->user();
......
......@@ -3,6 +3,7 @@
namespace Source\Authorization;
use App\Guards\ApiGuard;
use Illuminate\Contracts\Auth\Guard;
use Source\Exceptions\AuthorizationException;
use Source\Gateways\GroupUser\GroupUserRepository;
......@@ -19,7 +20,7 @@ class ApiAuthorizer implements Authorizer
*/
protected GroupUserRepository $groupUserRepository;
public function __construct(Guard $guard, GroupUserRepository $groupUserRepository)
public function __construct(ApiGuard $guard, GroupUserRepository $groupUserRepository)
{
$this->guard = $guard;
$this->groupUserRepository = $groupUserRepository;
......
......@@ -3,8 +3,8 @@
namespace Source\Authorization;
use App\Guards\ApiGuard;
use Carbon\Laravel\ServiceProvider;
use Illuminate\Contracts\Auth\Guard;
use Illuminate\Foundation\Application;
use Source\Gateways\GroupUser\GroupUserRepository;
use Illuminate\Contracts\Support\DeferrableProvider;
......@@ -22,7 +22,7 @@ class AuthorizerServiceProvider extends ServiceProvider implements DeferrablePro
public function register()
{
$this->app->bind(Authorizer::class, static function (Application $app) {
return new ApiAuthorizer($app->make(Guard::class), $app->make(GroupUserRepository::class));
return new ApiAuthorizer($app->make(ApiGuard::class), $app->make(GroupUserRepository::class));
});
}
......
......@@ -17,21 +17,21 @@ class LocalGroupUserRepository extends InMemoryGroupUserRepository
{
parent::__construct($users, $groups);
$this->addUserToGroup($users->getAdminUser()->getId(), $groups->getAdminGroup()->getId());
$this->addUserToGroup(LocalUsersRepository::getAdminUser()->getId(), LocalGroupsRepository::getAdminGroup()->getId());
$this->addUserToGroup($users->getSemiPrivilegedUser()->getId(), $groups->getManageUsersGroup()->getId());
$this->addUserToGroup($users->getSemiPrivilegedUser()->getId(), $groups->getManageDoorsGroup()->getId());
$this->addUserToGroup($users->getSemiPrivilegedUser()->getId(), $groups->getManageTokenGroup()->getId());
$this->addUserToGroup($users->getSemiPrivilegedUser()->getId(), $groups->getTokenCreateGroup()->getId());
$this->addUserToGroup($users->getSemiPrivilegedUser()->getId(), $groups->getCodeQueryGroup()->getId());
$this->addUserToGroup(LocalUsersRepository::getSemiPrivilegedUser()->getId(), LocalGroupsRepository::getManageUsersGroup()->getId());
$this->addUserToGroup(LocalUsersRepository::getSemiPrivilegedUser()->getId(), LocalGroupsRepository::getManageDoorsGroup()->getId());
$this->addUserToGroup(LocalUsersRepository::getSemiPrivilegedUser()->getId(), LocalGroupsRepository::getManageTokenGroup()->getId());
$this->addUserToGroup(LocalUsersRepository::getSemiPrivilegedUser()->getId(), LocalGroupsRepository::getTokenCreateGroup()->getId());
$this->addUserToGroup(LocalUsersRepository::getSemiPrivilegedUser()->getId(), LocalGroupsRepository::getCodeQueryGroup()->getId());
$this->addUserToGroup(
$users->getComputerScienceStudent()->getId(),
$groups->getComputerScienceMajorGroup()->getId()
LocalUsersRepository::getComputerScienceStudent()->getId(),
LocalGroupsRepository::getComputerScienceMajorGroup()->getId()
);
$this->addUserToGroup(
$users->getEngineeringLabAccessStudent()->getId(),
$groups->getEngineeringLabAccessGroup()->getId()
LocalUsersRepository::getEngineeringLabAccessStudent()->getId(),
LocalGroupsRepository::getEngineeringLabAccessGroup()->getId()
);
}
}
......@@ -10,27 +10,27 @@ class LocalGroupsRepository extends InMemoryGroupsRepository
{
public function __construct()
{
$this->create($this->getAdminGroup());
$this->create(static::getAdminGroup());
$this->create($this->getManageUsersGroup());
$this->create(static::getManageUsersGroup());
$this->create($this->getManageDoorsGroup());
$this->create(static::getManageDoorsGroup());
$this->create($this->getManageTokenGroup());
$this->create(static::getManageTokenGroup());
$this->create($this->getTokenCreateGroup());
$this->create(static::getTokenCreateGroup());
$this->create($this->getCodeQueryGroup());
$this->create(static::getCodeQueryGroup());
$this->create($this->getComputerScienceMajorGroup());
$this->create(static::getComputerScienceMajorGroup());
$this->create($this->getEngineeringLabAccessGroup());
$this->create(static::getEngineeringLabAccessGroup());
}
/**
* @return \Source\Entities\Group
*/
public function getAdminGroup(): Group
public static function getAdminGroup(): Group
{
return new Group(
1,
......@@ -42,7 +42,7 @@ class LocalGroupsRepository extends InMemoryGroupsRepository
/**
* @return \Source\Entities\Group
*/
public function getManageUsersGroup(): Group
public static function getManageUsersGroup(): Group
{
return new Group(
2,
......@@ -54,7 +54,7 @@ class LocalGroupsRepository extends InMemoryGroupsRepository
/**
* @return \Source\Entities\Group
*/
public function getManageDoorsGroup(): Group
public static function getManageDoorsGroup(): Group
{
return new Group(
3,
......@@ -66,7 +66,7 @@ class LocalGroupsRepository extends InMemoryGroupsRepository
/**
* @return \Source\Entities\Group
*/
public function getManageTokenGroup(): Group
public static function getManageTokenGroup(): Group
{
return new Group(
6,
......@@ -78,7 +78,7 @@ class LocalGroupsRepository extends InMemoryGroupsRepository
/**
* @return \Source\Entities\Group
*/
public function getTokenCreateGroup(): Group
public static function getTokenCreateGroup(): Group
{
return new Group(
4,
......@@ -90,7 +90,7 @@ class LocalGroupsRepository extends InMemoryGroupsRepository
/**
* @return \Source\Entities\Group
*/
public function getCodeQueryGroup(): Group
public static function getCodeQueryGroup(): Group
{
return new Group(
5,
......@@ -102,7 +102,7 @@ class LocalGroupsRepository extends InMemoryGroupsRepository
/**
* @return \Source\Entities\Group
*/
public function getComputerScienceMajorGroup(): Group
public static function getComputerScienceMajorGroup(): Group
{
return new Group(
7,
......@@ -114,7 +114,7 @@ class LocalGroupsRepository extends InMemoryGroupsRepository
/**
* @return \Source\Entities\Group
*/
public function getEngineeringLabAccessGroup(): Group
public static function getEngineeringLabAccessGroup(): Group
{
return new Group(
8,
......
......@@ -5,12 +5,50 @@ namespace Source\Gateways\Tokens;
use Carbon\Carbon;
use Source\Entities\Token;
use Source\Gateways\Users\LocalUsersRepository;
class LocalTokensRepository extends InMemoryTokensRepository
{
/**
* @throws \Source\Exceptions\EntityNotFoundException
* @throws \Exception
*/
public function __construct()
{
$this->tokens[] = new Token(1, 1, 'token_string', 'basic token');
$this->tokens[] = new Token(2, 420, 'expired_token', '', Carbon::now()->subDays(3));
$this->create(new Token(
0,
LocalUsersRepository::getAdminUser()->getId(),
'token_string_admin',
'basic token'
));
$this->create(new Token(
0,
LocalUsersRepository::getSemiPrivilegedUser()->getId(),
'token_string_semi',
'basic token'
));
$this->create(new Token(
0,
LocalUsersRepository::getComputerScienceStudent()->getId(),
'token_string_cs',
'basic token'
));
$this->create(new Token(
0,
LocalUsersRepository::getEngineeringLabAccessStudent()->getId(),
'token_string_engr',
'basic token'
));
$this->create(new Token(
0,
LocalUsersRepository::getAdminUser()->getId(),
'token_string_expired',
'expired token',
Carbon::now()->subDays(3)
));
}
}
......@@ -13,19 +13,19 @@ class LocalUsersRepository extends InMemoryUsersRepository
*/
public function __construct()
{
$this->create($this->getAdminUser());
$this->create(static::getAdminUser());
$this->create($this->getSemiPrivilegedUser());
$this->create(static::getSemiPrivilegedUser());
$this->create($this->getEngineeringLabAccessStudent());
$this->create(static::getEngineeringLabAccessStudent());
$this->create($this->getComputerScienceStudent());
$this->create(static::getComputerScienceStudent());
}
/**
* @return \Source\Entities\User
*/
public function getAdminUser(): User
public static function getAdminUser(): User
{
return new User(
1,
......@@ -46,7 +46,7 @@ class LocalUsersRepository extends InMemoryUsersRepository
* @return \Source\Entities\User
* @throws \Exception
*/
public function getSemiPrivilegedUser(): User
public static function getSemiPrivilegedUser(): User
{
return new User(
2,
......@@ -67,7 +67,7 @@ class LocalUsersRepository extends InMemoryUsersRepository
* @return \Source\Entities\User
* @throws \Exception
*/
public function getEngineeringLabAccessStudent(): User
public static function getEngineeringLabAccessStudent(): User
{
return new User(
420,
......@@ -88,7 +88,7 @@ class LocalUsersRepository extends InMemoryUsersRepository
* @return \Source\Entities\User
* @throws \Exception
*/
public function getComputerScienceStudent(): User
public static function getComputerScienceStudent(): User
{
return new User(
69,
......
......@@ -118,7 +118,9 @@ class Authenticate implements AuthenticateUseCase
*/
public function samlLogout(?string $token): string
{
$this->tokens->invalidateToken($token);
if ($token) {
$this->tokens->invalidateToken($token);
}
return $this->saml->logout();
}
......
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