当前位置: 首页>>代码示例>>PHP>>正文


PHP AuthenticationService::getIdentity方法代码示例

本文整理汇总了PHP中Zend\Authentication\AuthenticationService::getIdentity方法的典型用法代码示例。如果您正苦于以下问题:PHP AuthenticationService::getIdentity方法的具体用法?PHP AuthenticationService::getIdentity怎么用?PHP AuthenticationService::getIdentity使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Zend\Authentication\AuthenticationService的用法示例。


在下文中一共展示了AuthenticationService::getIdentity方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: __invoke

 public function __invoke(Request $req, Response $res, callable $next)
 {
     $res = $next($req, $res);
     $identity = $this->authService->getIdentity();
     if (!$identity) {
         return $res;
     }
     try {
         $user = R::findOne('user', 'mail = ?', [$identity->mail]);
         if (!$user) {
             $user = R::dispense('user');
             $user->uid = $identity->uid;
             $user->mail = $identity->mail;
             $user->display_name = $identity->displayName;
             $user->office_name = $identity->officeName;
             $user->authentication_source = $identity->authenticationSource;
             $user->password = '';
             $user->created = time();
             $user->role = 'school';
             $this->logger->info(sprintf('User %s imported from sso.sch.gr to database', $identity->mail));
         }
         $user->last_login = time();
         $user_id = R::store($user);
         $identityClass = get_class($identity);
         $newIdentity = new $identityClass($user_id, $user->uid, $user->mail, $user->display_name, $user->office_name, $user->authentication_source);
         $this->authService->getStorage()->write($newIdentity);
     } catch (\Exception $e) {
         $this->authService->clearIdentity();
         $this->flash->addMessage('danger', 'A problem occured storing user in database. <a href="%s" title="SSO logout">SSO Logout</a>');
         $this->logger->error('Problem inserting user form CAS in database', $identity->toArray());
         $this->logger->debug('Exception', [$e->getMessage(), $e->getTraceAsString()]);
         return $res->withRedirect($this->userErrorRedirectUrl);
     }
     return $res;
 }
开发者ID:eellak,项目名称:gredu_labs,代码行数:35,代码来源:CreateUser.php

示例2: getIdentityRoles

 /**
  * {@inheritDoc}
  */
 public function getIdentityRoles()
 {
     $definedRoles = $this->bjyConfig['role_providers']['BjyAuthorize\\Provider\\Role\\Config']['user']['children'];
     $roleKey = $this->config['identity_providers']['ldap_role_key'];
     if (!$this->authService->hasIdentity()) {
         return array($this->getDefaultRole());
     }
     $rawObj = $this->authService->getIdentity()->getRoles();
     //        $data = @unserialize($rawObj);
     //        if ($data === false) {
     //            return array($this->getDefaultRole());
     //        }
     //        $user = unserialize($rawObj);
     $user = $rawObj;
     if (is_null($user) || !is_array($user)) {
         return array($this->getDefaultRole());
     }
     $roles = array('user');
     //        foreach ($user[$roleKey] as $role) {
     foreach ($user as $role) {
         if (isset($definedRoles[$role])) {
             $roles[] = $role;
         }
     }
     return $roles;
 }
开发者ID:sha1,项目名称:zfcuser-ldap,代码行数:29,代码来源:LdapIdentityProvider.php

示例3: getUserValue

 /**
  * Get the user value to set on a Loggable field
  *
  * @param object $meta
  * @param string $field
  *
  * @return mixed
  */
 public function getUserValue($meta, $field)
 {
     if (empty($this->user) || !$this->user instanceof User) {
         $this->user = $this->authService->getIdentity();
     }
     return $this->user;
 }
开发者ID:nobesnickr,项目名称:ApiTimesheets,代码行数:15,代码来源:LoggableListener.php

