Esempio n. 1
0
    $service->addAfterHook('no_cache', new NoCacheHook());
    // Authentication
    $authMethod = $config->v('authMethod');
    $tpl->addDefault(['authMethod' => $authMethod]);
    $session = new Session($request->getServerName(), $request->getRoot(), $config->v('secureCookie'));
    switch ($authMethod) {
        case 'MellonAuthentication':
            $service->addBeforeHook('auth', new MellonAuthenticationHook($config->v('MellonAuthentication', 'attribute')));
            break;
        case 'FormAuthentication':
            $tpl->addDefault(['_show_logout' => true]);
            $service->addBeforeHook('auth', new FormAuthenticationHook($session, $tpl));
            $service->addModule(new FormAuthenticationModule($config->v('FormAuthentication'), $session, $tpl));
            break;
        default:
            throw new RuntimeException('unsupported authentication mechanism');
    }
    // vpn-server-api
    $serverClient = new ServerClient(new GuzzleHttpClient(['defaults' => ['auth' => [$config->v('apiUser'), $config->v('apiPass')]]]), $config->v('apiUri'));
    $service->addBeforehook('two_factor', new TwoFactorHook($session, $tpl, $serverClient));
    // two factor module
    $twoFactorModule = new TwoFactorModule($serverClient, $session, $tpl);
    $service->addModule($twoFactorModule);
    $adminPortalModule = new AdminPortalModule($tpl, $serverClient);
    $service->addModule($adminPortalModule);
    $service->run($request)->send();
} catch (Exception $e) {
    $logger->error($e->getMessage());
    $response = new HtmlResponse($e->getMessage(), 500);
    $response->send();
}