public function setSamlSpInfo(SamlSpInfo $info) { $this->samlSpInfo = $info; if ($info->getNameID()) { $this->setAttribute(self::ATTRIBUTE_NAME_ID, $info->getNameID()->getValue()); $this->setAttribute(self::ATTRIBUTE_NAME_ID_FORMAT, $info->getNameID()->getFormat()); } if ($info->getAttributes()) { foreach ($info->getAttributes() as $attribute) { $value = $attribute->getValues(); if (count($value) == 1) { $value = array_shift($value); } $this->setAttribute($attribute->getName(), $value); } } if ($info->getAuthnStatement()) { $this->setAttribute(self::ATTRIBUTE_SESSION_INDEX, $info->getAuthnStatement()->getSessionIndex()); } }
/** * @test */ public function shouldReturnEmptyArrayWhenNullAttributesSetInConstructor() { $samlSpInfo = new SamlSpInfo('idp'); $this->assertEquals(array(), $samlSpInfo->getAttributes()); }
/** * {@inheritdoc} */ public function createUserFromSamlInfo(SamlSpInfo $samlInfo) { $repository = $this->container->get('doctrine')->getManager()->getRepository('FITNetopeerBundle:SamlUser'); $user = $repository->findOneBy(array('nameID' => $samlInfo->getNameID()->getValue())); if ($user) { $user->setUsername($samlInfo->getAttributes()['eduPersonPrincipalName']->getFirstValue()); $user->setTargetedID($samlInfo->getAttributes()['eduPersonTargetedID']->getFirstValue()); } else { $user = new SamlUser(); $user->setUsername($samlInfo->getAttributes()['eduPersonPrincipalName']->getFirstValue()); $user->setTargetedID($samlInfo->getAttributes()['eduPersonTargetedID']->getFirstValue()); $user->setSessionIndex($samlInfo->getAuthnStatement()->getSessionIndex()); $user->setProviderID($samlInfo->getNameID()->getSPProvidedID()); $user->setAuthenticationServiceName($samlInfo->getAuthenticationServiceID()); $user->setNameID($samlInfo->getNameID()->getValue()); $user->setNameIDFormat($samlInfo->getNameID()->getFormat()); } $em = $this->container->get('doctrine')->getManager(); $em->persist($user); $em->flush(); return $user; }