コード例 #1
0
ファイル: Shibboleth.php プロジェクト: Jazzee/Jazzee
 /**
  * @SuppressWarnings(PHPMD.ExitExpression)
  * @throws \Jazzee\Exception
  */
 public function loginUser()
 {
     $config = $this->_controller->getConfig();
     if (!isset($_SERVER['Shib-Application-ID'])) {
         header('Location: ' . $config->getShibbolethLoginUrl());
         exit(0);
     }
     if (!isset($_SERVER[$config->getShibbolethUsernameAttribute()])) {
         throw new \Jazzee\Exception($config->getShibbolethUsernameAttribute() . ' attribute is missing from authentication source.');
     }
     $uniqueName = $_SERVER[$config->getShibbolethUsernameAttribute()];
     $firstName = isset($_SERVER[$config->getShibbolethFirstNameAttribute()]) ? $_SERVER[$config->getShibbolethFirstNameAttribute()] : null;
     $lastName = isset($_SERVER[$config->getShibbolethLastNameAttribute()]) ? $_SERVER[$config->getShibbolethLastNameAttribute()] : null;
     $mail = isset($_SERVER[$config->getShibbolethEmailAddressAttribute()]) ? $_SERVER[$config->getShibbolethEmailAddressAttribute()] : null;
     $this->_controller->getStore()->expire();
     $this->_controller->getStore()->touchAuthentication();
     $this->_user = $this->_controller->getEntityManager()->getRepository('\\Jazzee\\Entity\\User')->findOneBy(array('uniqueName' => $uniqueName, 'isActive' => true));
     if (!$this->_user) {
         //creat a new user
         $this->_user = new \Jazzee\Entity\User();
         $this->_user->setUniqueName($uniqueName);
         //persist and flush a new user early so we get the ID for the authenticaiton logs
         $this->_controller->getEntityManager()->persist($this->_user);
         $this->_controller->getEntityManager()->flush();
     }
     $this->_controller->getStore()->set(self::SESSION_VAR_ID, $this->_user->getId());
     $this->_controller->getEntityManager()->persist($this->_user);
     $this->_user->setFirstName($firstName);
     $this->_user->setLastName($lastName);
     $this->_user->setEmail($mail);
 }
コード例 #2
0
ファイル: SimpleSAML.php プロジェクト: Jazzee/Jazzee
 /**
  * Constructor
  *
  * Require authentication and setup the user if a valid session is detected
  *
  * @param \Jazzee\Interfaces\AdminController
  */
 public function __construct(\Jazzee\Interfaces\AdminController $controller)
 {
     $config = $controller->getConfig();
     require_once $config->getSimpleSAMLIncludePath();
     $this->_as = new \SimpleSAML_Auth_Simple($config->getSimpleSAMLAuthenticationSource());
     $this->_as->requireAuth();
     $attrs = $this->_as->getAttributes();
     if (!isset($attrs[$config->getSimpleSAMLUsernameAttribute()][0])) {
         throw new Exception($config->getSimpleSAMLUsernameAttribute() . ' attribute is missing from authentication source.');
     }
     $this->_user = $controller->getEntityManager()->getRepository('\\Jazzee\\Entity\\User')->findOneBy(array('uniqueName' => $attrs[$config->getSimpleSAMLUsernameAttribute()][0], 'isActive' => true));
     if ($this->_user) {
         $this->_user->setFirstName($attrs[$config->getSimpleSAMLFirstNameAttribute()][0]);
         $this->_user->setLastName($attrs[$config->getSimpleSAMLLastNameAttribute()][0]);
         $this->_user->setEmail($attrs[$config->getSimpleSAMLEmailAddressAttribute()][0]);
         $controller->getEntityManager()->persist($this->_user);
     }
 }