本文整理汇总了PHP中Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken类的典型用法代码示例。如果您正苦于以下问题:PHP UsernamePasswordToken类的具体用法?PHP UsernamePasswordToken怎么用?PHP UsernamePasswordToken使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了UsernamePasswordToken类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: authenticate
/**
* {@inheritdoc}
*/
public function authenticate(TokenInterface $token)
{
if (!$this->supports($token)) {
return;
}
$username = $token->getUsername();
if (empty($username)) {
$username = 'NONE_PROVIDED';
}
try {
$user = $this->retrieveUser($username, $token);
} catch (UsernameNotFoundException $notFound) {
if ($this->hideUserNotFoundExceptions) {
throw new BadCredentialsException('Bad credentials', 0, $notFound);
}
$notFound->setUsername($username);
throw $notFound;
}
if (!$user instanceof UserInterface) {
throw new AuthenticationServiceException('retrieveUser() must return a UserInterface.');
}
try {
$this->userChecker->checkPreAuth($user);
$this->checkAuthentication($user, $token);
$this->userChecker->checkPostAuth($user);
} catch (BadCredentialsException $e) {
if ($this->hideUserNotFoundExceptions) {
throw new BadCredentialsException('Bad credentials', 0, $e);
}
throw $e;
}
$authenticatedToken = new UsernamePasswordToken($user, $token->getCredentials(), $this->providerKey, $this->getRoles($user, $token));
$authenticatedToken->setAttributes($token->getAttributes());
return $authenticatedToken;
}
示例2: authUserFromRedmine
public function authUserFromRedmine(UsernamePasswordToken $token)
{
$pass = $token->getCredentials();
$username = $token->getUser();
try {
$response = $this->client->redmineLogin($username, $pass);
$q = json_decode($response);
$em = $this->em;
$user = $em->getRepository("RedmineAppBundle:RedmineUser")->findOneBy(['redmineToken' => $q->user->api_key, 'redmineUserID' => $q->user->id]);
if ($user) {
return $user->getUsername();
} else {
$user = new RedmineUser();
$user->setUsername($q->user->login)->setEmail($q->user->mail)->setPassword($this->encoder->encodePassword($user, md5(uniqid())))->setName($q->user->firstname)->setSurname($q->user->lastname)->setRedmineUserID($q->user->id)->setRedmineToken($q->user->api_key);
$settings = new Settings();
$settings->setSms(false)->setPush(false)->setCheckFirst(Carbon::createFromTime(17, 45))->setCheckSecond(Carbon::createFromTime(20, 0))->setCheckThird(Carbon::createFromTime(9, 30))->setUser($user);
$this->em->persist($user);
$this->em->persist($settings);
$this->em->flush();
return $user->getUsername();
}
} catch (\Exception $e) {
return null;
}
}
示例3: testUserBlame
public function testUserBlame()
{
$context = $this->getContainer()->get('security.context');
$token = new UsernamePasswordToken('test', 'test', 'test_provider', []);
$user = new User();
$user->setUsername('dantleech');
$user->setPassword('foo');
$user->setLocale('fr');
$user->setSalt('saltz');
$this->db('ORM')->getOm()->persist($user);
$this->db('ORM')->getOm()->flush();
$token->setUser($user);
$context->setToken($token);
$contact = new Contact();
$contact->setFirstName('Max');
$contact->setLastName('Mustermann');
$contact->setPosition('CEO');
$contact->setSalutation('Sehr geehrter Herr Dr Mustermann');
$this->db('ORM')->getOm()->persist($contact);
$this->db('ORM')->getOm()->flush();
$changer = $contact->getChanger();
$creator = $contact->getCreator();
$this->assertSame($changer, $user);
$this->assertSame($creator, $user);
}
示例4: setUp
public function setUp()
{
$this->voter = new ProfileVoter();
$this->token = new UsernamePasswordToken('testuser', 'password', 'public');
$this->user = new User();
$this->token->setUser($this->user);
}
示例5: checkAuthentication
/**
* {@inheritdoc}
*/
protected function checkAuthentication(UserInterface $user, UsernamePasswordToken $token)
{
$password = $token->getCredentials();
if ($password === null || $password === '') {
throw new BadCredentialsException('The presented password is invalid.');
}
return parent::checkAuthentication($user, $token);
}
示例6: authenticate
public function authenticate(TokenInterface $token)
{
if ($this->code != $token->getCredentials()) {
throw new AuthenticationException("Authentication code does not match");
}
$user = $token->getUser();
// TODO: Provide a mechanism to get the real user object, and set user roles in token
$token = new UsernamePasswordToken($user, $token->getCredentials(), $this->name, ['ROLE_USER']);
return $token;
}
示例7: checkAuthentication
/**
* {@inheritdoc}
*/
protected function checkAuthentication(UserInterface $user, UsernamePasswordToken $token)
{
$password = $token->getCredentials();
try {
$username = $user->getUsername();
$this->ldap->bind($username, $password);
} catch (ConnectionException $e) {
throw new BadCredentialsException('The presented password is invalid.');
}
}
示例8: features_for_user
public function features_for_user($user)
{
$token = new UsernamePasswordToken($user->getUsername(), null, 'main', $user->getRoles());
$token->setUser($user);
$ret = array();
foreach ($this->supported_features as $attribute) {
$ret[$attribute] = $this->voteOnAttribute($attribute, null, $token);
}
return $ret;
}
示例9: buildASession
private final function buildASession($session, $repository)
{
$user = $this->provider->loadUserByToken($session, $repository);
if ($user) {
$authenticatedToken = new UsernamePasswordToken($user, $session, 'front', ['ROLE_USER']);
$authenticatedToken->setUser($user);
$this->session->set($session, $authenticatedToken);
return true;
}
return false;
}
示例10: retrieveUser
/**
* {@inheritdoc}
*/
protected function retrieveUser($username, UsernamePasswordToken $token)
{
$repository = $this->getRepository();
try {
$apiUser = $repository->getUserService()->loadUserByCredentials($username, $token->getCredentials());
$repository->setCurrentUser($apiUser);
return new User($apiUser);
} catch (NotFoundException $e) {
throw new AuthenticationException('Authentication to eZ Publish failed', $e->getCode(), $e);
}
}
示例11: setClientForRiaClientView
/**
* Set client id for ria client view and add ROLE_CLIENT_VIEW to ria
*
* @param User $ria
* @param int $clientId
* @throws \InvalidArgumentException
*/
public function setClientForRiaClientView(User $ria, $clientId)
{
$this->checkIsRiaUser($ria);
$previousRoles = $this->securityContext->getToken()->getRoles();
$previousRoles[] = 'ROLE_CLIENT_VIEW';
//$ria->addRole('ROLE_CLIENT_VIEW');
//$token = new UsernamePasswordToken($ria, null, 'main', $ria->getRoles());
$token = new UsernamePasswordToken($ria, null, 'main', $previousRoles);
$token->setAttribute('ria.client_view.client_id', $clientId);
$this->securityContext->setToken($token);
}
示例12: checkAuthentication
/**
* {@inheritdoc}
*/
protected function checkAuthentication(UserInterface $user, UsernamePasswordToken $token)
{
$username = $token->getUsername();
$password = $token->getCredentials();
try {
$username = $this->ldap->escape($username, '', LDAP_ESCAPE_DN);
$dn = str_replace('{username}', $username, $this->dnString);
$this->ldap->bind($dn, $password);
} catch (ConnectionException $e) {
throw new BadCredentialsException('The presented password is invalid.');
}
}
示例13: logIn
protected function logIn()
{
$client = $this->container->get('client.repository')->findOneBy([]);
$session = $this->client->getContainer()->get('session');
$firewall = 'client';
$token = new UsernamePasswordToken('demo@wellcommerce.org', 'demo', $firewall, ['ROLE_CLIENT']);
$token->setUser($client);
$session->set('_security_' . $firewall, serialize($token));
$session->save();
$cookie = new Cookie($session->getName(), $session->getId());
$this->client->getCookieJar()->set($cookie);
$this->container->get('security.token_storage')->setToken($token);
}
示例14: logIn
protected function logIn(Client $client)
{
$em = $client->getContainer()->get('doctrine')->getManager();
$user = $em->getRepository('VidalMainBundle:User')->findOneByUsername('7binary@bk.ru');
$session = $client->getContainer()->get('session');
$firewall = 'everything';
$token = new UsernamePasswordToken($user, null, $firewall, $user->getRoles());
$token->setUser($user);
$session->set('_security_' . $firewall, serialize($token));
$session->save();
$cookie = new Cookie($session->getName(), $session->getId());
$client->getCookieJar()->set($cookie);
}
示例15: logIn
protected function logIn()
{
$user = $this->container->get('user.repository')->findOneBy([]);
$session = $this->client->getContainer()->get('session');
$firewall = 'admin';
$token = new UsernamePasswordToken('admin', 'admin', $firewall, ['ROLE_ADMIN']);
$token->setUser($user);
$session->set('_security_' . $firewall, serialize($token));
$session->save();
$cookie = new Cookie($session->getName(), $session->getId());
$this->client->getCookieJar()->set($cookie);
$this->container->get('security.token_storage')->setToken($token);
}