Search in sources :

Example 21 with EntityDescriptorType

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

the class SAMLParserTest method testSaml20MetadataEntityDescriptorAuthnAuthority.

@Test
public void testSaml20MetadataEntityDescriptorAuthnAuthority() throws Exception {
    EntityDescriptorType descriptor = assertParsed("saml20-entity-descriptor-authn-authority.xml", EntityDescriptorType.class);
    assertThat(descriptor.getChoiceType(), Matchers.<EntityDescriptorType.EDTChoiceType>hasSize(1));
    assertThat(descriptor.getChoiceType().get(0).getDescriptors().get(0).getAuthnDescriptor(), is(notNullValue()));
    AuthnAuthorityDescriptorType authnDescriptor = descriptor.getChoiceType().get(0).getDescriptors().get(0).getAuthnDescriptor();
    assertThat(authnDescriptor.getAssertionIDRequestService(), hasSize(1));
    assertThat(authnDescriptor.getAuthnQueryService(), hasSize(1));
    assertThat(authnDescriptor.getProtocolSupportEnumeration(), containsInAnyOrder("http://www.example.com/", "http://www.example2.com/"));
}
Also used : AuthnAuthorityDescriptorType(org.keycloak.dom.saml.v2.metadata.AuthnAuthorityDescriptorType) EntityDescriptorType(org.keycloak.dom.saml.v2.metadata.EntityDescriptorType) Test(org.junit.Test)

Example 22 with EntityDescriptorType

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

the class SAMLParserTest method testSaml20MetadataEntityDescriptorPDP.

@Test
public void testSaml20MetadataEntityDescriptorPDP() throws Exception {
    EntityDescriptorType descriptor = assertParsed("saml20-entity-descriptor-pdp.xml", EntityDescriptorType.class);
    assertThat(descriptor.getChoiceType(), Matchers.<EntityDescriptorType.EDTChoiceType>hasSize(1));
    assertThat(descriptor.getChoiceType().get(0).getDescriptors().get(0).getPdpDescriptor(), is(notNullValue()));
    PDPDescriptorType pdpDescriptor = descriptor.getChoiceType().get(0).getDescriptors().get(0).getPdpDescriptor();
    assertThat(pdpDescriptor.getKeyDescriptor(), Matchers.<KeyDescriptorType>hasSize(1));
    KeyDescriptorType keyDescriptorType = pdpDescriptor.getKeyDescriptor().get(0);
    assertThat(keyDescriptorType.getEncryptionMethod(), Matchers.<EncryptionMethodType>hasSize(1));
    EncryptionMethodType encryptionMethodType = keyDescriptorType.getEncryptionMethod().get(0);
    assertThat(encryptionMethodType.getAlgorithm(), is("http://www.example.com/"));
    EncryptionMethodType.EncryptionMethod encryptionMethod = encryptionMethodType.getEncryptionMethod();
    assertThat(encryptionMethod.getKeySize(), is(BigInteger.ONE));
    assertThat(encryptionMethod.getOAEPparams(), is("GpM7".getBytes()));
    // EndpointType parser already tested so we are not checking further
    assertThat(pdpDescriptor.getAuthzService(), Matchers.<EndpointType>hasSize(1));
    assertThat(pdpDescriptor.getAssertionIDRequestService(), Matchers.<EndpointType>hasSize(1));
}
Also used : PDPDescriptorType(org.keycloak.dom.saml.v2.metadata.PDPDescriptorType) EncryptionMethodType(org.keycloak.dom.xmlsec.w3.xmlenc.EncryptionMethodType) EntityDescriptorType(org.keycloak.dom.saml.v2.metadata.EntityDescriptorType) KeyDescriptorType(org.keycloak.dom.saml.v2.metadata.KeyDescriptorType) Test(org.junit.Test)

Example 23 with EntityDescriptorType

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

the class KcSamlSpDescriptorTest method testAttributeConsumingServiceMappersInSpMetadataWithoutServiceName.

@Test
public void testAttributeConsumingServiceMappersInSpMetadataWithoutServiceName() throws IOException, ParsingException, URISyntaxException {
    try (Closeable idpUpdater = new IdentityProviderAttributeUpdater(identityProviderResource).setAttribute(SAMLIdentityProviderConfig.ATTRIBUTE_CONSUMING_SERVICE_INDEX, "12").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(bc.consumerRealmName()));
    }
}
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)

Aggregations

EntityDescriptorType (org.keycloak.dom.saml.v2.metadata.EntityDescriptorType)23 SPSSODescriptorType (org.keycloak.dom.saml.v2.metadata.SPSSODescriptorType)10 Test (org.junit.Test)9 EndpointType (org.keycloak.dom.saml.v2.metadata.EndpointType)9 KeyDescriptorType (org.keycloak.dom.saml.v2.metadata.KeyDescriptorType)9 IndexedEndpointType (org.keycloak.dom.saml.v2.metadata.IndexedEndpointType)7 Element (org.w3c.dom.Element)7 SAMLParser (org.keycloak.saml.processing.core.parsers.saml.SAMLParser)6 StringInputStream (org.apache.tools.ant.filters.StringInputStream)5 IDPSSODescriptorType (org.keycloak.dom.saml.v2.metadata.IDPSSODescriptorType)5 RequestedAttributeType (org.keycloak.dom.saml.v2.metadata.RequestedAttributeType)5 Closeable (java.io.Closeable)4 QName (javax.xml.namespace.QName)4 Matchers.containsString (org.hamcrest.Matchers.containsString)4 AttributeConsumingServiceType (org.keycloak.dom.saml.v2.metadata.AttributeConsumingServiceType)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 StringWriter (java.io.StringWriter)3 URI (java.net.URI)3 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)3 AttributeType (org.keycloak.dom.saml.v2.assertion.AttributeType)3