/** * Authenticate user by webservice * @param string $usuario * @param string $senha * @return array */ public function autentica(string $login, string $senha) { $adapter = new ObjectRepository(); $auth = new AuthenticationService(); $adapter->setOptions(array('object_manager' => Conn::getConn(), 'identity_class' => 'MyClasses\\Entities\\AclUsuario', 'identity_property' => 'login', 'credential_property' => 'senha')); $adapter->setIdentityValue($login); $adapter->setCredentialValue(sha1($senha)); $resultado = $auth->authenticate($adapter); if ($resultado->isValid()) { foreach ($resultado->getIdentity()->getEquipes() as $equipe) { $equipes[] = array($equipe->getId(), mb_convert_encoding($equipe->getPerfil(), 'UTF-8')); } return array(0 => array(0 => array($resultado->getIdentity()->getId(), mb_convert_encoding($resultado->getIdentity()->getNome(), 'UTF-8'))), 1 => $equipes); /* return base64_encode( gzcompress( serialize($resultado->getIdentity()))); */ } else { return array(0 => "login invalido"); } //throw new Exception('Exception with some special chars: Äßö'); }
public function testWillNotCastAuthCredentialValue() { $objectRepository = $this->getMock('Doctrine\\Common\\Persistence\\ObjectRepository'); $adapter = new ObjectRepositoryAdapter(); $entity = new IdentityObject(); $entity->setPassword(0); $adapter->setOptions(array('object_repository' => $objectRepository, 'credential_property' => 'password', 'identity_property' => 'username')); $adapter->setIdentity('a username'); $adapter->setCredential('00000'); $objectRepository->expects($this->once())->method('findOneBy')->with($this->equalTo(array('username' => 'a username')))->will($this->returnValue($entity)); $this->assertFalse($adapter->authenticate()->isValid()); }
public function testWillRefuseToAuthenticateWhenInvalidInstanceIsFound() { $this->setExpectedException('Zend\\Authentication\\Adapter\\Exception\\UnexpectedValueException'); $objectRepository = $this->getMock('Doctrine\\Common\\Persistence\\ObjectRepository'); $objectRepository->expects($this->once())->method('findOneBy')->with($this->equalTo(array('username' => 'a username')))->will($this->returnValue(new \stdClass())); $adapter = new ObjectRepositoryAdapter(); $adapter->setOptions(array('object_repository' => $objectRepository, 'credential_property' => 'password', 'identity_property' => 'username')); $adapter->setIdentityValue('a username'); $adapter->setCredentialValue('a password'); $adapter->authenticate(); }