Search in sources :

Example 21 with EntityDescriptor

use of org.opensaml.saml2.metadata.EntityDescriptor in project ddf by codice.

the class SamlProtocolTest method testCreateIdpMetadata.

@Test
public void testCreateIdpMetadata() {
    EntityDescriptor entityDescriptor = SamlProtocol.createIdpMetadata("myid", "mysigningcert", "myencryptioncert", Arrays.asList("mynameid"), "redirectlocation", "postlocation", "soaplocation", "logoutlocation");
    assertEquals("myid", entityDescriptor.getEntityID());
    assertEquals("mysigningcert", entityDescriptor.getIDPSSODescriptor(SamlProtocol.SUPPORTED_PROTOCOL).getKeyDescriptors().get(0).getKeyInfo().getX509Datas().get(0).getX509Certificates().get(0).getValue());
    assertEquals("myencryptioncert", entityDescriptor.getIDPSSODescriptor(SamlProtocol.SUPPORTED_PROTOCOL).getKeyDescriptors().get(1).getKeyInfo().getX509Datas().get(0).getX509Certificates().get(0).getValue());
    assertEquals("mynameid", entityDescriptor.getIDPSSODescriptor(SamlProtocol.SUPPORTED_PROTOCOL).getNameIDFormats().get(0).getFormat());
    assertEquals("logoutlocation", entityDescriptor.getIDPSSODescriptor(SamlProtocol.SUPPORTED_PROTOCOL).getSingleLogoutServices().get(0).getLocation());
    List<SingleSignOnService> ssoServices = entityDescriptor.getIDPSSODescriptor(SamlProtocol.SUPPORTED_PROTOCOL).getSingleSignOnServices();
    assertTrue(ssoServices.stream().filter(service -> service.getBinding().equals(REDIRECT_BINDING) && service.getLocation().equals("redirectlocation")).findFirst().isPresent());
    assertTrue(ssoServices.stream().filter(service -> service.getBinding().equals(POST_BINDING) && service.getLocation().equals("postlocation")).findFirst().isPresent());
    assertTrue(ssoServices.stream().filter(service -> service.getBinding().equals(SOAP_BINDING) && service.getLocation().equals("soaplocation")).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) SingleSignOnService(org.opensaml.saml.saml2.metadata.SingleSignOnService) Test(org.junit.Test)

Example 22 with EntityDescriptor

use of org.opensaml.saml2.metadata.EntityDescriptor in project cas by apereo.

the class AuthnRequestRequestedAttributesAttributeReleasePolicy method getAttributesForSamlRegisteredService.

@Override
protected Map<String, List<Object>> getAttributesForSamlRegisteredService(final Map<String, List<Object>> attributes, final ApplicationContext applicationContext, final SamlRegisteredServiceCachingMetadataResolver resolver, final SamlRegisteredServiceServiceProviderMetadataFacade facade, final EntityDescriptor entityDescriptor, final RegisteredServiceAttributeReleasePolicyContext context) {
    val releaseAttributes = new HashMap<String, List<Object>>();
    getSamlAuthnRequest(applicationContext).ifPresent(authnRequest -> {
        if (authnRequest.getExtensions() != null) {
            authnRequest.getExtensions().getUnknownXMLObjects().stream().filter(object -> object instanceof RequestedAttribute).map(object -> (RequestedAttribute) object).filter(attr -> {
                val name = this.useFriendlyName ? attr.getFriendlyName() : attr.getName();
                LOGGER.debug("Checking for requested attribute [{}] in metadata for [{}]", name, context.getRegisteredService().getName());
                return attributes.containsKey(name);
            }).forEach(attr -> {
                val name = this.useFriendlyName ? attr.getFriendlyName() : attr.getName();
                LOGGER.debug("Found requested attribute [{}] in metadata for [{}]", name, context.getRegisteredService().getName());
                releaseAttributes.put(name, attributes.get(name));
            });
        }
    });
    return authorizeReleaseOfAllowedAttributes(context, releaseAttributes);
}
Also used : lombok.val(lombok.val) Setter(lombok.Setter) RegisteredServiceAttributeReleasePolicyContext(org.apereo.cas.services.RegisteredServiceAttributeReleasePolicyContext) Getter(lombok.Getter) SamlRegisteredServiceCachingMetadataResolver(org.apereo.cas.support.saml.services.idp.metadata.cache.SamlRegisteredServiceCachingMetadataResolver) lombok.val(lombok.val) HashMap(java.util.HashMap) EqualsAndHashCode(lombok.EqualsAndHashCode) ApplicationContext(org.springframework.context.ApplicationContext) ArrayList(java.util.ArrayList) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) Map(java.util.Map) ToString(lombok.ToString) SamlRegisteredServiceServiceProviderMetadataFacade(org.apereo.cas.support.saml.services.idp.metadata.SamlRegisteredServiceServiceProviderMetadataFacade) AllArgsConstructor(lombok.AllArgsConstructor) EntityDescriptor(org.opensaml.saml.saml2.metadata.EntityDescriptor) ApplicationContextProvider(org.apereo.cas.util.spring.ApplicationContextProvider) RequestedAttribute(org.opensaml.saml.saml2.metadata.RequestedAttribute) NoArgsConstructor(lombok.NoArgsConstructor) HashMap(java.util.HashMap) RequestedAttribute(org.opensaml.saml.saml2.metadata.RequestedAttribute)

Example 23 with EntityDescriptor

use of org.opensaml.saml2.metadata.EntityDescriptor in project cas by apereo.

