2013-10-28 2 views
8

मैं सिम्फनी 2.3 पर सीएएस प्रमाणीकरण को एकीकृत करने के लिए एक बंडल की तलाश में हूं। मुझे इन विकल्पों को मिला और सच्चाई यह है कि मैं किसी भी आश्वस्त नहीं हूं, क्योंकि लगभग सभी बंडलों को अद्यतन किए बिना छोड़ दिया जाता है।सीएएस प्रमाणीकरण Symfony2

1.- सेंसिओलाब/कैसबंडल: https://github.com/sensiolabs/CasBundle प्रलेखन अस्पष्ट और अपूर्ण है। मुझे इसका उपयोग करने के तरीके के बारे में कोई उदाहरण नहीं मिला है।

2.- BeSimple/BeSimpleSsoAuthBundle: https://github.com/BeSimple/BeSimpleSsoAuthBundle इसके साथ मैं परीक्षण कर रहा हूं और मुझे कुछ समस्याएं आ रही हैं। मुझे लगता है कि मैं चौथी समस्या पर हल हो गया हूं और मैं दूसरे के पीछे आता हूं।

3.- Symfony कैस ग्राहक: https://wiki.jasig.org/display/CASC/Symfony+CAS+Client पूरी तरह से पुरानी

वास्तव में, वहाँ बहुत कुछ विकल्प सिम्फोनी में कैस के साथ प्रमाणित करने कर रहे हैं?

+0

