Search in sources :

Example 6 with AttributeConsumingServiceType

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

the class SAMLAttributeConsumingServiceParser method processSubElement.

@Override
protected void processSubElement(XMLEventReader xmlEventReader, AttributeConsumingServiceType target, SAMLMetadataQNames element, StartElement elementDetail) throws ParsingException {
    switch(element) {
        case SERVICE_NAME:
            LocalizedNameType serviceName = new LocalizedNameType(StaxParserUtil.getAttributeValue(elementDetail, ATTR_LANG));
            StaxParserUtil.advance(xmlEventReader);
            serviceName.setValue(StaxParserUtil.getElementText(xmlEventReader));
            target.addServiceName(serviceName);
            break;
        case SERVICE_DESCRIPTION:
            LocalizedNameType serviceDescription = new LocalizedNameType(StaxParserUtil.getAttributeValue(elementDetail, ATTR_LANG));
            StaxParserUtil.advance(xmlEventReader);
            serviceDescription.setValue(StaxParserUtil.getElementText(xmlEventReader));
            target.addServiceDescription(serviceDescription);
            break;
        case REQUESTED_ATTRIBUTE:
            target.addRequestedAttribute(SAMLRequestedAttributeParser.getInstance().parse(xmlEventReader));
            break;
        default:
            throw LOGGER.parserUnknownTag(StaxParserUtil.getElementName(elementDetail), elementDetail.getLocation());
    }
}
Also used : LocalizedNameType(org.keycloak.dom.saml.v2.metadata.LocalizedNameType)

Example 7 with AttributeConsumingServiceType

use of org.keycloak.dom.saml.v2.metadata.AttributeConsumingServiceType 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)

Example 8 with AttributeConsumingServiceType

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

the class SAMLMetadataWriter method writeAttributeConsumingService.

public void writeAttributeConsumingService(AttributeConsumingServiceType attributeConsumer) throws ProcessingException {
    StaxUtil.writeStartElement(writer, METADATA_PREFIX, JBossSAMLConstants.ATTRIBUTE_CONSUMING_SERVICE.get(), JBossSAMLURIConstants.METADATA_NSURI.get());
    if (attributeConsumer.isIsDefault() != null)
        StaxUtil.writeAttribute(writer, JBossSAMLConstants.ISDEFAULT.get(), "" + attributeConsumer.isIsDefault());
    StaxUtil.writeAttribute(writer, JBossSAMLConstants.INDEX.get(), "" + attributeConsumer.getIndex());
    // Service Name
    List<LocalizedNameType> serviceNames = attributeConsumer.getServiceName();
    for (LocalizedNameType serviceName : serviceNames) {
        writeLocalizedNameType(serviceName, new QName(JBossSAMLURIConstants.METADATA_NSURI.get(), JBossSAMLConstants.SERVICE_NAME.get(), METADATA_PREFIX));
    }
    List<LocalizedNameType> serviceDescriptions = attributeConsumer.getServiceDescription();
    for (LocalizedNameType serviceDescription : serviceDescriptions) {
        writeLocalizedNameType(serviceDescription, new QName(JBossSAMLURIConstants.METADATA_NSURI.get(), JBossSAMLConstants.SERVICE_DESCRIPTION.get(), METADATA_PREFIX));
    }
    List<RequestedAttributeType> requestedAttributes = attributeConsumer.getRequestedAttribute();
    for (RequestedAttributeType requestedAttribute : requestedAttributes) {
        StaxUtil.writeStartElement(writer, METADATA_PREFIX, JBossSAMLConstants.REQUESTED_ATTRIBUTE.get(), JBossSAMLURIConstants.METADATA_NSURI.get());
        Boolean isRequired = requestedAttribute.isIsRequired();
        if (isRequired != null) {
            StaxUtil.writeAttribute(writer, new QName(JBossSAMLConstants.IS_REQUIRED.get()), isRequired.toString());
        }
        writeAttributeTypeWithoutRootTag(requestedAttribute);
        StaxUtil.writeEndElement(writer);
    }
    StaxUtil.writeEndElement(writer);
    StaxUtil.flush(writer);
}
Also used : LocalizedNameType(org.keycloak.dom.saml.v2.metadata.LocalizedNameType) QName(javax.xml.namespace.QName) RequestedAttributeType(org.keycloak.dom.saml.v2.metadata.RequestedAttributeType)

Aggregations

AttributeConsumingServiceType (org.keycloak.dom.saml.v2.metadata.AttributeConsumingServiceType)6 EntityDescriptorType (org.keycloak.dom.saml.v2.metadata.EntityDescriptorType)4 LocalizedNameType (org.keycloak.dom.saml.v2.metadata.LocalizedNameType)4 RequestedAttributeType (org.keycloak.dom.saml.v2.metadata.RequestedAttributeType)4 QName (javax.xml.namespace.QName)3 EndpointType (org.keycloak.dom.saml.v2.metadata.EndpointType)2 IndexedEndpointType (org.keycloak.dom.saml.v2.metadata.IndexedEndpointType)2 KeyDescriptorType (org.keycloak.dom.saml.v2.metadata.KeyDescriptorType)2 StringWriter (java.io.StringWriter)1 URI (java.net.URI)1 KeyPair (java.security.KeyPair)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 Entry (java.util.Map.Entry)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 Test (org.junit.Test)1 IdentityBrokerException (org.keycloak.broker.provider.IdentityBrokerException)1 IdentityProviderMapper (org.keycloak.broker.provider.IdentityProviderMapper)1