the class MetadataRegistrationAuthorityAttributeReleasePolicy method getAttributesForSamlRegisteredService.

@Override
protected Map<String, List<Object>> getAttributesForSamlRegisteredService(final Map<String, List<Object>> attributes, final ApplicationContext applicationContext, final SamlRegisteredServiceCachingMetadataResolver resolver, final SamlRegisteredServiceServiceProviderMetadataFacade facade, final EntityDescriptor entityDescriptor, final RegisteredServiceAttributeReleasePolicyContext context) {
    val extensions = Optional.ofNullable(facade.getExtensions()).map(ElementExtensibleXMLObject::getUnknownXMLObjects).orElseGet(List::of);
    val matched = extensions.stream().filter(object -> object instanceof RegistrationInfo).map(info -> (RegistrationInfo) info).anyMatch(info -> RegexUtils.find(this.registrationAuthority, info.getRegistrationAuthority()));
    if (matched) {
        return authorizeReleaseOfAllowedAttributes(context, attributes);
    }
    return new HashMap<>(0);
}
Also used : lombok.val(lombok.val) Setter(lombok.Setter) RegisteredServiceAttributeReleasePolicyContext(org.apereo.cas.services.RegisteredServiceAttributeReleasePolicyContext) Getter(lombok.Getter) SamlRegisteredServiceCachingMetadataResolver(org.apereo.cas.support.saml.services.idp.metadata.cache.SamlRegisteredServiceCachingMetadataResolver) lombok.val(lombok.val) HashMap(java.util.HashMap) RegistrationInfo(org.opensaml.saml.ext.saml2mdrpi.RegistrationInfo) EqualsAndHashCode(lombok.EqualsAndHashCode) ElementExtensibleXMLObject(org.opensaml.core.xml.ElementExtensibleXMLObject) ApplicationContext(org.springframework.context.ApplicationContext) RegexUtils(org.apereo.cas.util.RegexUtils) List(java.util.List) Map(java.util.Map) ToString(lombok.ToString) SamlRegisteredServiceServiceProviderMetadataFacade(org.apereo.cas.support.saml.services.idp.metadata.SamlRegisteredServiceServiceProviderMetadataFacade) Optional(java.util.Optional) EntityDescriptor(org.opensaml.saml.saml2.metadata.EntityDescriptor) RegistrationInfo(org.opensaml.saml.ext.saml2mdrpi.RegistrationInfo) HashMap(java.util.HashMap) List(java.util.List)

Example 24 with EntityDescriptor

use of org.opensaml.saml2.metadata.EntityDescriptor in project verify-hub by alphagov.

the class HubIdentityProviderMetadataDtoToEntityDescriptorTransformer method doTransform.

public EntityDescriptor doTransform(HubIdentityProviderMetadataDto dto) {
    EntityDescriptor entityDescriptor = openSamlXmlObjectFactory.createEntityDescriptor();
    entityDescriptor.setID(idGenerator.getId());
    entityDescriptor.setEntityID(dto.getEntityId());
    entityDescriptor.setValidUntil(dto.getValidUntil());
    IDPSSODescriptor idpSsoDescriptor = openSamlXmlObjectFactory.createIDPSSODescriptor();
    idpSsoDescriptor.addSupportedProtocol(SAMLConstants.SAML20P_NS);
    transformSingleSignOnServiceEndpoints(idpSsoDescriptor, dto);
    List<KeyDescriptor> signingKeyDescriptors = keyDescriptorsUnmarshaller.fromCertificates(List.copyOf(dto.getSigningCertificates()));
    idpSsoDescriptor.getKeyDescriptors().addAll(signingKeyDescriptors);
    entityDescriptor.getRoleDescriptors().add(idpSsoDescriptor);
    return entityDescriptor;
}
Also used : EntityDescriptor(org.opensaml.saml.saml2.metadata.EntityDescriptor) IDPSSODescriptor(org.opensaml.saml.saml2.metadata.IDPSSODescriptor) KeyDescriptor(org.opensaml.saml.saml2.metadata.KeyDescriptor)

Example 25 with EntityDescriptor

use of org.opensaml.saml2.metadata.EntityDescriptor in project verify-hub by alphagov.

the class IdpSingleSignOnServiceHelperTest method setUp.

@BeforeEach
public void setUp() throws ResolverException, MarshallingException, SignatureException {
    CriteriaSet criteria = new CriteriaSet(new EntityIdCriterion(idpEntityId));
    EntityDescriptor idpEntityDescriptor = anEntityDescriptor().withIdpSsoDescriptor(anIdpSsoDescriptor().withSingleSignOnService(anEndpoint().withLocation(idpSSOUri.toASCIIString()).buildSingleSignOnService()).build()).build();
    when(metadataProvider.resolveSingle(eq(criteria))).thenReturn(idpEntityDescriptor);
    when(metadataProvider.resolveSingle(not(eq(criteria)))).thenReturn(null);
    idpSingleSignOnServiceHelper = new IdpSingleSignOnServiceHelper(metadataProvider);
}
Also used : EntityDescriptor(org.opensaml.saml.saml2.metadata.EntityDescriptor) EntityDescriptorBuilder.anEntityDescriptor(uk.gov.ida.saml.core.test.builders.metadata.EntityDescriptorBuilder.anEntityDescriptor) CriteriaSet(net.shibboleth.utilities.java.support.resolver.CriteriaSet) EntityIdCriterion(org.opensaml.core.criterion.EntityIdCriterion) BeforeEach(org.junit.jupiter.api.BeforeEach)

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