Search in sources :

Example 11 with SPSSODescriptorType

use of org.keycloak.dom.saml.v2.metadata.SPSSODescriptorType in project keycloak by keycloak.

the class ArtifactBindingTest method testSPMetadataArtifactBindingNotUsedForLogout.

@Test
public void testSPMetadataArtifactBindingNotUsedForLogout() throws ParsingException, URISyntaxException {
    getCleanup().addCleanup(ClientAttributeUpdater.forClient(adminClient, REALM_NAME, SAML_CLIENT_ID_SALES_POST).setAttribute(SamlConfigAttributes.SAML_ARTIFACT_BINDING, "true").setAttribute(SamlProtocol.SAML_ASSERTION_CONSUMER_URL_ARTIFACT_ATTRIBUTE, "http://url.artifact.test").setAdminUrl("http://admin.url.test").update());
    SPSSODescriptorType spDescriptor = getSPInstallationDescriptor(adminClient.realm(REALM_NAME).clients(), SAML_CLIENT_ID_SALES_POST);
    assertThat(spDescriptor.getAssertionConsumerService().get(0).getBinding(), is(equalTo(JBossSAMLURIConstants.SAML_HTTP_ARTIFACT_BINDING.getUri())));
    assertThat(spDescriptor.getAssertionConsumerService().get(0).getLocation(), is(equalTo(new URI("http://url.artifact.test"))));
    assertThat(spDescriptor.getSingleLogoutService().get(0).getBinding(), is(equalTo(JBossSAMLURIConstants.SAML_HTTP_REDIRECT_BINDING.getUri())));
    assertThat(spDescriptor.getSingleLogoutService().get(0).getLocation(), is(equalTo(new URI("http://admin.url.test"))));
}
Also used : SPSSODescriptorType(org.keycloak.dom.saml.v2.metadata.SPSSODescriptorType) URI(java.net.URI) Test(org.junit.Test)

Example 12 with SPSSODescriptorType

use of org.keycloak.dom.saml.v2.metadata.SPSSODescriptorType in project keycloak by keycloak.

the class ArtifactBindingTest method testSPMetadataArtifactBindingUsedForLogout.

@Test
public void testSPMetadataArtifactBindingUsedForLogout() throws ParsingException, URISyntaxException {
    getCleanup().addCleanup(ClientAttributeUpdater.forClient(adminClient, REALM_NAME, SAML_CLIENT_ID_SALES_POST).setAttribute(SamlConfigAttributes.SAML_ARTIFACT_BINDING, "true").setAttribute(SamlProtocol.SAML_ASSERTION_CONSUMER_URL_ARTIFACT_ATTRIBUTE, "http://url.artifact.test").setAttribute(SamlProtocol.SAML_SINGLE_LOGOUT_SERVICE_URL_ARTIFACT_ATTRIBUTE, "http://url.artifact.test").setAdminUrl("http://admin.url.test").update());
    SPSSODescriptorType spDescriptor = getSPInstallationDescriptor(adminClient.realm(REALM_NAME).clients(), SAML_CLIENT_ID_SALES_POST);
    assertThat(spDescriptor.getAssertionConsumerService().get(0).getBinding(), is(equalTo(JBossSAMLURIConstants.SAML_HTTP_ARTIFACT_BINDING.getUri())));
    assertThat(spDescriptor.getAssertionConsumerService().get(0).getLocation(), is(equalTo(new URI("http://url.artifact.test"))));
    assertThat(spDescriptor.getSingleLogoutService().get(0).getBinding(), is(equalTo(JBossSAMLURIConstants.SAML_HTTP_ARTIFACT_BINDING.getUri())));
    assertThat(spDescriptor.getSingleLogoutService().get(0).getLocation(), is(equalTo(new URI("http://url.artifact.test"))));
}
Also used : SPSSODescriptorType(org.keycloak.dom.saml.v2.metadata.SPSSODescriptorType) URI(java.net.URI) Test(org.junit.Test)

Example 13 with SPSSODescriptorType

use of org.keycloak.dom.saml.v2.metadata.SPSSODescriptorType in project keycloak by keycloak.

the class SPMetadataDescriptor method buildSPdescriptor.

