/** * Provides login object created from POST-data. * * @returns AIS2Login */ private function provideLogin() { // TODO(ppershing): use injector here $factory = new LoginFactoryImpl(); if (FajrConfig::get('Login.Type') == 'cosign') { if (Input::get('loginType') == 'cosign') { return $factory->newLoginUsingCosignProxy(FajrConfig::get('Login.Cosign.ProxyDB'), FajrConfig::get('Login.Cosign.CookieName')); } return null; } $login = Input::get('login'); Input::set('login', null); $krbpwd = Input::get('krbpwd'); Input::set('krbpwd', null); $cosignCookie = Input::get('cosignCookie'); Input::set('cosignCookie', null); //TODO(ppershing): create hidden field "loginType" in the form if ($login !== null && $krbpwd !== null) { return $factory->newLoginUsingCosign($login, $krbpwd); } else { if ($cosignCookie !== null) { $cosignCookie = CosignServiceCookie::fixCookieValue($cosignCookie); // TODO(anty): change to use correct domain and cookie name return $factory->newLoginUsingCookie(new CosignServiceCookie('cosign-filter-ais2.uniba.sk', $cosignCookie, 'ais2.uniba.sk')); } else { return null; } } }
/** * 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; }
/** * 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() { $factory = $this->injector->getInstance('LoginFactory.class'); $request = $this->context->getRequest(); $loginType = $request->getParameter("loginType"); $login = $request->getParameter('login'); $krbpwd = $request->getParameter('krbpwd'); $cosignCookie = $request->getParameter('cosignCookie'); // we don't need this info in the global scope anymore $request->clearParameter('login'); $request->clearParameter('krbpwd'); $request->clearParameter('cosignCookie'); if (empty($loginType)) { return null; } if ($loginType == 'cosign') { if (FajrConfig::get('Login.Type') == 'cosign') { return $factory->newLoginUsingCosignProxy(FajrConfig::get('Login.Cosign.ProxyDB'), FajrConfig::get('Login.Cosign.CookieName')); } return null; } else { if ($loginType == 'password') { if ($login == null || $krbpwd == null) { // TODO(anty): maybe throw an exception? (and display login form...) return null; } return $factory->newLoginUsingCosign($login, $krbpwd); } else { if ($loginType == 'cookie') { if ($cosignCookie == null) { // TODO(anty): maybe throw an exception? (and display login form...) return null; } $cosignCookie = CosignServiceCookie::fixCookieValue($cosignCookie); return $factory->newLoginUsingCookie(new CosignServiceCookie(FajrConfig::get('Login.Cosign.CookieName'), $cosignCookie, FajrConfig::get('AIS2.ServerName'))); } } } return null; }
/** * 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, LoginFactory $factory, 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 $factory->newLoginUsingPassword($login, $password); break; case 'cosign': if ($loginType === 'cosigncookie') { if ($cosignCookie === '') { return null; } $cosignCookie = CosignServiceCookie::fixCookieValue($cosignCookie); return $factory->newLoginUsingCosignCookie(new CosignServiceCookie($serverConfig->getCosignCookieName(), $cosignCookie, $serverConfig->getServerName())); } else { if ($loginType == 'cosignpassword') { if ($login === null || $password === null) { return null; } return $factory->newLoginUsingCosignPassword($login, $password); } else { $this->assertSecurity(false, "Wrong loginType {$loginType}"); } } break; case 'cosignproxy': $this->assertSecurity($loginType === 'cosignproxy', "Wrong loginType {$loginType}"); return $factory->newLoginUsingCosignProxy($serverConfig->getCosignProxyDB(), $serverConfig->getCosignCookieName()); case 'nologin': $this->assertSecurity($loginType === 'nologin', "Wrong loginType {$loginType}"); return $factory->newNoLogin(); default: // TODO(ppershing): throw ConfigError assert(false); } }