本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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;
}
示例5: __invoke
/**
* Retrieve the current admin
*
* @return UserModel|boolean
*/
public function __invoke()
{
if ($this->auth->hasIdentity()) {
return $this->auth->getIdentity();
}
return false;
}
示例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);
}
示例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));
}
示例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'));
}
示例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;
}
示例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();
}
示例11: getIdentityRoles
/**
* {@inheritDoc}
*/
public function getIdentityRoles()
{
$identity = $this->authService->getIdentity();
if ($identity) {
return explode(',', $identity->getGroups());
} else {
return array($this->defaultRole);
}
}
示例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();
}
示例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;
}
示例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();
}
示例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;
}