public static EntityDescriptorType buildSPdescriptor(URI loginBinding, URI logoutBinding, URI assertionEndpoint, URI logoutEndpoint, boolean wantAuthnRequestsSigned, boolean wantAssertionsSigned, boolean wantAssertionsEncrypted, String entityId, String nameIDPolicyFormat, List<Element> signingCerts, List<Element> encryptionCerts) {
    EntityDescriptorType entityDescriptor = new EntityDescriptorType(entityId);
    entityDescriptor.setID(IDGenerator.create("ID_"));
    SPSSODescriptorType spSSODescriptor = new SPSSODescriptorType(Arrays.asList(PROTOCOL_NSURI.get()));
    spSSODescriptor.setAuthnRequestsSigned(wantAuthnRequestsSigned);
    spSSODescriptor.setWantAssertionsSigned(wantAssertionsSigned);
    spSSODescriptor.addNameIDFormat(nameIDPolicyFormat);
    spSSODescriptor.addSingleLogoutService(new EndpointType(logoutBinding, logoutEndpoint));
    if (wantAuthnRequestsSigned && signingCerts != null) {
        for (Element key : signingCerts) {
            KeyDescriptorType keyDescriptor = new KeyDescriptorType();
            keyDescriptor.setUse(KeyTypes.SIGNING);
            keyDescriptor.setKeyInfo(key);
            spSSODescriptor.addKeyDescriptor(keyDescriptor);
        }
    }
    if (wantAssertionsEncrypted && encryptionCerts != null) {
        for (Element key : encryptionCerts) {
            KeyDescriptorType keyDescriptor = new KeyDescriptorType();
            keyDescriptor.setUse(KeyTypes.ENCRYPTION);
            keyDescriptor.setKeyInfo(key);
            spSSODescriptor.addKeyDescriptor(keyDescriptor);
        }
    }
    IndexedEndpointType assertionConsumerEndpoint = new IndexedEndpointType(loginBinding, assertionEndpoint);
    assertionConsumerEndpoint.setIsDefault(true);
    assertionConsumerEndpoint.setIndex(1);
    spSSODescriptor.addAssertionConsumerService(assertionConsumerEndpoint);
    entityDescriptor.addChoiceType(new EntityDescriptorType.EDTChoiceType(Arrays.asList(new EntityDescriptorType.EDTDescriptorChoiceType(spSSODescriptor))));
    return entityDescriptor;
}
Also used : Element(org.w3c.dom.Element) EndpointType(org.keycloak.dom.saml.v2.metadata.EndpointType) IndexedEndpointType(org.keycloak.dom.saml.v2.metadata.IndexedEndpointType) EntityDescriptorType(org.keycloak.dom.saml.v2.metadata.EntityDescriptorType) KeyDescriptorType(org.keycloak.dom.saml.v2.metadata.KeyDescriptorType) IndexedEndpointType(org.keycloak.dom.saml.v2.metadata.IndexedEndpointType) SPSSODescriptorType(org.keycloak.dom.saml.v2.metadata.SPSSODescriptorType)

Example 14 with SPSSODescriptorType

use of org.keycloak.dom.saml.v2.metadata.SPSSODescriptorType in project keycloak by keycloak.

the class EntityDescriptorDescriptionConverter method getLogoutLocation.

private static String getLogoutLocation(SPSSODescriptorType idp, String bindingURI) {
    String logoutResponseLocation = null;
    List<EndpointType> endpoints = idp.getSingleLogoutService();
    for (EndpointType endpoint : endpoints) {
        if (endpoint.getBinding().toString().equals(bindingURI)) {
            if (endpoint.getLocation() != null) {
                logoutResponseLocation = endpoint.getLocation().toString();
            } else {
                logoutResponseLocation = null;
            }
            break;
        }
    }
    return logoutResponseLocation;
}
Also used : EndpointType(org.keycloak.dom.saml.v2.metadata.EndpointType) IndexedEndpointType(org.keycloak.dom.saml.v2.metadata.IndexedEndpointType)

Example 15 with SPSSODescriptorType

use of org.keycloak.dom.saml.v2.metadata.SPSSODescriptorType in project keycloak by keycloak.

the class SAMLMetadataWriter method write.