हम ['जैजिग/phpcas'] (https://github.com/Jasig/phpCAS/blob/master/docs/examples/example_simple.php) का उपयोग करके अपने स्वयं के प्रदाता को कार्यान्वित करना समाप्त कर देते हैं) बहुत सरल था। – rolebi

+0

मुझे एक ही समस्या है। वर्तमान में 'BeSimpleSsoAuthBundle' के 'login_path' के साथ strugling। प्रमाणीकरण के बाद, सीएएस सर्वर मुझे '/ login'' के लिए आगे बढ़ाता है ... इस पर वास्तव में बहुत कम दस्तावेज़ हैं ... :( –

+0

इस विषय पर एक से अधिक वर्षों से कोई समाचार? –

उत्तर

2

मेरे पास पहले एक ही समस्या है और मैंने इसे BeSimpleSsoAuthBundle का उपयोग करके हल किया है, लेकिन आपको कुछ बदलाव करना है: मान लीजिए कि आपकी उपयोगकर्ता इकाई पहले से ही आपके उपयोगकर्ता बंडल में लागू हो चुकी है, जिसमें एक अद्वितीय विशेषता एसजीआईडी ​​है जिसे आपको ओवरराइड करना है : 1- BeSimple \ SsoAuthBundle \ सुरक्षा \ कोर \ उपयोगकर्ता:

<?php 

namespace Application\UserBundle\Security\BeSimple\SpawnedUserProvider; 

use BeSimple\SsoAuthBundle\Security\Core\User\SpawnedUserProvider; 
use Symfony\Component\Security\Core\User\UserInterface; 
use Symfony\Component\Security\Core\User\User; 
use Symfony\Component\HttpFoundation\RedirectResponse; 


class SsoUserProvider extends SpawnedUserProvider 
{ 
/** 
* @var array 
*/ 
private $roles; 

/** 
* Constructor. 
* 
* @param array $roles An array of roles 
*/ 
private $entityManager; 
private $securityContext; 

public function __construct($em, $securityContext) { 
    $this->em = $em; 
    $this->securityContext = $securityContext; 
} 

/** 
* {@inheritdoc} 
*/ 
public function loadUserByUsername($username) 
{ 
    $session = $this->securityContext; 

    $qb = $this->em->createQueryBuilder(); 
    $qb->select("u") 
     ->from('ApplicationUserBundle:User', 'u') 
     ->where('u.sgid = :sgid') 
     ->AndWhere('u.status = 1') 
     ->setParameter("sgid", $username); 

    $result = $qb->getQuery()->getOneOrNullResult(); 

    if ($result == NULL) { 
     $session->getFlashBag()->add('error', 'Vous ne pouvez pas vous connecter car votre compte est désactivé'); 
     return new RedirectResponse('login'); 
    } 

    $user_name = $result->getFirstName().' '.$result->getLastName(); 
    $session->set('userId', $result->getId()); 
    if ($result->getUserType() == 1) { 
     $this->roles = array('ROLE_ADMIN'); 
    }else if ($result->getUserType() == 0){ 
     $this->roles = array('ROLE_USER'); 
    }else{ 
     $session->getFlashBag()->add('error', 'Vous ne pouvez pas vous connecter car votre compte n\'a pas de rôle'); 
     return new RedirectResponse('logout'); 
    } 
    return $this->spawnUser($user_name); 
} 

/** 
* {@inheritDoc} 
*/ 
public function refreshUser(UserInterface $user) 
{ 
    if (!$user instanceof User) { 
     throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', get_class($user))); 
    } 

    return $this->spawnUser($user->getUsername()); 
} 

/** 
* {@inheritDoc} 
*/ 
public function supportsClass($class) 
{ 
    return $class === 'Symfony\Component\Security\Core\User\User'; 
} 

/** 
* Spawns a new user with given username. 
* 
* @param string $username 
* 
* @return \Symfony\Component\Security\Core\User\User 
*/ 
private function spawnUser($username) 
{ 
    //$this->roles = $this->userType; 
    return new User($username, null, (array)$this->roles, true, true, true, true); 
    } 
} 

2- अवहेलना भी BeSimple \ SsoAuthBundle \ सुरक्षा \ कोर \ प्रमाणीकरण \ प्रदाता:

<?php 

namespace Application\UserBundle\Security\BeSimple\Authentication\Provider; 

use Symfony\Component\Security\Core\User\UserInterface; 
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException; 
use Symfony\Component\Security\Core\Exception\BadCredentialsException; 
use BeSimple\SsoAuthBundle\Security\Core\User\UserFactoryInterface; 

/* 
* @Override 
*/ 
use BeSimple\SsoAuthBundle\Security\Core\Authentication\Provider\SsoAuthenticationPr ovider; 

class AppAuthenticationProvider extends SsoAuthenticationProvider 
{ 
/** 
* @var UserProviderInterface 
*/ 
private $userProvider; 

/** 
* @var bool 
*/ 
private $createUsers; 

/** 
* @var bool 
*/ 
private $hideUserNotFound; 

/** 
* @Override file 
* @throws \Symfony\Component\Security\Core\Exception\UsernameNotFoundException 
* @throws \Symfony\Component\Security\Core\Exception\BadCredentialsException 
* 
* @param string $username 
* @param array $attributes 
* 
* @return UserInterface 
*/ 
protected function provideUser($username, array $attributes = array()) 
{ 
    try { 
     $user = $this->retrieveUser($username); 
    } catch (UsernameNotFoundException $notFound) { 
     if ($this->createUsers && $this->userProvider instanceof UserFactoryInterface) { 
      $user = $this->createUser($username, $attributes); 
     } elseif ($this->hideUserNotFound) { 
      throw new BadCredentialsException('Bad credentials', 0, $notFound); 
     } else { 
      throw $notFound; 
     } 
    } 

    return $user; 
    } 

} 

3- जब उपयोगकर्ता अपने आवेदन के लिए लॉग इन सत्र में आवश्यक जानकारी को बचाने: चाहिए

parameters: 
    security.authentication.provider.sso.class: Application\UserBundle\Security\BeSimple\Authentication\Provider\AppAuthenticationProvider 

services: 
    security.authentication.provider.sso: 
     class: %security.authentication.provider.sso.class% 
     public: false 
     arguments: ['', '@security.user_checker', '', '', false] 

5- BeSimple विन्यास:

<?php 

namespace Application\UserBundle\Security\Authentication\Handler; 

use Symfony\Component\HttpFoundation\Request; 
use Symfony\Component\HttpFoundation\RedirectResponse; 
use Symfony\Component\Routing\Router; 
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; 
use Symfony\Component\Security\Core\SecurityContext; 
use Symfony\Component\Security\Http\Authentication\AuthenticationSuccessHandlerInterface; 
use Doctrine\ORM\EntityManager; 

class LoginSuccessHandler implements AuthenticationSuccessHandlerInterface 
{ 
protected 
    $router, 
    $security, 
    $entityManager; 

public function __construct(Router $router, SecurityContext $security, EntityManager $entityManager) 
{ 
    $this->router = $router; 
    $this->security = $security; 
    $this->entityManager = $entityManager; 
} 

public function onAuthenticationSuccess(Request $request, TokenInterface $token) 
{ 
    $session = $request->getSession(); 

    $attributes = $this->security->getToken()->getAttributes(); 
    $sgid = $attributes['sso:validation']['sgid']; 

    $em = $this->entityManager; 
    $qb = $em->createQueryBuilder(); 
    $qb->select("u") 
     ->from('ApplicationUserBundle:User', 'u') 
     ->where('u.sgid = :sgid') 
     ->AndWhere('u.status = 1') 
     ->setParameter("sgid", $sgid); 

    $result = $qb->getQuery()->getOneOrNullResult(); 

    //en cas où utilisateur est désactivée 
    //Malgre que si il arrive a cette handler ça veut dire qu'il activé car le test se fait sur le bundle BeSimple 
    if ($result == NULL) { 
     return new RedirectResponse($this->router->generate('login')); 
    } 

    $session->set('userId', $result->getId()); 

    $response = new RedirectResponse('admin'); 

    return $response; 
    } 
} 

4- अब आवेदन/UserBundle/Ressources/config/security_listeners.yml में एक सुरक्षा listner को परिभाषित ऐसा हो सकता है:

be_simple_sso_auth: 
admin_sso: 
    protocol: 
     id: cas 
     version: 2 
    server: 
     id: cas 
     login_url: https://adresse ip:8443/cas-server-webapp-4.0.0/login 
     logout_url: https://adresse ip:8443/cas-server-webapp-4.0.0/logout 
     validation_url: https://adresse ip:8443/cas-server-webapp-4.0.0/serviceValidate 
services: 

    spawned_user_provider: 
     class:  Application\UserBundle\Security\BeSimple\SpawnedUserProvider\SsoUserProvider 
    arguments: [@doctrine.orm.entity_manager, @session] 

6- parameters.yml

be_simple.sso_auth.client.option.curlopt_ssl_verifypeer.value: false 
    be_simple.sso_auth.client.option.curlopt_sslversion.value: 4 (Optionale) 

7- security.yml

main: 
     pattern: ^/admin 
     context: marketshare_context 
     logout: 
      path: /admin/logout 
      target:/
     #provider: sso 
     trusted_sso: 
      manager: admin_sso 
      login_action: ApplicationUserBundle:TrustedSso:login 
      logout_action: false 
      login_path: /admin/login 
      check_path: /admin/check 
      always_use_default_target_path: true 
      default_target_path: /admin/potentiel 
      failure_path: /admin/logout 
1

तुम भी परीक्षण कर सकते हैं l3-team/CasBundle यह और अधिक हाल & सक्रिय और BeSimpleSSoBundle से एक स्पष्ट प्रलेखन के साथ लगता है।

यह सिंगल साइन आउट का भी समर्थन करता है।

संबंधित मुद्दे