示例4: __construct

 /**
  * @var AuthenticationService
  */
 public function __construct(AuthenticationService $authService, array $config)
 {
     $roles = array();
     $this->authService = $authService;
     $this->config = $config;
     $roleKey = $this->config['identity_providers']['ldap_role_key'];
     if ($this->authService->hasIdentity()) {
         $rawObj = $this->authService->getIdentity()->getRawLdapObj();
         $data = @unserialize($rawObj);
         if ($data !== false) {
             $user = unserialize($rawObj);
             if (!is_null($user) || is_array($user)) {
                 $roles = array('user');
                 foreach ($user[$roleKey] as $role) {
                     //if (isset($definedRoles[$role]))
                     $roles[] = $role;
                 }
             }
         }
     }
     if (!is_array($roles)) {
         throw new InvalidArgumentException('ZfcUserLdapRbacIdentityProvider only accepts strings or arrays');
     }
     $this->roles = $roles;
 }
开发者ID:hlich,项目名称:zfcuser-ldap,代码行数:28,代码来源:ZfcRbacIdentityProvider.php

示例5: __invoke

 /**
  * Retrieve the current admin
  *
  * @return UserModel|boolean
  */
 public function __invoke()
 {
     if ($this->auth->hasIdentity()) {
         return $this->auth->getIdentity();
     }
     return false;
 }
开发者ID:gotcms,项目名称:gotcms,代码行数:12,代码来源:Admin.php

示例6: isAllowed

 /**
  * @param $resource
  * @param $permission
  * @return bool
  */
 public function isAllowed($module, $permission, $element = null, $entity = null)
 {
     if (!$this->getAclService()->getUser()) {
         $this->getAclService()->setUser($this->authService->getIdentity());
     }
     return $this->getAclService()->isAllowed($module, $permission, $element, $entity);
 }
开发者ID:bedi,项目名称:mfcc-admin-module,代码行数:12,代码来源:Acl.php

示例7: indexAction

 public function indexAction()
 {
     $form = new LoginForm();
     $error = false;
     $request = $this->getRequest();
     if ($request->isPost()) {
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $data = $request->getPost()->toArray();
             $auth = new AuthenticationService();
             $sessionStorage = new SessionStorage("AssistenteAdmin");
             $auth->setStorage($sessionStorage);
             $authAdapter = $this->getServiceLocator()->get('Assitente\\Auth\\Adapter');
             $authAdapter->setUsername($data['email'])->setPassword($data['password']);
             $result = $auth->authenticate($authAdapter);
             if ($result->isValid()) {
                 $dadosUsuario = $auth->getIdentity()['user'];
                 //cria um container(sessao) chamada usuario
                 $user_session = new Container('usuario');
                 $user_session->id = $dadosUsuario['id'];
                 $user_session->nome = $dadosUsuario['nome'];
                 $user_session->matricula = $dadosUsuario['matricula'];
                 $user_session->foto = $dadosUsuario['foto'];
                 $user_session->dataNascimento = $dadosUsuario['dataNascimento'];
                 $user_session->email = $dadosUsuario['email'];
                 $sessionStorage->write($auth->getIdentity()['user'], null);
                 return $this->redirect()->toRoute("assistente", array('controller' => 'usuarios'));
             } else {
                 $error = true;
             }
         }
     }
     return new ViewModel(array('form' => $form, 'error' => $error));
 }
开发者ID:lucasfbr,项目名称:assistente,代码行数:34,代码来源:AuthController.php

示例8: AuthAndAcl

 /**
  * @param MvcEvent $e
  * @return bool
  */
 public function AuthAndAcl($e)
 {
     $acl = new MyAcl();
     $auth = new AuthenticationService();
     // Get User Role
     $role = $auth->getIdentity() ? User::getUserRole($auth->getIdentity()) : 'guest';
     return $acl->isAllowed($role, $e->getRouteMatch()->getParam('controller'));
 }
开发者ID:06romix,项目名称:store,代码行数:12,代码来源:Module.php

示例9: getIdentity

 /**
  * Get the identity
  *
  * @return IdentityInterface|null
  */
 public function getIdentity()
 {
     $identity = $this->authenticationService->getIdentity();
     $rbacIdentity = new RbacIdentity();
     if ($identity) {
         $rbacIdentity->setRoles($identity->getRoles());
     }
     return $rbacIdentity;
 }
