Search in sources :

Example 6 with SAMLParser

use of org.keycloak.saml.processing.core.parsers.saml.SAMLParser in project keycloak by keycloak.

the class KcSamlSpDescriptorTest method testAttributeConsumingServiceMappersInSpMetadataWithServiceName.

@Test
public void testAttributeConsumingServiceMappersInSpMetadataWithServiceName() throws IOException, ParsingException, URISyntaxException {
    try (Closeable idpUpdater = new IdentityProviderAttributeUpdater(identityProviderResource).setAttribute(SAMLIdentityProviderConfig.ATTRIBUTE_CONSUMING_SERVICE_INDEX, "12").setAttribute(SAMLIdentityProviderConfig.ATTRIBUTE_CONSUMING_SERVICE_NAME, "My Attribute Set").update()) {
        IdentityProviderMapperRepresentation attrMapperEmail = new IdentityProviderMapperRepresentation();
        attrMapperEmail.setName("attribute-mapper-email");
        attrMapperEmail.setIdentityProviderMapper(UserAttributeMapper.PROVIDER_ID);
        attrMapperEmail.setConfig(ImmutableMap.<String, String>builder().put(IdentityProviderMapperModel.SYNC_MODE, IdentityProviderMapperSyncMode.INHERIT.toString()).put(UserAttributeMapper.ATTRIBUTE_NAME, "email_attr_name").put(UserAttributeMapper.ATTRIBUTE_FRIENDLY_NAME, "email_attr_friendlyname").put(UserAttributeMapper.USER_ATTRIBUTE, "email").build());
        attrMapperEmail.setIdentityProviderAlias(bc.getIDPAlias());
        identityProviderResource.addMapper(attrMapperEmail);
        String spDescriptorString = identityProviderResource.export(null).readEntity(String.class);
        SAMLParser parser = SAMLParser.getInstance();
        EntityDescriptorType o = (EntityDescriptorType) parser.parse(new StringInputStream(spDescriptorString));
        SPSSODescriptorType spDescriptor = o.getChoiceType().get(0).getDescriptors().get(0).getSpDescriptor();
        assertThat(spDescriptor.getAttributeConsumingService(), not(empty()));
        assertThat(spDescriptor.getAttributeConsumingService().get(0).getIndex(), is(12));
        assertThat(spDescriptor.getAttributeConsumingService().get(0).getRequestedAttribute(), notNullValue());
        assertThat(spDescriptor.getAttributeConsumingService().get(0).getRequestedAttribute(), not(empty()));
        assertThat(spDescriptor.getAttributeConsumingService().get(0).getRequestedAttribute().get(0).getName(), is("email_attr_name"));
        assertThat(spDescriptor.getAttributeConsumingService().get(0).getRequestedAttribute().get(0).getFriendlyName(), is("email_attr_friendlyname"));
        assertThat(spDescriptor.getAttributeConsumingService().get(0).getServiceName(), notNullValue());
        assertThat(spDescriptor.getAttributeConsumingService().get(0).getServiceName().get(0).getValue(), is("My Attribute Set"));
    }
}
Also used : IdentityProviderMapperRepresentation(org.keycloak.representations.idm.IdentityProviderMapperRepresentation) StringInputStream(org.apache.tools.ant.filters.StringInputStream) Closeable(java.io.Closeable) IdentityProviderAttributeUpdater(org.keycloak.testsuite.updaters.IdentityProviderAttributeUpdater) SAMLParser(org.keycloak.saml.processing.core.parsers.saml.SAMLParser) EntityDescriptorType(org.keycloak.dom.saml.v2.metadata.EntityDescriptorType) SPSSODescriptorType(org.keycloak.dom.saml.v2.metadata.SPSSODescriptorType) Test(org.junit.Test)

Example 7 with SAMLParser

use of org.keycloak.saml.processing.core.parsers.saml.SAMLParser in project keycloak by keycloak.

the class SamlUtils method getSPInstallationDescriptor.

