php Symfony-Component-Security-Core-User-UserInterface类(方法)实例源码

下面列出了php Symfony-Component-Security-Core-User-UserInterface 类(方法)源码代码实例,从而了解它的用法。

作者:flobbi    项目:PasswordSaf   
public function isEqualTo(UserInterface $user)
 {
     if ($this->username == $user->getUsername()) {
         return true;
     }
     return false;
 }

作者:astrake    项目:we   
private function logUser(UserInterface $user, $password)
 {
     $token = new UsernamePasswordToken($user, $password, 'secured_area', $user->getRoles());
     $request = $this->getRequest();
     $session = $request->getSession();
     $session->set('_security_secured_area', serialize($token));
 }

作者:xamin12    项目:platfor   
/**
  * {@inheritdoc}
  */
 protected function getSecret(UserInterface $user)
 {
     if ($user instanceof AdvancedApiUserInterface) {
         return $user->getApiKeys();
     }
     return parent::getSecret($user);
 }

作者:sul    项目:sul   
/**
  * Update the users last login.
  *
  * @param UserInterface $user
  */
 protected function updateLastLogin($user)
 {
     if ($user instanceof BaseUser) {
         $user->setLastLogin(new \DateTime());
         $this->entityManager->flush();
     }
 }

作者:bampe    项目:symfony2-ep   
private function authenticateUser(UserInterface $user)
 {
     $providerKey = 'secured_area';
     // your firewall name
     $token = new UsernamePasswordToken($user, null, $providerKey, $user->getRoles());
     $this->getSecurityContext()->setToken($token);
 }

作者:eduardobenito1    项目:CorredoresRioj   
public function isEqualTo(UserInterface $user)
 {
     if (!$user instanceof CorredorUser || $this->password !== $user->getPassword() || $this->salt !== $user->getSalt() || $this->username !== $user->getUsername()) {
         return false;
     }
     return true;
 }

作者:otoban    项目:facebook-bundl   
/**
  * {@inheritDoc}
  */
 public function isEqualTo(UserInterface $user)
 {
     if ($user instanceof FacebookUser && $user->getId() === $this->getId()) {
         return true;
     }
     return false;
 }

作者:alcaly    项目:symfony-wss   
/**
  * {@InheritDoc}
  *
  * @throws NonceExpiredException
  */
 public function validateDigest(WsseUserToken $wsseToken, UserInterface $user)
 {
     $created = $wsseToken->created;
     $nonce = $wsseToken->nonce;
     $digest = $wsseToken->digest;
     $secret = $user->getPassword();
     // Check created time is not too far in the future (leaves 5 minutes margin)
     if (strtotime($created) > time() + 300) {
         throw new WsseAuthenticationException(sprintf('Token created date cannot be in future (%d seconds in the future).', time() - strtotime($created)));
     }
     // Expire timestamp after 5 minutes
     if (strtotime($created) < time() - 300) {
         throw new WsseAuthenticationException(sprintf('Token created date has expired its 300 seconds of validity (%d seconds).', strtotime($created) - time()));
     }
     // Validate that the nonce is *not* used in the last 10 minutes
     // if it has, this could be a replay attack
     if (file_exists($this->cacheDir . '/' . $nonce) && file_get_contents($this->cacheDir . '/' . $nonce) + 600 > time()) {
         throw new NonceExpiredException('Previously used nonce detected.');
     }
     // If cache directory does not exist we create it
     if (!is_dir($this->cacheDir)) {
         mkdir($this->cacheDir, 0777, true);
     }
     file_put_contents($this->cacheDir . '/' . $nonce, time());
     // Validate Secret
     $expected = base64_encode(sha1(base64_decode($nonce) . $created . $secret, true));
     if (!StringUtils::equals($expected, $digest)) {
         throw new WsseAuthenticationException('Token digest is not valid.');
     }
     return true;
 }

作者:spherei    项目:commercetools-sunrise-ph   
/**
  * {@inheritdoc}
  */
 protected function checkAuthentication(UserInterface $user, UsernamePasswordToken $token)
 {
     $currentUser = $token->getUser();
     if ($currentUser instanceof UserInterface) {
         if ($currentUser->getPassword() !== $user->getPassword()) {
             throw new BadCredentialsException('The credentials were changed from another session.');
         }
     } else {
         if (!($presentedPassword = $token->getCredentials())) {
             throw new BadCredentialsException('The presented password cannot be empty.');
         }
         $client = $this->clientFactory->build('en');
         $request = CustomerLoginRequest::ofEmailAndPassword($token->getUser(), $presentedPassword);
         $response = $request->executeWithClient($client);
         if ($response->isError()) {
             throw new BadCredentialsException('The presented password is invalid.');
         }
         $result = $request->mapResponse($response);
         $customer = $result->getCustomer();
         if ($currentUser !== $customer->getEmail()) {
             throw new BadCredentialsException('The presented password is invalid.');
         }
         $this->session->set('customer.id', $customer->getId());
     }
 }

作者:vbessono    项目:fsrap   
public function refreshUser(UserInterface $user)
 {
     if (!$user instanceof User) {
         throw new UnsupportedUserException("Instances of {get_class({$user})} are not supported");
     }
     return $this->loadUserByUsername($user->getUsername());
 }

作者:tuimedi    项目:foru   
/**
  * {@inheritDoc}
  */
 public function refreshUser(UserInterface $user)
 {
     if (null === ($refreshedUser = $this->repository->findOneByUsername($user->getUsername()))) {
         throw new UsernameNotFoundException(sprintf('User with id %s not found', json_encode($user->getId())));
     }
     return $refreshedUser;
 }