开发者ID:jmleroux,项目名称:zfc-rbac-application,代码行数:14,代码来源:RbacIdentityProvider.php

示例10: testFailAuthenticationOnExpiredToken

 public function testFailAuthenticationOnExpiredToken()
 {
     $token = new AccessToken();
     $owner = $this->getMock(TokenOwnerInterface::class);
     $token->setOwner($owner);
     $this->resourceServer->expects($this->atLeastOnce())->method('getAccessToken')->with($this->isInstanceOf(PsrServerRequestInterface::class))->will($this->throwException(new OAuth2Exception('Expired token', 123)));
     $this->setExpectedException(OAuth2Exception::class, 'Expired token', 123);
     $this->authenticationService->getIdentity();
 }
开发者ID:basz,项目名称:zfr-oauth2-server-module,代码行数:9,代码来源:AuthenticationFunctionalTest.php

示例11: getIdentityRoles

 /**
  * {@inheritDoc}
  */
 public function getIdentityRoles()
 {
     $identity = $this->authService->getIdentity();
     if ($identity) {
         return explode(',', $identity->getGroups());
     } else {
         return array($this->defaultRole);
     }
 }
开发者ID:fillup,项目名称:zfauthsaml,代码行数:12,代码来源:SamlIdentityProvider.php

示例12: __invoke

 /**
  * Retrieve the current identity, if any.
  *
  * If none available, returns null.
  *
  * @throws Exception\RuntimeException
  * @return mixed|null
  */
 public function __invoke()
 {
     if (!$this->authenticationService instanceof AuthenticationService) {
         throw new Exception\RuntimeException('No AuthenticationService instance provided');
     }
     if (!$this->authenticationService->hasIdentity()) {
         return null;
     }
     return $this->authenticationService->getIdentity();
 }
开发者ID:youprofit,项目名称:casebox,代码行数:18,代码来源:Identity.php

示例13: __invoke

 /**
  * @return string
  */
 public function __invoke()
 {
     $template = '';
     if ($this->authService->hasIdentity()) {
         $user = $this->authService->getIdentity();
         $viewModel = new ViewModel(['user' => $user, 'coins' => $this->gameBackendService->getCoins($user), 'loggedIn' => $this->config['logged_in']]);
         $viewModel->setTemplate('helper/sidebarLoggedInWidget');
         $template = $this->getView()->render($viewModel);
     }
     return $template;
 }
开发者ID:kokspflanze,项目名称:PServerCore,代码行数:14,代码来源:LoggedInWidget.php

示例14: getIdentityRoles

 /**
  * {@inheritDoc}
  */
 public function getIdentityRoles()
 {
     //if user was manually deleted from storage we should clear identity
     if ($this->authService->hasIdentity() && !$this->authService->getIdentity()) {
         $this->authService->clearIdentity();
     }
     if (!$this->authService->hasIdentity()) {
         return array($this->getDefaultRole());
     }
     return $this->authService->getIdentity()->getUser()->getRole();
 }
开发者ID:zfury,项目名称:cmf,代码行数:14,代码来源:DoctrineProvider.php

示例15: getPermissions

 /**
  * Returns an array of common actions and whether they are allowed for current user
  *
  * This should NOT be used in our own code, because it is suboptimal,
  * instead a direct, single call to Authorization service is preferred. It exists here
  * only for ease of use for REST API.
  * @param AbstractModel $object
  * @return array
  */
 private function getPermissions(AbstractModel $object)
 {
     $identity = $this->authentification->getIdentity();
     $resourceId = $this->getResourceId($object);
     $resource = new \Application\Authorization\ModelResource($resourceId, $object);
     $result = [];
     $result['read'] = $this->authorization->isAuthorized($identity, $resource, Request::METHOD_GET);
     $result['update'] = $this->authorization->isAuthorized($identity, $resource, Request::METHOD_PUT);
     $result['delete'] = $this->authorization->isAuthorized($identity, $resource, Request::METHOD_DELETE);
     return $result;
 }
开发者ID:Theodia,项目名称:theodia.org,代码行数:20,代码来源:Hydrator.php


注:本文中的Zend\Authentication\AuthenticationService::getIdentity方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。