public static SPSSODescriptorType getSPInstallationDescriptor(ClientsResource res, String clientId) throws ParsingException {
    String spDescriptorString = res.findByClientId(clientId).stream().findFirst().map(ClientRepresentation::getId).map(res::get).map(clientResource -> clientResource.getInstallationProvider(SamlSPDescriptorClientInstallation.SAML_CLIENT_INSTALATION_SP_DESCRIPTOR)).orElseThrow(() -> new RuntimeException("Missing descriptor"));
    SAMLParser parser = SAMLParser.getInstance();
    EntityDescriptorType o = (EntityDescriptorType) parser.parse(new StringInputStream(spDescriptorString));
    return o.getChoiceType().get(0).getDescriptors().get(0).getSpDescriptor();
}
Also used : SAMLParser(org.keycloak.saml.processing.core.parsers.saml.SAMLParser) DeploymentArchiveProcessorUtils(org.keycloak.testsuite.utils.arquillian.DeploymentArchiveProcessorUtils) SPSSODescriptorType(org.keycloak.dom.saml.v2.metadata.SPSSODescriptorType) DeploymentBuilder(org.keycloak.adapters.saml.config.parsers.DeploymentBuilder) EntityDescriptorType(org.keycloak.dom.saml.v2.metadata.EntityDescriptorType) IOUtil(org.keycloak.testsuite.utils.io.IOUtil) ClientRepresentation(org.keycloak.representations.idm.ClientRepresentation) ParsingException(org.keycloak.saml.common.exceptions.ParsingException) SamlSPDescriptorClientInstallation(org.keycloak.protocol.saml.installation.SamlSPDescriptorClientInstallation) ClientsResource(org.keycloak.admin.client.resource.ClientsResource) SamlDeployment(org.keycloak.adapters.saml.SamlDeployment) Document(org.w3c.dom.Document) StringInputStream(org.apache.tools.ant.filters.StringInputStream) ResourceLoader(org.keycloak.adapters.saml.config.parsers.ResourceLoader) InputStream(java.io.InputStream) StringInputStream(org.apache.tools.ant.filters.StringInputStream) SAMLParser(org.keycloak.saml.processing.core.parsers.saml.SAMLParser) EntityDescriptorType(org.keycloak.dom.saml.v2.metadata.EntityDescriptorType)

Example 8 with SAMLParser

use of org.keycloak.saml.processing.core.parsers.saml.SAMLParser in project keycloak by keycloak.

the class SAML2Request method getSAML2ObjectFromDocument.

/**
 * Get the Underlying SAML2Object from a document
 * @param samlDocument a Document containing a SAML2Object
 * @return a SAMLDocumentHolder
 * @throws ProcessingException
 * @throws ParsingException
 */
public static SAMLDocumentHolder getSAML2ObjectFromDocument(Document samlDocument) throws ProcessingException, ParsingException {
    SAMLParser samlParser = SAMLParser.getInstance();
    JAXPValidationUtil.checkSchemaValidation(samlDocument);
    SAML2Object requestType = (SAML2Object) samlParser.parse(samlDocument);
    return new SAMLDocumentHolder(requestType, samlDocument);
}
Also used : SAML2Object(org.keycloak.dom.saml.v2.SAML2Object) SAMLDocumentHolder(org.keycloak.saml.processing.core.saml.v2.common.SAMLDocumentHolder) SAMLParser(org.keycloak.saml.processing.core.parsers.saml.SAMLParser)

Example 9 with SAMLParser

use of org.keycloak.saml.processing.core.parsers.saml.SAMLParser in project keycloak by keycloak.

the class SAML2Request method getAuthnRequestType.

/**
 * Get the AuthnRequestType from an input stream
 *
 * @param is Inputstream containing the AuthnRequest
 *
 * @return
 *
 * @throws ParsingException
 * @throws ProcessingException
 * @throws ConfigurationException
 * @throws IllegalArgumentException inputstream is null
 */
