100 lines
3.6 KiB
PHP
100 lines
3.6 KiB
PHP
<?php
|
|
|
|
namespace Cadoles\CoreBundle\Controller;
|
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
|
|
use Symfony\Component\HttpFoundation\Session\Session;
|
|
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
|
|
use Symfony\Component\Security\Http\Event\InteractiveLoginEvent;
|
|
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
|
|
use Symfony\Component\EventDispatcher\EventDispatcher;
|
|
use Symfony\Component\HttpFoundation\RedirectResponse;
|
|
use Symfony\Component\Routing\RouterInterface;
|
|
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
|
use Cadoles\CoreBundle\Entity\User;
|
|
use Cadoles\CoreBundle\Form\LoginType;
|
|
|
|
class SecurityController extends Controller
|
|
{
|
|
public function loginAction(Request $request)
|
|
{
|
|
|
|
$targetpath=$request->getSession()->get("_security.main.target_path");
|
|
|
|
// Mode d'authentification
|
|
$modeauth=$this->getParameter('mode_auth');
|
|
|
|
switch($modeauth) {
|
|
case "SQL":
|
|
$authUtils = $this->get('security.authentication_utils');
|
|
|
|
// get the login error if there is one
|
|
$error = $authUtils->getLastAuthenticationError();
|
|
|
|
// last username entered by the user
|
|
$lastUsername = $authUtils->getLastUsername();
|
|
|
|
return $this->render('CadolesCoreBundle:Security:login.html.twig', array(
|
|
'useheader' => false,
|
|
'usemenu' => false,
|
|
'usesidebar' => false,
|
|
'last_username' => $lastUsername,
|
|
'error' => $error
|
|
));
|
|
break;
|
|
}
|
|
}
|
|
|
|
public function logoutAction(Request $request)
|
|
{
|
|
$this->get('security.context')->setToken(null);
|
|
$this->get('request')->getSession()->invalidate();
|
|
}
|
|
|
|
public function killAction(Request $request)
|
|
{
|
|
$session = new Session();
|
|
if($this->getParameter("auth_mode")=="SAML") {
|
|
$samlLogout = $this->getParameter("saml_logout_url");
|
|
return $this->redirect($samlLogout);
|
|
}
|
|
else
|
|
return $this->redirectToRoute("myapp_webzine_home");
|
|
}
|
|
|
|
|
|
public function checkuserAction(Request $request)
|
|
{
|
|
// Mode d'authentification
|
|
$modeauth=$this->getParameter('mode_auth');
|
|
switch($modeauth) {
|
|
case "CAS":
|
|
// Init Client CAS
|
|
\phpCAS::setDebug(false);
|
|
\phpCAS::client(CAS_VERSION_2_0, $this->container->getParameter('cas_host'), $this->container->getParameter('cas_port'), is_null($this->container->getParameter('cas_path')) ? '' : $this->container->getParameter('cas_path'), false);
|
|
\phpCAS::setNoCasServerValidation();
|
|
|
|
if(\phpCAS::checkAuthentication()) {
|
|
$usercas = \phpCAS::getUser();
|
|
$userapp = $this->getUser();
|
|
|
|
// si on a un usercas mais pas de userapp c'est qu'il faut s'autoconnect
|
|
if(!$userapp) {
|
|
$url=$this->generateUrl('cas_sp.login');
|
|
return new Response(
|
|
'<script>document.location.replace("'.$url.'");</script>'
|
|
);
|
|
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
|
|
return new Response();
|
|
}
|
|
}
|