Compare commits

...

11 Commits

Author SHA1 Message Date
a-sansara
a9bb3e3be5 composer dev 2017-03-30 01:54:11 +02:00
a-sansara
260ffeeb74 add missing routing definition in ctrl/base + php version 7 require 2017-03-30 01:51:26 +02:00
a-sansara
071aa12e13 composer.json dev 2017-03-21 03:47:43 +01:00
a-sansara
bf0c42f474 version 1.0.3 - manage responseHeader 2017-03-21 03:46:27 +01:00
a-sansara
a90df3ca74 amend responseHeader 2017-03-21 02:55:50 +01:00
a-sansara
2debb3dc02 amend 2017-03-21 01:59:40 +01:00
a-sansara
e20bef3b9a manage responseHeader 2017-03-21 01:35:31 +01:00
a-sansara
3f484c6481 update composer.json - require yaml due to prod dependecies on gecko-silex-config 2017-03-18 00:11:58 +01:00
a-sansara
6c3bb16937 add missing source code header 2017-03-16 02:03:04 +01:00
a-sansara
ffd0addcec amend 2017-03-16 01:59:04 +01:00
a-sansara
de9c242c2f update composer.json 2017-03-15 23:46:50 +01:00
10 changed files with 96 additions and 38 deletions

View File

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

View File

@ -17,10 +17,12 @@
}
},
"require": {
"meta-tech/pws-auth" : "~2.1",
"meta-tech/silex-controller-service" : "~1.0",
"silex/silex": "~2.0",
"php" : "^7.0",
"meta-tech/pws-auth" : "@dev",
"meta-tech/silex-controller-service" : "^1.0",
"silex/silex": "^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,4 +1,12 @@
<?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;
/*!

View File

@ -1,4 +1,12 @@
<?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;
use PDO;

View File

@ -1,4 +1,12 @@
<?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;
use MetaTech\Db\PdoConnector;

View File

@ -1,4 +1,12 @@
<?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;
/*!

View File

@ -51,6 +51,17 @@ 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
* @public

View File

@ -1,4 +1,12 @@
<?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;
use Symfony\Component\Security\Core\User\UserProviderInterface;
@ -67,7 +75,7 @@ class UserProvider implements UserProviderInterface
}
/*!
* @method loadUserPrograms
* @method loadUserByRole
* @public
* @return Symfony\Component\Security\Core\User\User
*/
@ -76,24 +84,6 @@ class UserProvider implements UserProviderInterface
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
* @public

View File

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

View File

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