public function login(AIS2ServerConnection $serverConnection) { $connection = $serverConnection->getHttpConnection(); if (empty($_SERVER['REMOTE_USER'])) { throw new LoginException('Nie je nastaveny cosign username'); } $myCookie = CosignServiceCookie::getMyCookie(); $filename = $this->proxyDir . '/' . $myCookie->getName() . '=' . $myCookie->getValue(); $parser = new CosignProxyFileParser(); $cookies = $parser->parseFile(new NullTrace(), $filename); if (empty($cookies[$this->proxyCookieName])) { throw new LoginException('Neviem najst relevantny proxy cookie'); } $cookie = $cookies[$this->proxyCookieName]; $connection->addCookie($cookie->getName(), $cookie->getValue(), 0, '/', $cookie->getDomain()); return true; }
public function login(AIS2ServerConnection $serverConnection) { $connection = $serverConnection->getHttpConnection(); $connection->addCookie($this->cookie->getName(), $this->cookie->getValue(), 0, '/', $this->cookie->getDomain()); return true; }
/** * Provides login object created from POST-data * or null if login info is not (fully) present in the request. * * This function should be called only once (it will * return null on subsequent calls). * * @returns Login login instance recognized */ private function provideLogin(ServerConfig $serverConfig, Request $request) { $loginType = $request->getParameter("loginType"); $login = $request->getParameter('login'); $password = $request->getParameter('password'); $cosignCookie = $request->getParameter('cosignCookie'); // we don't need this info in the global scope anymore $request->clearParameter('login'); $request->clearParameter('password'); $request->clearParameter('cosignCookie'); if (empty($loginType)) { return null; } switch ($serverConfig->getLoginType()) { case 'password': $this->assertSecurity($loginType === 'password', "Wrong login type {$loginType}"); $this->assertSecurity($login !== null, 'Login field missing'); $this->assertSecurity($password !== null, 'Password field missing'); if ($login === '' || $password === '') { return null; } return new AIS2PasswordLogin($login, $password); break; case 'cosign': if ($loginType === 'cosigncookie') { if ($cosignCookie === '') { return null; } $cosignCookie = CosignServiceCookie::fixCookieValue($cosignCookie); return new AIS2CosignLogin(new CosignCookieLogin(new CosignServiceCookie($serverConfig->getCosignCookieName(), $cosignCookie, $serverConfig->getServerName()))); } else { if ($loginType == 'cosignpassword') { if ($login === null || $password === null) { return null; } return new AIS2CosignLogin(new CosignPasswordLogin($login, $password)); } else { $this->assertSecurity(false, "Wrong loginType {$loginType}"); } } break; case 'cosignproxy': $this->assertSecurity($loginType === 'cosignproxy', "Wrong loginType {$loginType}"); return new AIS2CosignLogin(new CosignProxyLogin($serverConfig->getCosignProxyDB(), $serverConfig->getCosignCookieName())); case 'nologin': $this->assertSecurity($loginType === 'nologin', "Wrong loginType {$loginType}"); return new NoLogin(); default: // TODO(ppershing): throw ConfigError assert(false); } }
/** * Return a cosign service cookie corresponding to this service * * @returns CosignServiceCookie service cookie for this service */ public static function getMyCookie() { if (empty($_SERVER['COSIGN_SERVICE'])) { throw new LoginException('Nazov tejto cosign sluzby nie je pritomny v ' . 'prostredi. Prosim skontrolujte nastavenie ' . 'cosignu.'); } $service = $_SERVER['COSIGN_SERVICE']; $cookieName = strtr($service, '.', '_'); if (empty($_COOKIE[$cookieName])) { throw new LoginException('Service cookie pre tuto sluzbu nie je ' . 'pritomny v prostredi.'); } $value = CosignServiceCookie::fixCookieValue($_COOKIE[$cookieName]); $domain = $_SERVER['SERVER_NAME']; $cookie = new CosignServiceCookie($service, $value, $domain); return $cookie; }