Search in sources :

Example 46 with EntityDescriptor

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));
}
Also used : EntityDescriptor(org.opensaml.saml.saml2.metadata.EntityDescriptor) InputStreamReader(java.io.InputStreamReader) ByteArrayInputStream(java.io.ByteArrayInputStream) Element(org.w3c.dom.Element) Transactional(org.springframework.transaction.annotation.Transactional)

Example 47 with EntityDescriptor

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());
}
Also used : AttributeQuery(org.opensaml.saml.saml2.core.AttributeQuery) Arrays(java.util.Arrays) AssertionConsumerService(org.opensaml.saml.saml2.metadata.AssertionConsumerService) Assert.assertNotNull(org.junit.Assert.assertNotNull) LogoutResponse(org.opensaml.saml.saml2.core.LogoutResponse) Assert.assertTrue(org.junit.Assert.assertTrue) POST_BINDING(ddf.security.samlp.impl.SamlProtocol.POST_BINDING) Test(org.junit.Test) PAOS_BINDING(ddf.security.samlp.impl.SamlProtocol.PAOS_BINDING) SOAP_BINDING(ddf.security.samlp.impl.SamlProtocol.SOAP_BINDING) LogoutRequest(org.opensaml.saml.saml2.core.LogoutRequest) List(java.util.List) Assert.assertNull(org.junit.Assert.assertNull) WSSecurityException(org.apache.wss4j.common.ext.WSSecurityException) SingleSignOnService(org.opensaml.saml.saml2.metadata.SingleSignOnService) REDIRECT_BINDING(ddf.security.samlp.impl.SamlProtocol.REDIRECT_BINDING) LogoutWrapper(ddf.security.samlp.LogoutWrapper) EntityDescriptor(org.opensaml.saml.saml2.metadata.EntityDescriptor) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) Response(org.opensaml.saml.saml2.core.Response) EntityDescriptor(org.opensaml.saml.saml2.metadata.EntityDescriptor) AssertionConsumerService(org.opensaml.saml.saml2.metadata.AssertionConsumerService) Test(org.junit.Test)

Example 48 with EntityDescriptor

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);
    }
}
Also used : Path(java.nio.file.Path) EntityDescriptor(org.opensaml.saml.saml2.metadata.EntityDescriptor) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) NoSuchFileException(java.nio.file.NoSuchFileException)

Example 49 with EntityDescriptor

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));
}
Also used : EntityDescriptor(org.opensaml.saml.saml2.metadata.EntityDescriptor) Test(org.junit.Test)

Example 50 with EntityDescriptor

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));
}
Also used : EntityDescriptor(org.opensaml.saml.saml2.metadata.EntityDescriptor) KeyDescriptor(org.opensaml.saml.saml2.metadata.KeyDescriptor) SamlDto(uk.gov.ida.hub.samlproxy.domain.SamlDto) Test(org.junit.jupiter.api.Test)

Aggregations

EntityDescriptor (org.opensaml.saml.saml2.metadata.EntityDescriptor)60 Test (org.junit.jupiter.api.Test)15 KeyDescriptor (org.opensaml.saml.saml2.metadata.KeyDescriptor)13 EntityDescriptorBuilder.anEntityDescriptor (uk.gov.ida.saml.core.test.builders.metadata.EntityDescriptorBuilder.anEntityDescriptor)11 CriteriaSet (net.shibboleth.utilities.java.support.resolver.CriteriaSet)8 Test (org.junit.Test)8 IDPSSODescriptor (org.opensaml.saml.saml2.metadata.IDPSSODescriptor)8 SingleSignOnService (org.opensaml.saml.saml2.metadata.SingleSignOnService)8 List (java.util.List)7 EntityIdCriterion (org.opensaml.core.criterion.EntityIdCriterion)7 AssertionConsumerService (org.opensaml.saml.saml2.metadata.AssertionConsumerService)7 X509Certificate (org.opensaml.xmlsec.signature.X509Certificate)7 IOException (java.io.IOException)6 InputStream (java.io.InputStream)6 ArrayList (java.util.ArrayList)6 SPSSODescriptor (org.opensaml.saml.saml2.metadata.SPSSODescriptor)6 InputStreamReader (java.io.InputStreamReader)5 SamlRegisteredServiceServiceProviderMetadataFacade (org.apereo.cas.support.saml.services.idp.metadata.SamlRegisteredServiceServiceProviderMetadataFacade)5 SamlRegisteredServiceCachingMetadataResolver (org.apereo.cas.support.saml.services.idp.metadata.cache.SamlRegisteredServiceCachingMetadataResolver)5 ApplicationContext (org.springframework.context.ApplicationContext)5