public AuthnRequestType getAuthnRequestType(InputStream is) throws ConfigurationException, ProcessingException, ParsingException {
    if (is == null)
        throw logger.nullArgumentError("InputStream");
    Document samlDocument = DocumentUtil.getDocument(is);
    SAMLParser samlParser = SAMLParser.getInstance();
    JAXPValidationUtil.checkSchemaValidation(samlDocument);
    AuthnRequestType requestType = (AuthnRequestType) samlParser.parse(samlDocument);
    samlDocumentHolder = new SAMLDocumentHolder(requestType, samlDocument);
    return requestType;
}
Also used : SAMLDocumentHolder(org.keycloak.saml.processing.core.saml.v2.common.SAMLDocumentHolder) AuthnRequestType(org.keycloak.dom.saml.v2.protocol.AuthnRequestType) SAMLParser(org.keycloak.saml.processing.core.parsers.saml.SAMLParser) Document(org.w3c.dom.Document)

Example 10 with SAMLParser

use of org.keycloak.saml.processing.core.parsers.saml.SAMLParser in project keycloak by keycloak.

the class SAML2Request method getRequestType.

/**
 * Get a Request Type from Input Stream
 *
 * @param is
 *
 * @return
 *
 * @throws ProcessingException
 * @throws ConfigurationException
 * @throws
 * @throws IllegalArgumentException inputstream is null
 */
public RequestAbstractType getRequestType(InputStream is) throws ParsingException, ConfigurationException, ProcessingException {
    if (is == null)
        throw logger.nullArgumentError("InputStream");
    Document samlDocument = DocumentUtil.getDocument(is);
    SAMLParser samlParser = SAMLParser.getInstance();
    JAXPValidationUtil.checkSchemaValidation(samlDocument);
    RequestAbstractType requestType = (RequestAbstractType) samlParser.parse(samlDocument);
    samlDocumentHolder = new SAMLDocumentHolder(requestType, samlDocument);
    return requestType;
}
Also used : SAMLDocumentHolder(org.keycloak.saml.processing.core.saml.v2.common.SAMLDocumentHolder) RequestAbstractType(org.keycloak.dom.saml.v2.protocol.RequestAbstractType) SAMLParser(org.keycloak.saml.processing.core.parsers.saml.SAMLParser) Document(org.w3c.dom.Document)

Aggregations

SAMLParser (org.keycloak.saml.processing.core.parsers.saml.SAMLParser)15 Document (org.w3c.dom.Document)8 Test (org.junit.Test)6 StringInputStream (org.apache.tools.ant.filters.StringInputStream)5 EntityDescriptorType (org.keycloak.dom.saml.v2.metadata.EntityDescriptorType)5 SPSSODescriptorType (org.keycloak.dom.saml.v2.metadata.SPSSODescriptorType)5 SAMLDocumentHolder (org.keycloak.saml.processing.core.saml.v2.common.SAMLDocumentHolder)5 Closeable (java.io.Closeable)4 AssertionType (org.keycloak.dom.saml.v2.assertion.AssertionType)4 ResponseType (org.keycloak.dom.saml.v2.protocol.ResponseType)4 IdentityProviderAttributeUpdater (org.keycloak.testsuite.updaters.IdentityProviderAttributeUpdater)4 InputStream (java.io.InputStream)3 EncryptedAssertionType (org.keycloak.dom.saml.v2.assertion.EncryptedAssertionType)3 IdentityProviderMapperRepresentation (org.keycloak.representations.idm.IdentityProviderMapperRepresentation)3 SAMLDataMarshaller (org.keycloak.broker.saml.SAMLDataMarshaller)2 SAML2Object (org.keycloak.dom.saml.v2.SAML2Object)2 QName (javax.xml.namespace.QName)1 SamlDeployment (org.keycloak.adapters.saml.SamlDeployment)1 DeploymentBuilder (org.keycloak.adapters.saml.config.parsers.DeploymentBuilder)1 ResourceLoader (org.keycloak.adapters.saml.config.parsers.ResourceLoader)1