Commit c49b75ce authored by Jacob Priddy's avatar Jacob Priddy 👌

readd simple saml php

parent c5cce3cb
......@@ -28,11 +28,11 @@ services:
- ./src/web:/var/www
- ./nginx/conf.d/:/etc/nginx/conf.d/
# Saml config
- ./simplesamlphp-1.18.3:/var/simplesamlphp
- ./simplesamlphp-1.18.5:/var/simplesamlphp
- ./simple-saml/cert:/var/simplesamlphp/cert
- ./simple-saml/config:/var/simplesamlphp/config
- ./simple-saml/metadata:/var/simplesamlphp/metadata
- ./simplesamlphp-1.18.3:/var/simplesamlphp-idp
- ./simplesamlphp-1.18.5:/var/simplesamlphp-idp
- ./simple-saml-idp/cert:/var/simplesamlphp-idp/cert
- ./simple-saml-idp/config:/var/simplesamlphp-idp/config
- ./simple-saml-idp/metadata:/var/simplesamlphp-idp/metadata
......@@ -77,11 +77,11 @@ services:
- ./src/web:/var/www
- ./php/dev.ini:/usr/local/etc/php/conf.d/local.ini
# Map saml files to the php-fpm server so it has access to them as well
- ./simplesamlphp-1.18.3:/var/simplesamlphp
- ./simplesamlphp-1.18.5:/var/simplesamlphp
- ./simple-saml/cert:/var/simplesamlphp/cert
- ./simple-saml/config:/var/simplesamlphp/config
- ./simple-saml/metadata:/var/simplesamlphp/metadata
- ./simplesamlphp-1.18.3:/var/simplesamlphp-idp
- ./simplesamlphp-1.18.5:/var/simplesamlphp-idp
- ./simple-saml-idp/cert:/var/simplesamlphp-idp/cert
- ./simple-saml-idp/config:/var/simplesamlphp-idp/config
- ./simple-saml-idp/metadata:/var/simplesamlphp-idp/metadata
......
......@@ -3,6 +3,7 @@
/public/storage
/storage/*.key
/vendor
/vendor-bin
.env
.env.backup
.phpunit.result.cache
......
......@@ -10,18 +10,19 @@
"require": {
"php": "^7.4",
"fideloper/proxy": "^4.0",
"friendsofphp/php-cs-fixer": "^2.16",
"fruitcake/laravel-cors": "^1.0",
"laravel/framework": "^7.0",
"laravel/tinker": "^2.0"
},
"require-dev": {
"roave/security-advisories": "dev-master",
"bamarni/composer-bin-plugin": "^1.3",
"friendsofphp/php-cs-fixer": "^2.16",
"facade/ignition": "^2.0",
"fzaninotto/faker": "^1.4",
"mockery/mockery": "^1.0",
"nunomaduro/collision": "^4.1",
"phpunit/phpunit": "^8.5"
"phpunit/phpunit": "^8.5",
"roave/security-advisories": "dev-master"
},
"config": {
"optimize-autoloader": true,
......
......@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "724d38cdc18fab793fe808f568c1cdde",
"content-hash": "cd2f50b50bd735add91a87d4abd9d3d7",
"packages": [
{
"name": "asm89/stack-cors",
......@@ -756,6 +756,7 @@
"email": "jakub.onderka@gmail.com"
}
],
"abandoned": "php-parallel-lint/php-console-color",
"time": "2018-09-29T17:23:10+00:00"
},
{
......@@ -802,6 +803,7 @@
}
],
"description": "Highlight PHP code in terminal",
"abandoned": "php-parallel-lint/php-console-highlighter",
"time": "2018-09-29T18:48:56+00:00"
},
{
......@@ -3697,6 +3699,45 @@
}
],
"packages-dev": [
{
"name": "bamarni/composer-bin-plugin",
"version": "v1.3.0",
"source": {
"type": "git",
"url": "https://github.com/bamarni/composer-bin-plugin.git",
"reference": "67f9d314dc7ecf7245b8637906e151ccc62b8d24"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/bamarni/composer-bin-plugin/zipball/67f9d314dc7ecf7245b8637906e151ccc62b8d24",
"reference": "67f9d314dc7ecf7245b8637906e151ccc62b8d24",
"shasum": ""
},
"require": {
"composer-plugin-api": "^1.0"
},
"require-dev": {
"composer/composer": "dev-master",
"symfony/console": "^2.5 || ^3.0 || ^4.0"
},
"type": "composer-plugin",
"extra": {
"class": "Bamarni\\Composer\\Bin\\Plugin",
"branch-alias": {
"dev-master": "1.1-dev"
}
},
"autoload": {
"psr-4": {
"Bamarni\\Composer\\Bin\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"time": "2019-03-17T12:38:04+00:00"
},
{
"name": "doctrine/instantiator",
"version": "1.3.0",
......
......@@ -3,7 +3,7 @@
namespace Source\Gateways\Saml;
use Exception;
use SimpleSAML_Auth_Simple;
use SimpleSamlPHP\SimpleSAML_Auth_Simple;
use Source\Entities\SamlUser;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Validator;
......@@ -17,11 +17,11 @@ class SimpleSamlPhpSamlRepository implements SamlRepository
protected string $logoutUrl;
/**
* Found in simplesamlphp-1.18.3/lib/SimpleSAML/Auth/Simple.php
* Found in simplesamlphp-1.18.5/lib/SimpleSAML/Auth/Simple.php
*
* See https://simplesamlphp.org/docs/stable/simplesamlphp-sp-api for information on these methods
*
* @var SimpleSAML_Auth_Simple
* @var SimpleSamlPHP\SimpleSAML_Auth_Simple
* @method bool isAuthenticated()
* @method void requireAuth(array $params = [])
* @method void login(array $params = [])
......@@ -50,7 +50,7 @@ class SimpleSamlPhpSamlRepository implements SamlRepository
require_once base_path($samlAutoloadPath);
$this->saml = new SimpleSAML_Auth_Simple($authSource);
$this->saml = new SimpleSamlPHP\SimpleSAML_Auth_Simple($authSource);
}
/**
......
......@@ -24,17 +24,19 @@ 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\Tokens\TokensRepository $tokens
* @param \Source\Gateways\Saml\SamlRepository $saml
*/
public function __construct(UsersRepository $users, TokensRepository $tokens)
public function __construct(UsersRepository $users, TokensRepository $tokens, SamlRepository $saml)
{
$this->saml = $saml;
$this->users = $users;
$this->tokens = $tokens;
}
......@@ -80,8 +82,8 @@ class Authenticate implements AuthenticateUseCase
*/
public function handToSaml(array $options = []): string
{
throw new NotImplementedException();
// return $this->saml->login($options);
// throw new NotImplementedException();
return $this->saml->login($options);
}
/**
......@@ -90,49 +92,49 @@ class Authenticate implements AuthenticateUseCase
*/
public function handleSamlLogin(Presenter $presenter): void
{
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);
// 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);
}
/**
......@@ -141,11 +143,11 @@ class Authenticate implements AuthenticateUseCase
*/
public function samlLogout(?string $token): string
{
throw new NotImplementedException();
// 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,8 @@ class AuthenticateUseCaseServiceProvider extends ServiceProvider implements Defe
$this->app->bind(AuthenticateUseCase::class, static function (Application $app) {
return new Authenticate(
$app->make(UsersRepository::class),
$app->make(TokensRepository::class)
$app->make(TokensRepository::class),
$app->make(SamlRepository::class)
);
});
}
......
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