public void write(SPSSODescriptorType spSSODescriptor) throws ProcessingException {
    StaxUtil.writeStartElement(writer, METADATA_PREFIX, JBossSAMLConstants.SP_SSO_DESCRIPTOR.get(), JBossSAMLURIConstants.METADATA_NSURI.get());
    writeProtocolSupportEnumeration(spSSODescriptor.getProtocolSupportEnumeration());
    // Write the attributes
    Boolean authnSigned = spSSODescriptor.isAuthnRequestsSigned();
    if (authnSigned != null) {
        StaxUtil.writeAttribute(writer, new QName(JBossSAMLConstants.AUTHN_REQUESTS_SIGNED.get()), authnSigned.toString());
    }
    Boolean wantAssertionsSigned = spSSODescriptor.isWantAssertionsSigned();
    if (wantAssertionsSigned != null) {
        StaxUtil.writeAttribute(writer, new QName(JBossSAMLConstants.WANT_ASSERTIONS_SIGNED.get()), wantAssertionsSigned.toString());
    }
    // Get the key descriptors
    List<KeyDescriptorType> keyDescriptors = spSSODescriptor.getKeyDescriptor();
    for (KeyDescriptorType keyDescriptor : keyDescriptors) {
        writeKeyDescriptor(keyDescriptor);
    }
    List<EndpointType> sloServices = spSSODescriptor.getSingleLogoutService();
    for (EndpointType endpoint : sloServices) {
        writeSingleLogoutService(endpoint);
    }
    List<IndexedEndpointType> artifactResolutions = spSSODescriptor.getArtifactResolutionService();
    for (IndexedEndpointType artifactResolution : artifactResolutions) {
        writeArtifactResolutionService(artifactResolution);
    }
    List<String> nameIDFormats = spSSODescriptor.getNameIDFormat();
    for (String nameIDFormat : nameIDFormats) {
        writeNameIDFormat(nameIDFormat);
    }
    List<IndexedEndpointType> assertionConsumers = spSSODescriptor.getAssertionConsumerService();
    for (IndexedEndpointType assertionConsumer : assertionConsumers) {
        writeAssertionConsumerService(assertionConsumer);
    }
    List<AttributeConsumingServiceType> attributeConsumers = spSSODescriptor.getAttributeConsumingService();
    for (AttributeConsumingServiceType attributeConsumer : attributeConsumers) {
        writeAttributeConsumingService(attributeConsumer);
    }
    StaxUtil.writeEndElement(writer);
    StaxUtil.flush(writer);
}
Also used : QName(javax.xml.namespace.QName) EndpointType(org.keycloak.dom.saml.v2.metadata.EndpointType) IndexedEndpointType(org.keycloak.dom.saml.v2.metadata.IndexedEndpointType) KeyDescriptorType(org.keycloak.dom.saml.v2.metadata.KeyDescriptorType) IndexedEndpointType(org.keycloak.dom.saml.v2.metadata.IndexedEndpointType) AttributeConsumingServiceType(org.keycloak.dom.saml.v2.metadata.AttributeConsumingServiceType)

Aggregations

SPSSODescriptorType (org.keycloak.dom.saml.v2.metadata.SPSSODescriptorType)13 EntityDescriptorType (org.keycloak.dom.saml.v2.metadata.EntityDescriptorType)10 Test (org.junit.Test)7 IndexedEndpointType (org.keycloak.dom.saml.v2.metadata.IndexedEndpointType)7 EndpointType (org.keycloak.dom.saml.v2.metadata.EndpointType)6 SAMLParser (org.keycloak.saml.processing.core.parsers.saml.SAMLParser)6 StringInputStream (org.apache.tools.ant.filters.StringInputStream)5 KeyDescriptorType (org.keycloak.dom.saml.v2.metadata.KeyDescriptorType)5 Closeable (java.io.Closeable)4 IdentityProviderAttributeUpdater (org.keycloak.testsuite.updaters.IdentityProviderAttributeUpdater)4 URI (java.net.URI)3 IdentityProviderMapperRepresentation (org.keycloak.representations.idm.IdentityProviderMapperRepresentation)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 QName (javax.xml.namespace.QName)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 AttributeConsumingServiceType (org.keycloak.dom.saml.v2.metadata.AttributeConsumingServiceType)2 ClientRepresentation (org.keycloak.representations.idm.ClientRepresentation)2 ParsingException (org.keycloak.saml.common.exceptions.ParsingException)2 X509Certificate (java.security.cert.X509Certificate)1