Package com.coveo.saml
Class SamlClient
java.lang.Object
com.coveo.saml.SamlClient
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionSamlClient(String relyingPartyIdentifier, String assertionConsumerServiceUrl, String identityProviderUrl, String responseIssuer, X509Certificate certificate) Constructs an SAML client using explicit parameters.SamlClient(String relyingPartyIdentifier, String assertionConsumerServiceUrl, String identityProviderUrl, String responseIssuer, List<X509Certificate> certificates) Constructs an SAML client using explicit parameters.SamlClient(String relyingPartyIdentifier, String assertionConsumerServiceUrl, String identityProviderUrl, String responseIssuer, List<X509Certificate> certificates, SamlClient.SamlIdpBinding samlBinding) Constructs an SAML client using explicit parameters. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddAdditionalSPKey(String publicKey, String privateKey) Add an additional service provider certificate/key pair for decryption.voidaddAdditionalSPKey(X509Certificate certificate, PrivateKey privateKey) Add an additional service provider certificate/key pair for decryption.voidRemove all additional service provider decryption certificate/key pairs.voiddecodeAndValidateSamlLogoutRequest(String encodedRequest, String nameID, String method) Decodes and validates an SAML logout request send by an identity provider.decodeAndValidateSamlLogoutResponse(String encodedResponse, String method) Decodes and validates an SAML response returned by an identity provider.decodeAndValidateSamlResponse(String encodedResponse, String method) Decodes and validates an SAML response returned by an identity provider.static SamlClientfromMetadata(String relyingPartyIdentifier, String assertionConsumerServiceUrl, Reader metadata) Constructs an SAML client using XML metadata obtained from the identity provider.static SamlClientfromMetadata(String relyingPartyIdentifier, String assertionConsumerServiceUrl, Reader metadata, SamlClient.SamlIdpBinding samlBinding) Constructs an SAML client using XML metadata obtained from the identity provider.static SamlClientfromMetadata(String relyingPartyIdentifier, String assertionConsumerServiceUrl, Reader metadata, SamlClient.SamlIdpBinding samlBinding, List<X509Certificate> certificates) Constructs an SAML client using XML metadata obtained from the identity provider.getAttributes(SamlResponse response) Gets attributes from the IDP ResponseReturns the url where SAML requests should be posted.getLogoutRequest(String nameId) Gets the encoded logout request.getSamlLogoutResponse(String status) Gets saml logout response.getSamlLogoutResponse(String status, String statMsg) Gets saml logout response.Builds an encoded SAML request.voidprocessLogoutRequestPostFromIdentityProvider(jakarta.servlet.http.HttpServletRequest request, String nameID) Processes a POST containing the SAML logout request.processPostFromIdentityProvider(jakarta.servlet.http.HttpServletRequest request) Processes a POST containing the SAML response.processPostLogoutResponseFromIdentityProvider(jakarta.servlet.http.HttpServletRequest request) Processes a POST containing the SAML response.voidredirectToIdentityProvider(jakarta.servlet.http.HttpServletResponse response, String relayState) Redirects anHttpServletResponseto the configured identity provider.voidredirectToIdentityProvider(jakarta.servlet.http.HttpServletResponse response, String relayState, String nameId) Redirects anHttpServletResponseto the configured identity provider.voidredirectToIdentityProviderLogout(jakarta.servlet.http.HttpServletResponse response, String statusCode, String statMsg) Redirect to identity provider logout.voidsetInstantNow(Instant now) Sets the date that will be considered as now.voidsetNotBeforeSkew(long notBeforeSkew) Sets by how much the current time can be before the assertion's notBefore.voidSet service provider keys.voidsetSPKeys(X509Certificate certificate, PrivateKey privateKey) Set service provider keys.
-
Constructor Details
-
SamlClient
public SamlClient(String relyingPartyIdentifier, String assertionConsumerServiceUrl, String identityProviderUrl, String responseIssuer, List<X509Certificate> certificates, SamlClient.SamlIdpBinding samlBinding) throws SamlException Constructs an SAML client using explicit parameters.- Parameters:
relyingPartyIdentifier- the identifier of the relying party.assertionConsumerServiceUrl- the url where the identity provider will post back the SAML response.identityProviderUrl- the url where the SAML request will be submitted.responseIssuer- the expected issuer ID for SAML responses.certificates- the list of base-64 encoded certificates to use to validate responses.samlBinding- what type of SAML binding should the client use.- Throws:
SamlException- thrown if any error occur while loading the provider information.
-
SamlClient
public SamlClient(String relyingPartyIdentifier, String assertionConsumerServiceUrl, String identityProviderUrl, String responseIssuer, List<X509Certificate> certificates) throws SamlException Constructs an SAML client using explicit parameters.- Parameters:
relyingPartyIdentifier- the identifier of the relying party.assertionConsumerServiceUrl- the url where the identity provider will post back the SAML response.identityProviderUrl- the url where the SAML request will be submitted.responseIssuer- the expected issuer ID for SAML responses.certificates- the list of base-64 encoded certificates to use to validate responses.- Throws:
SamlException- thrown if any error occur while loading the provider information.
-
SamlClient
public SamlClient(String relyingPartyIdentifier, String assertionConsumerServiceUrl, String identityProviderUrl, String responseIssuer, X509Certificate certificate) throws SamlException Constructs an SAML client using explicit parameters.- Parameters:
relyingPartyIdentifier- the identifier of the relying party.assertionConsumerServiceUrl- the url where the identity provider will post back the SAML response.identityProviderUrl- the url where the SAML request will be submitted.responseIssuer- the expected issuer ID for SAML responses.certificate- the base-64 encoded certificate to use to validate responses.- Throws:
SamlException- thrown if any error occur while loading the provider information.
-
-
Method Details
-
getIdentityProviderUrl
Returns the url where SAML requests should be posted.- Returns:
- the url where SAML requests should be posted.
-
setInstantNow
Sets the date that will be considered as now. This is only useful for testing.- Parameters:
now- the date to use for now.
-
setNotBeforeSkew
public void setNotBeforeSkew(long notBeforeSkew) Sets by how much the current time can be before the assertion's notBefore. Used to mitigate clock differences between the identity provider and relying party.- Parameters:
notBeforeSkew- non-negative amount of skew (in milliseconds) to allow between the current time and the assertion's notBefore date. Default: 0
-
decodeAndValidateSamlResponse
public SamlResponse decodeAndValidateSamlResponse(String encodedResponse, String method) throws SamlException Decodes and validates an SAML response returned by an identity provider.- Parameters:
encodedResponse- the encoded response returned by the identity provider.method- The HTTP method used by the request- Returns:
- An
SamlResponseobject containing information decoded from the SAML response. - Throws:
SamlException- if the signature is invalid, or if any other error occurs.
-
redirectToIdentityProvider
public void redirectToIdentityProvider(jakarta.servlet.http.HttpServletResponse response, String relayState) throws IOException, SamlException Redirects anHttpServletResponseto the configured identity provider.- Parameters:
response- TheHttpServletResponse.relayState- Optional relay state that will be passed along.- Throws:
IOException- thrown if an IO error occurs.SamlException- thrown is an unexpected error occurs.
-
processPostFromIdentityProvider
public SamlResponse processPostFromIdentityProvider(jakarta.servlet.http.HttpServletRequest request) throws SamlException Processes a POST containing the SAML response.- Parameters:
request- theHttpServletRequest.- Returns:
- An
SamlResponseobject containing information decoded from the SAML response. - Throws:
SamlException- thrown is an unexpected error occurs.
-
fromMetadata
public static SamlClient fromMetadata(String relyingPartyIdentifier, String assertionConsumerServiceUrl, Reader metadata) throws SamlException Constructs an SAML client using XML metadata obtained from the identity provider.When using Okta as an identity provider, it is possible to pass null to relyingPartyIdentifier and assertionConsumerServiceUrl; they will be inferred from the metadata provider XML.
- Parameters:
relyingPartyIdentifier- the identifier for the relying party.assertionConsumerServiceUrl- the url where the identity provider will post back the SAML response.metadata- the XML metadata obtained from the identity provider.- Returns:
- The created
SamlClient. - Throws:
SamlException- thrown if any error occur while loading the metadata information.
-
fromMetadata
public static SamlClient fromMetadata(String relyingPartyIdentifier, String assertionConsumerServiceUrl, Reader metadata, SamlClient.SamlIdpBinding samlBinding) throws SamlException Constructs an SAML client using XML metadata obtained from the identity provider.When using Okta as an identity provider, it is possible to pass null to relyingPartyIdentifier and assertionConsumerServiceUrl; they will be inferred from the metadata provider XML.
- Parameters:
relyingPartyIdentifier- the identifier for the relying party.assertionConsumerServiceUrl- the url where the identity provider will post back the SAML response.metadata- the XML metadata obtained from the identity provider.samlBinding- the HTTP method to use for binding to the IdP.- Returns:
- The created
SamlClient. - Throws:
SamlException- thrown if any error occur while loading the metadata information.
-
fromMetadata
public static SamlClient fromMetadata(String relyingPartyIdentifier, String assertionConsumerServiceUrl, Reader metadata, SamlClient.SamlIdpBinding samlBinding, List<X509Certificate> certificates) throws SamlException Constructs an SAML client using XML metadata obtained from the identity provider.When using Okta as an identity provider, it is possible to pass null to relyingPartyIdentifier and assertionConsumerServiceUrl; they will be inferred from the metadata provider XML.
- Parameters:
relyingPartyIdentifier- the identifier for the relying party.assertionConsumerServiceUrl- the url where the identity provider will post back the SAML response.metadata- the XML metadata obtained from the identity provider.samlBinding- the HTTP method to use for binding to the IdP.certificates- list of certificates.- Returns:
- The created
SamlClient. - Throws:
SamlException- thrown if any error occur while loading the metadata information.
-
decodeAndValidateSamlLogoutResponse
public SamlLogoutResponse decodeAndValidateSamlLogoutResponse(String encodedResponse, String method) throws SamlException Decodes and validates an SAML response returned by an identity provider.- Parameters:
encodedResponse- the encoded response returned by the identity provider.method- The HTTP method used by the request- Returns:
- An
SamlResponseobject containing information decoded from the SAML response. - Throws:
SamlException- if the signature is invalid, or if any other error occurs.
-
decodeAndValidateSamlLogoutRequest
public void decodeAndValidateSamlLogoutRequest(String encodedRequest, String nameID, String method) throws SamlException Decodes and validates an SAML logout request send by an identity provider.- Parameters:
encodedRequest- the encoded request send by the identity provider.nameID- The user to logoutmethod- The HTTP method used by the request- Throws:
SamlException- if the signature is invalid, or if any other error occurs.
-
setSPKeys
Set service provider keys.- Parameters:
publicKey- the public keyprivateKey- the private key- Throws:
SamlException- if publicKey and privateKey don't form a valid credential
-
setSPKeys
Set service provider keys.- Parameters:
certificate- the certificateprivateKey- the private key- Throws:
SamlException- if publicKey and privateKey don't form a valid credential
-
addAdditionalSPKey
Add an additional service provider certificate/key pair for decryption.- Parameters:
publicKey- the public keyprivateKey- the private key- Throws:
SamlException- if publicKey and privateKey don't form a valid credential
-
addAdditionalSPKey
Add an additional service provider certificate/key pair for decryption.- Parameters:
certificate- the certificateprivateKey- the private key
-
clearAdditionalSPKeys
public void clearAdditionalSPKeys()Remove all additional service provider decryption certificate/key pairs. -
getAttributes
Gets attributes from the IDP Response- Parameters:
response- the response- Returns:
- the attributes
-
getSamlRequest
Builds an encoded SAML request.- Returns:
- The base-64 encoded SAML request.
- Throws:
SamlException- thrown if an unexpected error occurs.
-
getLogoutRequest
Gets the encoded logout request.- Parameters:
nameId- the name id- Returns:
- the logout request
- Throws:
SamlException- the saml exception
-
getSamlLogoutResponse
Gets saml logout response.- Parameters:
status- the status code @See StatusCode.java- Returns:
- saml logout response
- Throws:
SamlException- the saml exception
-
getSamlLogoutResponse
Gets saml logout response.- Parameters:
status- the status code @See StatusCode.javastatMsg- the status message- Returns:
- saml logout response
- Throws:
SamlException- the saml exception
-
processLogoutRequestPostFromIdentityProvider
public void processLogoutRequestPostFromIdentityProvider(jakarta.servlet.http.HttpServletRequest request, String nameID) throws SamlException Processes a POST containing the SAML logout request.- Parameters:
request- theHttpServletRequest.nameID- the user to log out.- Throws:
SamlException- thrown is an unexpected error occurs.
-
processPostLogoutResponseFromIdentityProvider
public SamlLogoutResponse processPostLogoutResponseFromIdentityProvider(jakarta.servlet.http.HttpServletRequest request) throws SamlException Processes a POST containing the SAML response.- Parameters:
request- theHttpServletRequest.- Returns:
- An
SamlResponseobject containing information decoded from the SAML response. - Throws:
SamlException- thrown is an unexpected error occurs.
-
redirectToIdentityProvider
public void redirectToIdentityProvider(jakarta.servlet.http.HttpServletResponse response, String relayState, String nameId) throws IOException, SamlException Redirects anHttpServletResponseto the configured identity provider.- Parameters:
response- TheHttpServletResponse.relayState- Optional relay state that will be passed along.nameId- the user to log out.- Throws:
IOException- thrown if an IO error occurs.SamlException- thrown is an unexpected error occurs.
-
redirectToIdentityProviderLogout
public void redirectToIdentityProviderLogout(jakarta.servlet.http.HttpServletResponse response, String statusCode, String statMsg) throws IOException, SamlException Redirect to identity provider logout.- Parameters:
response- the responsestatusCode- the status codestatMsg- the stat msg- Throws:
IOException- the io exceptionSamlException- the saml exception
-