forked from eellak/gredu_labs
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
authentication in progress; sso with cas and some views implemented
- Loading branch information
Showing
22 changed files
with
581 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
/** | ||
* gredu_labs | ||
* | ||
* @link https://github.com/eellak/gredu_labs for the canonical source repository | ||
* @copyright Copyright (c) 2008-2015 Greek Free/Open Source Software Society (https://gfoss.ellak.gr/) | ||
* @license GNU GPLv3 http://www.gnu.org/licenses/gpl-3.0-standalone.html | ||
*/ | ||
|
||
namespace GrEduLabs\Action\User; | ||
|
||
use Psr\Http\Message\ResponseInterface; | ||
use Psr\Http\Message\ServerRequestInterface; | ||
use Slim\Views\Twig; | ||
|
||
class Login | ||
{ | ||
/** | ||
* @var Twig | ||
*/ | ||
protected $view; | ||
|
||
/** | ||
* @var callable | ||
*/ | ||
protected $authenticate; | ||
|
||
/** | ||
* Constructor | ||
* @param Twig $view | ||
*/ | ||
public function __construct( | ||
Twig $view, | ||
callable $authenticate | ||
) { | ||
$this->view = $view; | ||
$this->authenticate = $authenticate; | ||
} | ||
|
||
public function __invoke(ServerRequestInterface $req, ResponseInterface $res, array $args = []) | ||
{ | ||
if ($req->isPost()) { | ||
$authenticate = $this->authenticate; | ||
$result = $authenticate( | ||
$req->getParam('email'), | ||
$req->getParam('password') | ||
); | ||
var_dump($result); | ||
} | ||
|
||
return $this->view->render($res, 'user/login.twig'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
/** | ||
* gredu_labs | ||
* | ||
* @link https://github.com/eellak/gredu_labs for the canonical source repository | ||
* @copyright Copyright (c) 2008-2015 Greek Free/Open Source Software Society (https://gfoss.ellak.gr/) | ||
* @license GNU GPLv3 http://www.gnu.org/licenses/gpl-3.0-standalone.html | ||
*/ | ||
|
||
namespace GrEduLabs\Action\User; | ||
|
||
use Psr\Http\Message\ResponseInterface; | ||
use Psr\Http\Message\ServerRequestInterface; | ||
use Slim\Views\Twig; | ||
|
||
class LoginSso | ||
{ | ||
|
||
/** | ||
* @var callable | ||
*/ | ||
protected $authenticate; | ||
|
||
/** | ||
* Constructor | ||
* @param Twig $view | ||
*/ | ||
public function __construct(callable $authenticate) | ||
{ | ||
$this->authenticate = $authenticate; | ||
} | ||
|
||
public function __invoke(ServerRequestInterface $req, ResponseInterface $res, array $args = []) | ||
{ | ||
$authenticate = $this->authenticate; | ||
$result = $authenticate(); | ||
|
||
var_dump($result); | ||
|
||
return $res; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
/** | ||
* gredu_labs | ||
* | ||
* @link https://github.com/eellak/gredu_labs for the canonical source repository | ||
* @copyright Copyright (c) 2008-2015 Greek Free/Open Source Software Society (https://gfoss.ellak.gr/) | ||
* @license GNU GPLv3 http://www.gnu.org/licenses/gpl-3.0-standalone.html | ||
*/ | ||
|
||
namespace GrEduLabs\Action\User; | ||
|
||
use Psr\Http\Message\ResponseInterface; | ||
use Psr\Http\Message\ServerRequestInterface; | ||
use Zend\Authentication\AuthenticationServiceInterface; | ||
|
||
class Logout | ||
{ | ||
/** | ||
* @var AuthenticationServiceInterface | ||
*/ | ||
protected $authService; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $redirectUrl; | ||
|
||
public function __construct( | ||
AuthenticationServiceInterface $authService, | ||
$redirectUrl | ||
) { | ||
$this->authService = $authService; | ||
$this->router = $router; | ||
$this->redirectUrl = $redirectUrl; | ||
} | ||
|
||
public function __invoke(ServerRequestInterface $req, ResponseInterface $res, array $args = []) | ||
{ | ||
if ($this->authService->hasIdentity()) { | ||
$this->authService->clearIdentity(); | ||
} | ||
|
||
return $res->withRedirect($this->redirectUrl); | ||
} | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<?php | ||
/** | ||
* gredu_labs | ||
* | ||
* @link https://github.com/eellak/gredu_labs for the canonical source repository | ||
* @copyright Copyright (c) 2008-2015 Greek Free/Open Source Software Society (https://gfoss.ellak.gr/) | ||
* @license GNU GPLv3 http://www.gnu.org/licenses/gpl-3.0-standalone.html | ||
*/ | ||
|
||
namespace GrEduLabs\Authentication\Adapter; | ||
|
||
use Exception; | ||
use GrEduLabs\Authentication\Identity; | ||
use phpCAS; | ||
use Zend\Authentication\Adapter\AdapterInterface; | ||
use Zend\Authentication\Result; | ||
|
||
class Cas implements AdapterInterface | ||
{ | ||
public function __construct(array $settings = []) | ||
{ | ||
phpCAS::client( | ||
$settings['serverVersion'], | ||
$settings['serverHostname'], | ||
$settings['serverPort'], | ||
$settings['serverUri'], | ||
$settings['changeSessionId'] | ||
); | ||
|
||
if (($casServerCaCert = $settings['casServerCaCert'])) { | ||
if ($settings['casServerCnValidate']) { | ||
phpCAS::setCasServerCACert($casServerCaCert, true); | ||
} else { | ||
phpCAS::setCasServerCACert($casServerCaCert, false); | ||
} | ||
} | ||
|
||
if ($settings['noCasServerValidation']) { | ||
phpCAS::setNoCasServerValidation(); | ||
} | ||
} | ||
|
||
public function authenticate() | ||
{ | ||
try { | ||
phpCAS::handleLogoutRequests(); | ||
phpCAS::forceAuthentication(); | ||
if (!phpCAS::isAuthenticated()) { | ||
return new Result(Result::FAILURE, null, ['Authentication failure']); | ||
} | ||
|
||
return new Result( | ||
Result::SUCCESS, | ||
self::identityFormCasAttributes(), | ||
['Authentication success'] | ||
); | ||
} catch (Exception $e) { | ||
return new Result(Result::FAILURE_UNCATEGORIZED, null, [$e->getMessage()]); | ||
} | ||
} | ||
|
||
private static function identityFormCasAttributes() | ||
{ | ||
$attributes = phpCAS::getAttributes(); | ||
$identity = phpCAS::getUser(); | ||
|
||
$filterAttribute = function ($attribute) use ($attributes) { | ||
if (!isset($attributes[$attribute])) { | ||
return; | ||
} | ||
|
||
if (is_array($attributes[$attribute])) { | ||
return $attributes[$attribute]; | ||
} | ||
|
||
return $attributes[$attribute]; | ||
}; | ||
|
||
return new Identity( | ||
$identity, | ||
$filterAttribute('mail'), | ||
$filterAttribute('cn'), | ||
$filterAttribute('ou') | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
/** | ||
* gredu_labs | ||
* | ||
* @link https://github.com/eellak/gredu_labs for the canonical source repository | ||
* @copyright Copyright (c) 2008-2015 Greek Free/Open Source Software Society (https://gfoss.ellak.gr/) | ||
* @license GNU GPLv3 http://www.gnu.org/licenses/gpl-3.0-standalone.html | ||
*/ | ||
|
||
namespace GrEduLabs\Authentication\Adapter; | ||
|
||
use PDO as PDOConnection; | ||
use Zend\Authentication\Adapter\AbstractAdapter; | ||
use Zend\Authentication\Result; | ||
|
||
class Pdo extends AbstractAdapter | ||
{ | ||
|
||
/** | ||
* @var EventManagerInterface | ||
*/ | ||
protected $events; | ||
|
||
/** | ||
* Construct adapter | ||
* | ||
* @param PDOConnection $db | ||
*/ | ||
public function __construct(PDOConnection $db) | ||
{ | ||
$this->db = $db; | ||
} | ||
|
||
|
||
public function authenticate() | ||
{ | ||
return new Result(Result::FAILURE, null, ['Authentication failure']); | ||
} | ||
} |
Oops, something went wrong.