use of org.opensaml.saml2.metadata.EntityDescriptor in project syncope by apache.
the class SAML2IdPCache method put.
@Transactional(readOnly = true)
public SAML2IdPEntity put(final SAML2IdP idp) throws CertificateException, IOException, KeyStoreException, NoSuchAlgorithmException, WSSecurityException, XMLParserException {
Element element = OpenSAMLUtil.getParserPool().parse(new InputStreamReader(new ByteArrayInputStream(idp.getMetadata()))).getDocumentElement();
EntityDescriptor entityDescriptor = (EntityDescriptor) OpenSAMLUtil.fromDom(element);
return put(entityDescriptor, binder.getIdPTO(idp));
}
use of org.opensaml.saml2.metadata.EntityDescriptor in project ddf by codice.
the class SamlProtocolTest method testCreateSpMetadata.
@Test
public void testCreateSpMetadata() {
EntityDescriptor entityDescriptor = SamlProtocol.createSpMetadata("myid", "mysigningcert", "myencryptioncert", Arrays.asList("mynameid"), "logoutlocation", "redirectlocation", "postlocation", "paoslocation");
assertEquals("myid", entityDescriptor.getEntityID());
assertEquals("mysigningcert", entityDescriptor.getSPSSODescriptor(SamlProtocol.SUPPORTED_PROTOCOL).getKeyDescriptors().get(0).getKeyInfo().getX509Datas().get(0).getX509Certificates().get(0).getValue());
assertEquals("myencryptioncert", entityDescriptor.getSPSSODescriptor(SamlProtocol.SUPPORTED_PROTOCOL).getKeyDescriptors().get(1).getKeyInfo().getX509Datas().get(0).getX509Certificates().get(0).getValue());
assertEquals("mynameid", entityDescriptor.getSPSSODescriptor(SamlProtocol.SUPPORTED_PROTOCOL).getNameIDFormats().get(0).getFormat());
assertEquals("logoutlocation", entityDescriptor.getSPSSODescriptor(SamlProtocol.SUPPORTED_PROTOCOL).getSingleLogoutServices().get(0).getLocation());
List<AssertionConsumerService> acServices = entityDescriptor.getSPSSODescriptor(SamlProtocol.SUPPORTED_PROTOCOL).getAssertionConsumerServices();
assertTrue(acServices.stream().filter(service -> service.getBinding().equals(REDIRECT_BINDING) && service.getLocation().equals("redirectlocation")).findFirst().isPresent());
assertTrue(acServices.stream().filter(service -> service.getBinding().equals(POST_BINDING) && service.getLocation().equals("postlocation")).findFirst().isPresent());
assertTrue(acServices.stream().filter(service -> service.getBinding().equals(PAOS_BINDING) && service.getLocation().equals("paoslocation")).findFirst().isPresent());
assertNotNull(entityDescriptor.getCacheDuration());
}
use of org.opensaml.saml2.metadata.EntityDescriptor in project ddf by codice.
the class MetadataConfigurationParser method privilegedParseEntityDescriptions.
private void privilegedParseEntityDescriptions(Path metadataFolder) throws IOException {
try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(metadataFolder)) {
for (Path path : directoryStream) {
if (Files.isReadable(path)) {
try (InputStream fileInputStream = Files.newInputStream(path)) {
List<EntityDescriptor> entityDescriptors = readEntityDescriptors(new InputStreamReader(fileInputStream, "UTF-8"));
entityDescriptors.forEach(this::processEntityDescriptor);
}
}
}
} catch (NoSuchFileException e) {
LOGGER.debug("IDP metadata directory is not configured.", e);
}
}
use of org.opensaml.saml2.metadata.EntityDescriptor in project ddf by codice.
the class MetadataConfigurationParserTest method testRootElementNoCacheDuration.
@Test
public void testRootElementNoCacheDuration() throws Exception {
String xml = IOUtils.toString(entityDescriptorPath.toUri());
String xmlNoCacheDuration = xml.replaceFirst(CACHE_DURATION_REGEX, "");
EntityDescriptor entity = getEntityDescriptor(xmlNoCacheDuration);
assertThat(String.format("Expected default cache duration %s milliseconds", SEVEN_DAYS), entity.getCacheDuration(), is(SEVEN_DAYS));
}
use of org.opensaml.saml2.metadata.EntityDescriptor in project verify-hub by alphagov.
the class HubMetadataIntegrationTests method getIdpMetadataFromApi_shouldWork.
@Test
public void getIdpMetadataFromApi_shouldWork() {
SamlDto samlDto = client.getTargetMain(UriBuilder.fromPath("/API/metadata/idp").build(), SamlDto.class);
EntityDescriptor entityDescriptor = getEntityDescriptor(samlDto);
assertThat(entityDescriptor.getEntityID()).isEqualTo(HUB_ENTITY_ID);
assertThat(entityDescriptor.getSPSSODescriptor(SAMLConstants.SAML20P_NS)).isNull();
assertThat(entityDescriptor.getIDPSSODescriptor(SAMLConstants.SAML20P_NS)).isNotNull();
List<KeyDescriptor> keyDescriptors = entityDescriptor.getIDPSSODescriptor(SAMLConstants.SAML20P_NS).getKeyDescriptors();
// this is a bit fragile and dependent on the ordering of IDPs and in federation metadata
// this endpoint should be removed soon though...
assertThat(keyDescriptors).hasSize(7);
// signing certificates
validateKeyDescriptor(keyDescriptors, 0, HUB_ENTITY_ID);
validateKeyDescriptor(keyDescriptors, 1, HUB_ENTITY_ID, TestCertificateStrings.PUBLIC_SIGNING_CERTS.get(HUB_SECONDARY_ENTITY_ID));
validateKeyDescriptor(keyDescriptors, 2, STUB_IDP_ONE);
validateKeyDescriptor(keyDescriptors, 3, STUB_IDP_TWO);
validateKeyDescriptor(keyDescriptors, 4, STUB_IDP_THREE);
validateKeyDescriptor(keyDescriptors, 5, STUB_IDP_FOUR);
// encryption certificate
assertThat(getKeyName(keyDescriptors, 6)).isEqualTo(HUB_ENTITY_ID);
assertThat(getCertificateData(keyDescriptors, 6)).isEqualTo(TestCertificateStrings.getPrimaryPublicEncryptionCert(HUB_ENTITY_ID));
assertThat(entityDescriptor.getValidUntil()).isEqualTo(DateTime.now(DateTimeZone.UTC).plusHours(1));
}
Aggregations