version 1.0.1 - manage ws Authentication via userProvider
This commit is contained in:
parent
dc0b7533b7
commit
e875e3c0d5
7
config/db.yml
Normal file
7
config/db.yml
Normal file
|
@ -0,0 +1,7 @@
|
|||
default :
|
||||
driver : pdo_mysql
|
||||
host : db
|
||||
dbname : pwsserver
|
||||
user : dev
|
||||
password : mysql
|
||||
charset : utf8
|
12
config/security.yml
Normal file
12
config/security.yml
Normal file
|
@ -0,0 +1,12 @@
|
|||
security.firewalls :
|
||||
dev:
|
||||
pattern: ^/(_(profiler|wdt)|css|images|js)/
|
||||
security: false
|
||||
|
||||
main:
|
||||
pattern: ^/ws
|
||||
anonymous: true
|
||||
|
||||
security.params :
|
||||
sleep : 3
|
||||
|
13
schema/170315-init-users.sql
Normal file
13
schema/170315-init-users.sql
Normal file
|
@ -0,0 +1,13 @@
|
|||
CREATE TABLE `users` (
|
||||
`id` smallint(4) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`name` varchar(30) NOT NULL,
|
||||
`username` varchar(32) NOT NULL,
|
||||
`password` varchar(255) NOT NULL,
|
||||
`key` varchar(255) DEFAULT NULL,
|
||||
`roles` varchar(255) NOT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `UNIQ_6E736E72F85E0677` (`username`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;
|
||||
|
||||
-- user dev : foo
|
||||
INSERT INTO `users` (`id`, `name`, `username`, `password`, `key`, `roles`) VALUES ('', 'Meta-Tech', 'dev', 'EZJ4em8bQ409UiPU+LpfJ5IWpiTkT2lSzMkVEl3IP5A0TDRV+RZS1Q==', 'ed830045da9861d29c46f36b4f4b1a4d4b223408667c52428370e51b615e8769', 'ROLE_ADMIN');
|
|
@ -11,6 +11,9 @@ namespace MetaTech\PwsServer;
|
|||
|
||||
use MetaTech\Silex\Application as App;
|
||||
use MetaTech\Silex\Provider\ControllerServiceProvider as CtrlProvider;
|
||||
use MetaTech\Silex\Provider\UserProvider;
|
||||
use MetaTech\Db\PdoWrapper;
|
||||
use MetaTech\Db\Profile;
|
||||
use MetaTech\PwsAuth\Authenticator;
|
||||
use MetaTech\PwsServer\Ctrl\Test;
|
||||
use MetaTech\PwsServer\Ctrl\WebService;
|
||||
|
@ -35,8 +38,11 @@ class Application extends App
|
|||
$app['ws.authenticator'] = function ($app) {
|
||||
return new Authenticator($app['config']['pwsauth']);
|
||||
};
|
||||
$app['pdo'] = function ($app) {
|
||||
return new PdoWrapper(new Profile($app['config']['db']['default']));
|
||||
};
|
||||
$app['user.provider'] = function ($app) {
|
||||
return null;
|
||||
return new UserProvider($app['pdo']);
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -10,8 +10,11 @@
|
|||
namespace MetaTech\PwsServer\Ws;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Session\Session;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\Security\Core\Encoder\PasswordEncoderInterface;
|
||||
use MetaTech\PwsAuth\Authenticator;
|
||||
use MetaTech\Silex\Ws\Authentication as BaseAuthentication;
|
||||
use MetaTech\Silex\Provider\UserProvider;
|
||||
|
||||
/*!
|
||||
* @package MetaTech\PwsServer\Ws
|
||||
|
@ -27,26 +30,39 @@ class Authentication extends BaseAuthentication
|
|||
/*!
|
||||
* @constructor
|
||||
* @public
|
||||
* @param Symfony\Component\HttpFoundation\Session\Session $session
|
||||
* @param MetaTech\PwsAuth\Authenticator $authenticator
|
||||
* @param Symfony\Component\HttpFoundation\Session\Session $session
|
||||
* @param MetaTech\PwsAuth\Authenticator $authenticator
|
||||
* @param Symfony\Component\Security\Core\Encoder\PasswordEncoderInterface $passEncoder
|
||||
* @param MetaTech\Silex\Provider\UserProvider $userProvider
|
||||
*/
|
||||
public function __construct(Session $session, Authenticator $authenticator, $userProvider)
|
||||
public function __construct(Session $session, Authenticator $authenticator, PasswordEncoderInterface $passEncoder = null, UserProvider $userProvider)
|
||||
{
|
||||
parent::__construct($session, $authenticator);
|
||||
$this->userOrovider = $userProvider;
|
||||
parent::__construct($session, $authenticator, $passEncoder);
|
||||
$this->userProvider = $userProvider;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @method checkUser
|
||||
* @public
|
||||
* @param str $login
|
||||
* @param str $password
|
||||
* @param str $key
|
||||
* @param str $login
|
||||
* @param str $password
|
||||
* @param str $key
|
||||
* @param Symfony\Component\Security\Core\Encoder\PasswordEncoderInterface $passEncoder
|
||||
* @return bool
|
||||
*/
|
||||
public function checkUser($login, $password, $key)
|
||||
public function checkUser($login, $password, $key, PasswordEncoderInterface $passEncoder = null)
|
||||
{
|
||||
// @todo implements with userProvider
|
||||
return true;
|
||||
$done = false;
|
||||
try {
|
||||
if (!is_null($passEncoder)) {
|
||||
$user = $this->userProvider->loadUserByUsername($login);
|
||||
$salt = $this->authenticator->getUserSalt($login);
|
||||
$done = $user->key == $key && $passEncoder->encodePassword($password, $salt) == $user->getPassword();
|
||||
}
|
||||
}
|
||||
catch(\Exception $e) {
|
||||
//~ var_dump($e->getTraceAsString());
|
||||
}
|
||||
return $done;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,6 +32,6 @@ class Controller extends BaseController
|
|||
public function __construct(Application $app = null)
|
||||
{
|
||||
$this->session = $app['session'];
|
||||
$this->handler = new Authentication($this->session, $app['ws.authenticator'], $app['user.provider']);
|
||||
$this->handler = new Authentication($this->session, $app['ws.authenticator'], $app['security.encoder.pbkdf2'], $app['user.provider']);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user