Compare commits

..

No commits in common. "master" and "1.0.1" have entirely different histories.

10 changed files with 38 additions and 96 deletions

View File

@ -23,7 +23,7 @@ Or add the package to your `composer.json`.
``` ```
"require": { "require": {
"meta-tech/silex-core" : "^1.0" "meta-tech/silex-core" : "~1.0"
} }
``` ```

View File

@ -17,12 +17,10 @@
} }
}, },
"require": { "require": {
"php" : "^7.0", "meta-tech/pws-auth" : "~2.1",
"meta-tech/pws-auth" : "@dev", "meta-tech/silex-controller-service" : "~1.0",
"meta-tech/silex-controller-service" : "^1.0", "silex/silex": "~2.0",
"silex/silex": "^2.0",
"gecko-packages/gecko-silex-config-service": "^2.0", "gecko-packages/gecko-silex-config-service": "^2.0",
"symfony/security": "^3.2", "symfony/security": "~3.2"
"symfony/yaml": "^3.2"
} }
} }

View File

@ -1,12 +1,4 @@
<?php <?php
/*
* This file is part of the silex-core package.
*
* (c) meta-tech.academy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace MetaTech\Core; namespace MetaTech\Core;
/*! /*!

View File

@ -1,12 +1,4 @@
<?php <?php
/*
* This file is part of the silex-core package.
*
* (c) meta-tech.academy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace MetaTech\Db; namespace MetaTech\Db;
use PDO; use PDO;

View File

@ -1,12 +1,4 @@
<?php <?php
/*
* This file is part of the silex-core package.
*
* (c) meta-tech.academy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace MetaTech\Db; namespace MetaTech\Db;
use MetaTech\Db\PdoConnector; use MetaTech\Db\PdoConnector;

View File

@ -1,12 +1,4 @@
<?php <?php
/*
* This file is part of the silex-core package.
*
* (c) meta-tech.academy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace MetaTech\Db; namespace MetaTech\Db;
/*! /*!

View File

@ -51,17 +51,6 @@ abstract class Base implements ControllerProviderInterface
} }
/*!
* @method routing
* @public
* @param Silex\ControllerCollection $collection
* @return Silex\ControllerCollection
*/
public function routing(ControllerCollection $collection) : ControllerCollection
{
return $collection;
}
/*! /*!
* @method connect * @method connect
* @public * @public

View File

@ -1,12 +1,4 @@
<?php <?php
/*
* This file is part of the silex-core package.
*
* (c) meta-tech.academy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace MetaTech\Silex\Provider; namespace MetaTech\Silex\Provider;
use Symfony\Component\Security\Core\User\UserProviderInterface; use Symfony\Component\Security\Core\User\UserProviderInterface;
@ -75,7 +67,7 @@ class UserProvider implements UserProviderInterface
} }
/*! /*!
* @method loadUserByRole * @method loadUserPrograms
* @public * @public
* @return Symfony\Component\Security\Core\User\User * @return Symfony\Component\Security\Core\User\User
*/ */
@ -84,6 +76,24 @@ class UserProvider implements UserProviderInterface
return $this->pdo->exec('SELECT * FROM ' . $this->table . ' WHERE roles LIKE :role', compact('role'))->fetchAll(); return $this->pdo->exec('SELECT * FROM ' . $this->table . ' WHERE roles LIKE :role', compact('role'))->fetchAll();
} }
/*!
* @method loadProgramKeys
* @public
* @return Symfony\Component\Security\Core\User\User
*/
public function loadProgramKeys()
{
$keys = [];
$rows = $this->loadUserPrograms();
$rows = array_merge($rows, $this->loadUserPrograms('INSURER'));
if (!empty($rows)) {
foreach ($rows as $row) {
$keys[] = $row->key;
}
}
return $keys;
}
/*! /*!
* @method loadUserByUsername * @method loadUserByUsername
* @public * @public

View File

@ -95,13 +95,11 @@ class Authentication
public function auth(Request $request) public function auth(Request $request)
{ {
$this->sessionInvalidate(); $this->sessionInvalidate();
$done = false; $done = false;
$msg = 'authentication require'; $msg = 'authentication require';
$token = $this->authenticator->getToken(); $token = $this->authenticator->getToken();
$login = $request->get('login');
$responseToken = $this->authenticator->generateResponseHeader($token);
$headers = $this->getResponseHeaders([], $responseToken);
if ($this->authenticator->isValid($token)) { if ($this->authenticator->isValid($token)) {
$login = $request->get('login');
$password = $request->get('password'); $password = $request->get('password');
if ($this->authenticator->check($token, $login)) { if ($this->authenticator->check($token, $login)) {
try { try {
@ -119,21 +117,7 @@ class Authentication
if (!$done) { if (!$done) {
sleep(3); sleep(3);
} }
return new JsonResponse(compact('done', 'msg', 'data'), $done ? 200 : 401, $headers); return new JsonResponse(compact('done', 'msg', 'data'), $done ? 200 : 401);
}
/*!
* @method getResponseHeaders
* @private
* @param [assoc] $headers
* @return [assoc]
*/
private function getResponseHeaders($headers=[], $tokenResponse=null)
{
if (!empty($tokenResponse) || !empty($tokenResponse = $this->session->get('pwsauth.response'))) {
$headers['Pws-Response'] = $tokenResponse;
}
return $headers;
} }
/*! /*!
@ -163,22 +147,20 @@ class Authentication
public function check(Request $request) public function check(Request $request)
{ {
if (!$this->isAllowedRoute($request->getPathInfo())) { if (!$this->isAllowedRoute($request->getPathInfo())) {
$done = false; $done = false;
$msg = "authentication require"; $msg = "authentication require";
$headers = [];
try { try {
$token = $this->authenticator->getToken(); $token = $this->authenticator->getToken();
$tokenResponse = $this->authenticator->generateResponseHeader($token);
$headers = $this->getResponseHeaders($headers, $tokenResponse);
if ($this->authenticator->isValid($token)) { if ($this->authenticator->isValid($token)) {
if (!empty($sid = $this->authenticator->getSessionId($token))) { if (!empty($sid = $this->authenticator->getSessionId($token))) {
$this->sessionInvalidate(); $this->sessionInvalidate();
$this->session->setId($sid); $this->session->setId($sid);
$this->session->start(); $this->session->start();
$user = $this->session->get('user'); $user = $this->session->get('user');
$data = compact('user');
// done : lets controller takes hand // done : lets controller takes hand
if (!is_null($user) && $user->key == $token->getIdent()) { if (!is_null($user) && $user->key == $token->getIdent()) {
$this->session->set('pwsauth.response', $tokenResponse);
return; return;
} }
else { else {
@ -191,7 +173,7 @@ class Authentication
$done = false; $done = false;
$msg = $e->getMessage(); $msg = $e->getMessage();
} }
return new JsonResponse(compact('done', 'msg', 'data'), 401, $headers); return new JsonResponse(compact('done', 'msg', 'data'), 401);
} }
} }
} }

View File

@ -49,16 +49,12 @@ class Controller extends Base
* @param [] $data * @param [] $data
* @return Symfony\Component\HttpFoundation\JsonResponse * @return Symfony\Component\HttpFoundation\JsonResponse
*/ */
public function response($done = false, $msg = "fail", $data = null, $tokenResponse = null) public function response($done = false, $msg = "fail", $data = null)
{ {
if (is_null($data)) { if (is_null($data)) {
unset($data); unset($data);
} }
$headers = []; $response = new JsonResponse(compact('done', 'msg', 'data'), 200);
if (!empty($tokenResponse) || !empty($tokenResponse = $this->session->get('pwsauth.response'))) {
$headers['Pws-Response'] = $tokenResponse;
}
$response = new JsonResponse(compact('done', 'msg', 'data'), 200, $headers);
return $response; return $response;
} }
@ -107,12 +103,11 @@ class Controller extends Base
*/ */
public function logout() public function logout()
{ {
$tokenResponse = $this->session->isStarted() ? $this->session->get('pwsauth.response') : null;
$this->handler->sessionInvalidate(); $this->handler->sessionInvalidate();
$sessid = $this->session->getId(); $sessid = $this->session->getId();
$done = true; $done = true;
$msg = 'session logout'; $msg = 'session logout';
return $this->response($done, $msg, null, $tokenResponse); return $this->response($done, $msg);
} }
/*! /*!