作者:oestev    项目:grupet   
/**
  * 
  * @param string $attribute
  * @param Club $club
  * @param UserInterface $user
  * @return boolean
  */
 protected function isGranted($attribute, $club, $user = null)
 {
     switch ($attribute) {
         case self::VIEW:
             if (!$club->isPrivate()) {
                 return true;
             }
             // make sure there is a user object (i.e. that the user is logged in)
             if (!$user instanceof UserInterface) {
                 return false;
             }
             if (in_array('ROLE_ADMIN', $user->getRoles())) {
                 return true;
             }
             break;
         case self::EDIT:
             // make sure there is a user object (i.e. that the user is logged in)
             if (!$user instanceof UserInterface) {
                 return false;
             }
             foreach ($club->getAdministrators() as $administrator) {
                 if ($administrator->getId() == $user->getId()) {
                     return true;
                 }
             }
             if (in_array('ROLE_ADMIN', $user->getRoles())) {
                 return true;
             }
             return false;
         case self::CREATE:
             break;
     }
     return false;
 }

作者:redventures-os    项目:LdapBundl   
public function isEqualTo(UserInterface $user)
 {
     if (!$user instanceof LdapUser || $user->getUsername() !== $this->username || $user->getEmail() !== $this->email || count(array_diff($user->getRoles(), $this->roles)) > 0 || $user->getDn() !== $this->dn) {
         return false;
     }
     return true;
 }

作者:xsolve-p    项目:xsolve-google-auth-bundl   
public function login(UserInterface $user)
 {
     $user->setLastLogin(new \DateTime());
     $this->userManager->updateUser($user);
     $this->loginManager->loginUser($this->providerKey, $user);
     return $user;
 }

作者:laiell    项目:mediathequescru   
public function equals(UserInterface $account)
 {
     if ($this->getUsername() == $account->getUsername()) {
         return true;
     }
     return false;
 }

作者:sopine    项目:userbundl   
/**
  * {@inheritDoc}
  */
 public function connect(UserInterface $user, UserResponseInterface $response)
 {
     $property = $this->getProperty($response);
     $username = $response->getUsername();
     //on connect - get the access token and the user ID
     $service = $response->getResourceOwner()->getName();
     if ($service == "google") {
         $service = "gplus";
     }
     $setter = 'set' . ucfirst($service);
     $setter_id = $setter . 'Uid';
     $setter_token = $setter . 'Name';
     //we "disconnect" previously connected users
     if (null !== ($previousUser = $this->userManager->findUserBy(array($property => $username)))) {
         $previousUser->{$setter_id}(null);
         $previousUser->{$setter_token}(null);
         $this->userManager->updateUser($previousUser);
     }
     //we connect current user
     $user->{$setter_id}($username);
     $user->{$setter_token}($response->getAccessToken());
     //save customfield
     $user->setProfilePicture($response->getProfilePicture());
     //TODO: Save locale, $user->setLocale($response->getLocale());
     $this->userManager->updateUser($user);
 }

作者:scottstuf    项目:GCProtractorJ   
public function checkPostAuth(UserInterface $user)
 {
     if (!$user instanceof AdvancedUserInterface) {
         return;
     }
     if (!$user->isAccountNonLocked()) {
         $ex = new LockedException('User account is locked.');
         $ex->setUser($user);
         throw $ex;
     }
     if (!$user->isEnabled() and $user->getStatus() == User::STATUS_BAD_EMAIL) {
         $ex = new DisabledException('BAD_EMAIL');
         $ex->setUser($user);
         throw $ex;
     }
     if (!$user->isEnabled()) {
         $ex = new DisabledException('DISABLED');
         if ($user instanceof User && $user->getConfirmationToken()) {
             $ex = new DisabledException('DISABLED:' . Strings::base64EncodeUrl($user->getEmail()));
         }
         $ex->setUser($user);
         throw $ex;
     }
     if (!$user->isAccountNonExpired()) {
         $ex = new AccountExpiredException('User account has expired.');
         $ex->setUser($user);
         throw $ex;
     }
 }

作者:Athorci    项目:athorrent-fronten   
public function refreshUser(UserInterface $user)
 {
     if ($user instanceof User) {
         return $this->loadUserByUsername($user->getUsername());
     }
     throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', get_class($user)));
 }

作者:skydiabl    项目:FR3DLdapBundl   
/**
  * Hydrates an user entity with ldap attributes.
  *
  * @param  UserInterface $user user to hydrate
  * @param  array $entry ldap result
  *
  * @return UserInterface
  */
 protected function hydrate(UserInterface $user, array $entry)
 {
     $user->setPassword('');
     if ($user instanceof AdvancedUserInterface) {
         $user->setEnabled(true);
     }
     foreach ($this->params['attributes'] as $attr) {
         if (!array_key_exists($attr['ldap_attr'], $entry)) {
             continue;
         }
         $ldapValue = $entry[$attr['ldap_attr']];
         $value = null;
         if (!array_key_exists('count', $ldapValue) || $ldapValue['count'] == 1) {
             $value = $ldapValue[0];
         } else {
             $value = array_slice($ldapValue, 1);
         }
         call_user_func(array($user, $attr['user_method']), $value);
     }
     if ($user instanceof LdapUserInterface) {
         $user->setDn($entry['dn']);
     }
     if ($user instanceof LdapUserRoleInterface && count($this->params['role'])) {
         $this->addRoles($user, $entry);
     }
 }

作者:jayrule    项目:sf   
public function checkCredentials($credentials, UserInterface $user)
 {
     if ($user->getPassword() === $this->passwordEncoder->encodePassword($user, $credentials['password'])) {
         return true;
     }
     throw new CustomUserMessageAuthenticationException("Password is incorrect.");
 }


问题


面经


文章

微信
公众号

扫码关注公众号