Class ExtendedAuthnRequestBuilder
- java.lang.Object
-
- se.litsec.opensaml.core.AbstractSAMLObjectBuilder<T>
-
- se.litsec.opensaml.saml2.core.build.AbstractRequestBuilder<AuthnRequest,BUILDER>
-
- se.litsec.opensaml.saml2.core.build.AbstractAuthnRequestBuilder<ExtendedAuthnRequestBuilder>
-
- se.litsec.opensaml.saml2.authentication.build.ExtendedAuthnRequestBuilder
-
- All Implemented Interfaces:
SAMLObjectBuilder<AuthnRequest>
public class ExtendedAuthnRequestBuilder extends AbstractAuthnRequestBuilder<ExtendedAuthnRequestBuilder>
TheExtendedAuthnRequestBuilderbuilds anAuthnRequestobject given the metadata entry for the Service Provider that sends the request and the metadata entry for the Identity Provider that is the recipient of the request.The purpose with this builder is that the caller does not have to go through the SP and IdP metadata and create a valid
AuthnRequest. By invokingassignDefaults()theAuthnRequestis built using values found in the metadata entries. Any particular settings that are non-default should be assigned using the builder's assigment methods, either before or after invokingassignDefaults(). The builder will assume that the "HTTP-Redirect" binding is used to send the request to the IdP (given that the IdP has an endpoint for this binding). Should the caller want to use another binding (POST), thebinding(String)should be invoked before callingassignDefaults().- Author:
- Martin Lindström (martin.lindstrom@litsec.se)
-
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_ID_SIZEIf an ID attribute is generated by the builder it uses 24 characters for it.static StringDEFAULT_REQUEST_BINDINGIf no binding for how the request is to be passed to the IdP we assumeSAMLConstants.SAML2_REDIRECT_BINDING_URI.
-
Constructor Summary
Constructors Constructor Description ExtendedAuthnRequestBuilder(EntityDescriptor spMetadata, EntityDescriptor idpMetadata)Constructor initializing the builder with the metadata entry for the Service Provider that is creating the authentication request and the metadata entry for the Identity Provider which is about to receive the request.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ExtendedAuthnRequestBuilderassignDefaults()Calculates values based on the SP and IdP metadata and assigns them to theAuthnRequest.ExtendedAuthnRequestBuilderauthnContextClassRefs(boolean onlyMatching, boolean failOnNoMatch, String... uris)ExtendedAuthnRequestBuilderauthnContextClassRefs(boolean onlyMatching, boolean failOnNoMatch, List<String> uris)A utility method that helps adding one or more Authentication context class reference URI(s) to theRequestedAuthnContextelement.Stringbinding()Returns the binding URI to be used to this request, i.e., should the request be redirected to the IdP or should it be posted?ExtendedAuthnRequestBuilderbinding(String binding)Assigns the URI that tells which binding (method) to use when transfering the AuthnRequest to the IdP.ExtendedAuthnRequestBuilderdestination(String destination)Assigns theDestinationattribute and also updates the binding to use based on which of the IdPSingleSignServiceelements that match the supplied destination value.protected ExtendedAuthnRequestBuildergetThis()In order for us to be able to make chaining calls we need to return the concrete type of the builder.ExtendedAuthnRequestBuilderid(int idSize)Generates an identifier of sizeidSizeand assigns it to theAuthnRequest.ExtendedAuthnRequestBuildernameIDPolicyFormat(String format)Assigns aNameIDPolicyelement with theFormatattribute assigned toformatand itsAllowCreateattribute set totrue.-
Methods inherited from class se.litsec.opensaml.saml2.core.build.AbstractAuthnRequestBuilder
assertionConsumerServiceIndex, assertionConsumerServiceURL, attributeConsumerServiceIndex, build, conditions, forceAuthn, getObjectType, isPassive, nameIDPolicy, postProtocolBinding, protocolBinding, providerName, requestedAuthnContext, scoping, subject
-
Methods inherited from class se.litsec.opensaml.saml2.core.build.AbstractRequestBuilder
consent, extensions, id, issueInstant, issuer, issuer, version, version
-
Methods inherited from class se.litsec.opensaml.core.AbstractSAMLObjectBuilder
getDefaultElementName, object
-
-
-
-
Field Detail
-
DEFAULT_REQUEST_BINDING
public static final String DEFAULT_REQUEST_BINDING
If no binding for how the request is to be passed to the IdP we assumeSAMLConstants.SAML2_REDIRECT_BINDING_URI.- See Also:
- Constant Field Values
-
DEFAULT_ID_SIZE
public static final int DEFAULT_ID_SIZE
If an ID attribute is generated by the builder it uses 24 characters for it.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
ExtendedAuthnRequestBuilder
public ExtendedAuthnRequestBuilder(EntityDescriptor spMetadata, EntityDescriptor idpMetadata)
Constructor initializing the builder with the metadata entry for the Service Provider that is creating the authentication request and the metadata entry for the Identity Provider which is about to receive the request.- Parameters:
spMetadata- the SP metadataidpMetadata- the IdP metadata
-
-
Method Detail
-
assignDefaults
public ExtendedAuthnRequestBuilder assignDefaults()
Calculates values based on the SP and IdP metadata and assigns them to theAuthnRequest. The following rules are automatically applied by theassignDefaults()method:- The version is set to 2.0.
- An ID attribute is generated and assigned.
- The
ProtocolBindingis assigned to HTTP-POST. - The
Destinationattribute is assigned the value found in the IdP metadata'sSingleSignOnServiceelement having a binding matching the binding that was assigned this builder. - The
Issuerelement is assigned the entityID found in the SP metadata. - The
NameIDPolicyelement is assigned by iterating over the declaredNameIDFormatelements of the SP metadata and using the first format that is also declared by the IdP. TheAllowCreateis set totrue.
- Returns:
- the builder
-
id
public ExtendedAuthnRequestBuilder id(int idSize)
Generates an identifier of sizeidSizeand assigns it to theAuthnRequest.- Parameters:
idSize- the number of characters to be used in the ID- Returns:
- the builder
-
destination
public ExtendedAuthnRequestBuilder destination(String destination)
Assigns theDestinationattribute and also updates the binding to use based on which of the IdPSingleSignServiceelements that match the supplied destination value.Using this builder it is not recommended to assign the
Destinationattribute. Instead assign the desired binding (binding(String)) and theDestinationattribute will be automatically assigned.- Overrides:
destinationin classAbstractRequestBuilder<AuthnRequest,ExtendedAuthnRequestBuilder>- Parameters:
destination- the destination URI- Returns:
- the builder
- See Also:
binding(String)
-
binding
public String binding()
Returns the binding URI to be used to this request, i.e., should the request be redirected to the IdP or should it be posted?The setting controls how the AuthnRequest is put together and which data that is read from the IdP metadata.
- Returns:
- the binding URI
-
binding
public ExtendedAuthnRequestBuilder binding(String binding) throws SAMLObjectBuilderRuntimeException
Assigns the URI that tells which binding (method) to use when transfering the AuthnRequest to the IdP.The setting controls how the
AuthnRequestis put together and which data that is read from the IdP metadata. More specifically it assigns theDestinationattribute to the address found in the IdPSingleSignOnServiceelement having this binding.- Parameters:
binding- the binding URI- Returns:
- the builder
- Throws:
SAMLObjectBuilderRuntimeException- is thrown if the IdP metadata does not define aSingleSignOnServiceelement having the given binding, which means that it does not support it, and it it thus meaningless to send this request using this binding
-
nameIDPolicyFormat
public ExtendedAuthnRequestBuilder nameIDPolicyFormat(String format) throws SAMLObjectBuilderRuntimeException
Assigns aNameIDPolicyelement with theFormatattribute assigned toformatand itsAllowCreateattribute set totrue.- Parameters:
format- the format to assign- Returns:
- the builder
- Throws:
SAMLObjectBuilderRuntimeException- if the IdP's metadata entry does not list the supplied format as supported
-
authnContextClassRefs
public ExtendedAuthnRequestBuilder authnContextClassRefs(boolean onlyMatching, boolean failOnNoMatch, List<String> uris) throws SAMLObjectBuilderRuntimeException
A utility method that helps adding one or more Authentication context class reference URI(s) to theRequestedAuthnContextelement. The method will read the IdP's declared assuranceCertification URIs from its metadata.- Parameters:
onlyMatching- only add URIs that are also declared by the IdP in its metadatafailOnNoMatch- throw if none of our given URIs are declared by the IdPuris- the URIs to add- Returns:
- the builder
- Throws:
SAMLObjectBuilderRuntimeException- is thrown iffailOnNoMatchis set and we don't get a match between given URIs and declared URIs
-
authnContextClassRefs
public ExtendedAuthnRequestBuilder authnContextClassRefs(boolean onlyMatching, boolean failOnNoMatch, String... uris) throws SAMLObjectBuilderRuntimeException
- Parameters:
onlyMatching- only add URIs that are also declared by the IdP in its metadatafailOnNoMatch- throw if none of our given URIs are declared by the IdPuris- the URIs to add- Returns:
- the builder
- Throws:
SAMLObjectBuilderRuntimeException- is thrown iffailOnNoMatchis set and we don't get a match between given URIs and declared URIs- See Also:
authnContextClassRefs(boolean, boolean, List)
-
getThis
protected ExtendedAuthnRequestBuilder getThis()
In order for us to be able to make chaining calls we need to return the concrete type of the builder.- Specified by:
getThisin classAbstractRequestBuilder<AuthnRequest,ExtendedAuthnRequestBuilder>- Returns:
- the concrete type of the builder
-
-