Package com.onelogin.saml2
Class Auth
java.lang.Object
com.onelogin.saml2.Auth
Main class of OneLogin's Java Toolkit.
This class implements the SP SAML instance.
Defines the methods that you can invoke in your application in
order to add SAML support (initiates sso, initiates slo, processes a
SAML Response, a Logout Request or a Logout Response).
This is stateful and not thread-safe, you should create a new instance for each request/response.
-
Field Summary
FieldsModifier and TypeFieldDescriptionUser attributes data.private booleanIf user is authenticated.private static final SamlMessageFactoryprivate StringReason of the last error.Stores any error.private StringThe ID of the last assertion processedThe NotOnOrAfter values of the last assertion processedprivate StringThe ID of the last message processedprivate CalendarThe issue instant of the last message processedprivate StringThe most recently-constructed/processed XML SAML request (AuthNRequest, LogoutRequest)private StringThe id of the last request (Authn or Logout) generatedprivate CalendarThe issue instant of the last request (Authn or Logout) generatedprivate StringThe most recently-constructed/processed XML SAML response (SAMLResponse, LogoutResponse).private static final org.slf4j.LoggerPrivate property to construct a logger for this class.private StringNameID.private StringNameIDFormat.private StringnameId NameQualifierprivate StringnameId SP NameQualifierprivate jakarta.servlet.http.HttpServletRequestHttpServletRequest object to be processed (Contains GET and POST parameters, session, ...).private jakarta.servlet.http.HttpServletResponseHttpServletResponse object to be used (For example to execute the redirections).private SamlMessageFactoryprivate InstantSessionNotOnOrAfter.private StringSessionIndex.private Saml2SettingsSettings data.private ExceptionException of the last error. -
Constructor Summary
ConstructorsConstructorDescriptionAuth()Initializes the SP SAML instance.Auth(KeyStoreSettings keyStoreSetting) Initializes the SP SAML instance.Auth(KeyStoreSettings keyStoreSetting, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) Initializes the SP SAML instance.Auth(Saml2Settings settings, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) Initializes the SP SAML instance.Auth(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) Initializes the SP SAML instance.Initializes the SP SAML instance.Auth(String filename, KeyStoreSettings keyStoreSetting) Initializes the SP SAML instance.Auth(String filename, KeyStoreSettings keyStoreSetting, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) Initializes the SP SAML instance.Auth(String filename, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) Initializes the SP SAML instance. -
Method Summary
Modifier and TypeMethodDescriptionbuildRequestSignature(String samlRequest, String relayState, String signAlgorithm) Generates the Signature for a SAML RequestbuildResponseSignature(String samlResponse, String relayState, String signAlgorithm) Generates the Signature for a SAML Responseprivate StringbuildSignature(String samlMessage, String relayState, String signAlgorithm, String type) Generates the Signature for a SAML Messagefinal Collection<String> getAttribute(String name) Returns the issue instant of the last message processed.Returns the issue instant of the last request generated (AuthnRequest or LogoutRequest).Returns the most recently-constructed/processed XML SAML request (AuthNRequest, LogoutRequest)Returns the most recently-constructed/processed XML SAML response (SAMLResponse, LogoutResponse).final Stringfinal Stringfinal Stringfinal Stringfinal Instantfinal Stringfinal booleanvoidlogin()Initiates the SSO process.voidlogin(AuthnRequestParams authnRequestParams) Initiates the SSO process.voidInitiates the SSO process.voidlogin(String relayState, AuthnRequestParams authnRequestParams) Initiates the SSO process.login(String relayState, AuthnRequestParams authnRequestParams, Boolean stay) Initiates the SSO process.login(String relayState, AuthnRequestParams authnRequestParams, Boolean stay, Map<String, String> parameters) Initiates the SSO process.voidDeprecated.login(String relayState, Boolean forceAuthn, Boolean isPassive, Boolean setNameIdPolicy, Boolean stay) Deprecated.login(String relayState, Boolean forceAuthn, Boolean isPassive, Boolean setNameIdPolicy, Boolean stay, String nameIdValueReq) Deprecated.login(String relayState, Boolean forceAuthn, Boolean isPassive, Boolean setNameIdPolicy, Boolean stay, String nameIdValueReq, Map<String, String> parameters) Deprecated.voidlogout()Initiates the SLO process.voidInitiates the SLO process.voidlogout(String relayState, LogoutRequestParams logoutRequestParams) Initiates the SLO process.logout(String relayState, LogoutRequestParams logoutRequestParams, Boolean stay) Initiates the SLO process.logout(String relayState, LogoutRequestParams logoutRequestParams, Boolean stay, Map<String, String> parameters) Initiates the SLO process.voidDeprecated.uselogout(String, LogoutRequestParams)withLogoutRequestParams(String, String)insteadDeprecated.Deprecated.logout(String relayState, String nameId, String sessionIndex, Boolean stay, String nameidFormat, String nameIdNameQualifier) Deprecated.logout(String relayState, String nameId, String sessionIndex, Boolean stay, String nameidFormat, String nameIdNameQualifier, String nameIdSPNameQualifier) Deprecated.logout(String relayState, String nameId, String sessionIndex, Boolean stay, String nameidFormat, String nameIdNameQualifier, String nameIdSPNameQualifier, Map<String, String> parameters) Deprecated.voidDeprecated.voidlogout(String relayState, String nameId, String sessionIndex, String nameidFormat, String nameIdNameQualifier) Deprecated.voidlogout(String relayState, String nameId, String sessionIndex, String nameidFormat, String nameIdNameQualifier, String nameIdSPNameQualifier) Deprecated.voidProcess the SAML Response sent by the IdP.voidprocessResponse(String requestId) Process the SAML Response sent by the IdP.voidProcess the SAML Logout Response / Logout Request sent by the IdP.voidprocessSLO(Boolean keepLocalSession, String requestId) Process the SAML Logout Response / Logout Request sent by the IdP.processSLO(Boolean keepLocalSession, String requestId, Boolean stay) Process the SAML Logout Response / Logout Request sent by the IdP.voidsetSamlMessageFactory(SamlMessageFactory samlMessageFactory) Sets the factory thisAuthwill use to create SAML messages.voidSet the strict mode active/disable
-
Field Details
-
LOGGER
private static final org.slf4j.Logger LOGGERPrivate property to construct a logger for this class. -
settings
Settings data. -
request
private jakarta.servlet.http.HttpServletRequest requestHttpServletRequest object to be processed (Contains GET and POST parameters, session, ...). -
response
private jakarta.servlet.http.HttpServletResponse responseHttpServletResponse object to be used (For example to execute the redirections). -
nameid
NameID. -
nameidFormat
NameIDFormat. -
nameidNameQualifier
nameId NameQualifier -
nameidSPNameQualifier
nameId SP NameQualifier -
sessionIndex
SessionIndex. When the user is logged, this stored it from the AuthnStatement of the SAML Response -
sessionExpiration
SessionNotOnOrAfter. When the user is logged, this stored it from the AuthnStatement of the SAML Response -
lastMessageId
The ID of the last message processed -
lastMessageIssueInstant
The issue instant of the last message processed -
lastAssertionId
The ID of the last assertion processed -
lastAssertionNotOnOrAfter
The NotOnOrAfter values of the last assertion processed -
attributes
User attributes data. -
authenticated
private boolean authenticatedIf user is authenticated. -
errors
Stores any error. -
errorReason
Reason of the last error. -
validationException
Exception of the last error. -
lastRequestId
The id of the last request (Authn or Logout) generated -
lastRequestIssueInstant
The issue instant of the last request (Authn or Logout) generated -
lastRequest
The most recently-constructed/processed XML SAML request (AuthNRequest, LogoutRequest) -
lastResponse
The most recently-constructed/processed XML SAML response (SAMLResponse, LogoutResponse). If the SAMLResponse was encrypted, by default tries to return the decrypted XML -
DEFAULT_SAML_MESSAGE_FACTORY
-
samlMessageFactory
-
-
Constructor Details
-
Auth
Initializes the SP SAML instance.- Throws:
IOExceptionSettingsExceptionError
-
Auth
Initializes the SP SAML instance.- Parameters:
keyStoreSetting- KeyStoreSettings is a KeyStore which have the Private/Public keys- Throws:
IOExceptionSettingsExceptionError
-
Auth
Initializes the SP SAML instance.- Parameters:
filename- String Filename with the settings- Throws:
IOExceptionSettingsExceptionError
-
Auth
public Auth(String filename, KeyStoreSettings keyStoreSetting) throws IOException, SettingsException, Error Initializes the SP SAML instance.- Parameters:
filename- String Filename with the settingskeyStoreSetting- KeyStoreSettings is a KeyStore which have the Private/Public keys- Throws:
IOExceptionSettingsExceptionError
-
Auth
public Auth(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) throws IOException, SettingsException, Error Initializes the SP SAML instance.- Parameters:
request- HttpServletRequest object to be processedresponse- HttpServletResponse object to be used- Throws:
IOExceptionSettingsExceptionError
-
Auth
public Auth(KeyStoreSettings keyStoreSetting, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) throws IOException, SettingsException, Error Initializes the SP SAML instance.- Parameters:
keyStoreSetting- KeyStoreSettings is a KeyStore which have the Private/Public keysrequest- HttpServletRequest object to be processedresponse- HttpServletResponse object to be used- Throws:
IOExceptionSettingsExceptionError
-
Auth
public Auth(String filename, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) throws SettingsException, IOException, Error Initializes the SP SAML instance.- Parameters:
filename- String Filename with the settingsrequest- HttpServletRequest object to be processedresponse- HttpServletResponse object to be used- Throws:
SettingsExceptionIOExceptionError
-
Auth
public Auth(String filename, KeyStoreSettings keyStoreSetting, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) throws SettingsException, IOException, Error Initializes the SP SAML instance.- Parameters:
filename- String Filename with the settingskeyStoreSetting- KeyStoreSettings is a KeyStore which have the Private/Public keysrequest- HttpServletRequest object to be processedresponse- HttpServletResponse object to be used- Throws:
SettingsExceptionIOExceptionError
-
Auth
public Auth(Saml2Settings settings, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) throws SettingsException Initializes the SP SAML instance.- Parameters:
settings- Saml2Settings object. Setting datarequest- HttpServletRequest object to be processedresponse- HttpServletResponse object to be used- Throws:
SettingsException
-
-
Method Details
-
setStrict
Set the strict mode active/disable- Parameters:
value- Strict value
-
login
@Deprecated public String login(String relayState, Boolean forceAuthn, Boolean isPassive, Boolean setNameIdPolicy, Boolean stay, String nameIdValueReq) throws IOException, SettingsException Deprecated.Initiates the SSO process.- Parameters:
relayState- a state information to pass forth and back between the Service Provider and the Identity Provider; in the most simple case, it may be a URL to which the authenticated user should be redirected after the authentication response has been received back from the Identity Provider and validated correctly withprocessResponse(); please note that SAML 2.0 specification imposes a limit of max 80 characters for this relayState data and that protection strategies against tampering should better be implemented; it will be a self-routed URL whennull, otherwise no relayState at all will be appended if an empty string is providedforceAuthn- When true the AuthNRequest will set the ForceAuthn='true'isPassive- When true the AuthNRequest will set the IsPassive='true'setNameIdPolicy- When true the AuthNRequest will set a nameIdPolicystay- True if we want to stay (returns the url string) False to execute redirectionnameIdValueReq- Indicates to the IdP the subject that should be authenticated- Returns:
- the SSO URL with the AuthNRequest if stay = True
- Throws:
IOExceptionSettingsException
-
login
@Deprecated public String login(String relayState, Boolean forceAuthn, Boolean isPassive, Boolean setNameIdPolicy, Boolean stay, String nameIdValueReq, Map<String, String> parameters) throws IOException, SettingsExceptionDeprecated.Initiates the SSO process.- Parameters:
relayState- a state information to pass forth and back between the Service Provider and the Identity Provider; in the most simple case, it may be a URL to which the authenticated user should be redirected after the authentication response has been received back from the Identity Provider and validated correctly withprocessResponse(); please note that SAML 2.0 specification imposes a limit of max 80 characters for this relayState data and that protection strategies against tampering should better be implemented; it will be a self-routed URL whennull, otherwise no relayState at all will be appended if an empty string is providedforceAuthn- When true the AuthNRequest will set the ForceAuthn='true'isPassive- When true the AuthNRequest will set the IsPassive='true'setNameIdPolicy- When true the AuthNRequest will set a nameIdPolicystay- True if we want to stay (returns the url string) False to execute redirectionnameIdValueReq- Indicates to the IdP the subject that should be authenticatedparameters- Use it to send extra parameters in addition to the AuthNRequest- Returns:
- the SSO URL with the AuthNRequest if stay = True
- Throws:
IOExceptionSettingsException
-
login
@Deprecated public String login(String relayState, Boolean forceAuthn, Boolean isPassive, Boolean setNameIdPolicy, Boolean stay) throws IOException, SettingsException Deprecated.Initiates the SSO process.- Parameters:
relayState- a state information to pass forth and back between the Service Provider and the Identity Provider; in the most simple case, it may be a URL to which the authenticated user should be redirected after the authentication response has been received back from the Identity Provider and validated correctly withprocessResponse(); please note that SAML 2.0 specification imposes a limit of max 80 characters for this relayState data and that protection strategies against tampering should better be implemented; it will be a self-routed URL whennull, otherwise no relayState at all will be appended if an empty string is providedforceAuthn- When true the AuthNRequest will set the ForceAuthn='true'isPassive- When true the AuthNRequest will set the IsPassive='true'setNameIdPolicy- When true the AuthNRequest will set a nameIdPolicystay- True if we want to stay (returns the url string) False to execute redirection- Returns:
- the SSO URL with the AuthNRequest if stay = True
- Throws:
IOExceptionSettingsException
-
login
@Deprecated public void login(String relayState, Boolean forceAuthn, Boolean isPassive, Boolean setNameIdPolicy) throws IOException, SettingsException Deprecated.Initiates the SSO process.- Parameters:
relayState- a state information to pass forth and back between the Service Provider and the Identity Provider; in the most simple case, it may be a URL to which the authenticated user should be redirected after the authentication response has been received back from the Identity Provider and validated correctly withprocessResponse(); please note that SAML 2.0 specification imposes a limit of max 80 characters for this relayState data and that protection strategies against tampering should better be implemented; it will be a self-routed URL whennull, otherwise no relayState at all will be appended if an empty string is providedforceAuthn- When true the AuthNRequest will set the ForceAuthn='true'isPassive- When true the AuthNRequest will set the IsPassive='true'setNameIdPolicy- When true the AuthNRequest will set a nameIdPolicy- Throws:
IOExceptionSettingsException
-
login
Initiates the SSO process.- Throws:
IOExceptionSettingsException
-
login
Initiates the SSO process.- Parameters:
authnRequestParams- the authentication request input parameters- Throws:
IOExceptionSettingsException
-
login
Initiates the SSO process.- Parameters:
relayState- a state information to pass forth and back between the Service Provider and the Identity Provider; in the most simple case, it may be a URL to which the authenticated user should be redirected after the authentication response has been received back from the Identity Provider and validated correctly withprocessResponse(); please note that SAML 2.0 specification imposes a limit of max 80 characters for this relayState data and that protection strategies against tampering should better be implemented; it will be a self-routed URL whennull, otherwise no relayState at all will be appended if an empty string is provided- Throws:
IOExceptionSettingsException
-
login
public void login(String relayState, AuthnRequestParams authnRequestParams) throws IOException, SettingsException Initiates the SSO process.- Parameters:
relayState- a state information to pass forth and back between the Service Provider and the Identity Provider; in the most simple case, it may be a URL to which the authenticated user should be redirected after the authentication response has been received back from the Identity Provider and validated correctly withprocessResponse(); please note that SAML 2.0 specification imposes a limit of max 80 characters for this relayState data and that protection strategies against tampering should better be implemented; it will be a self-routed URL whennull, otherwise no relayState at all will be appended if an empty string is providedauthnRequestParams- the authentication request input parameters- Throws:
IOExceptionSettingsException
-
login
public String login(String relayState, AuthnRequestParams authnRequestParams, Boolean stay) throws IOException, SettingsException Initiates the SSO process.- Parameters:
relayState- a state information to pass forth and back between the Service Provider and the Identity Provider; in the most simple case, it may be a URL to which the authenticated user should be redirected after the authentication response has been received back from the Identity Provider and validated correctly withprocessResponse(); please note that SAML 2.0 specification imposes a limit of max 80 characters for this relayState data and that protection strategies against tampering should better be implemented; it will be a self-routed URL whennull, otherwise no relayState at all will be appended if an empty string is providedauthnRequestParams- the authentication request input parametersstay- True if we want to stay (returns the url string) False to execute redirection- Returns:
- the SSO URL with the AuthNRequest if stay = True
- Throws:
IOExceptionSettingsException
-
login
public String login(String relayState, AuthnRequestParams authnRequestParams, Boolean stay, Map<String, String> parameters) throws IOException, SettingsExceptionInitiates the SSO process.- Parameters:
relayState- a state information to pass forth and back between the Service Provider and the Identity Provider; in the most simple case, it may be a URL to which the authenticated user should be redirected after the authentication response has been received back from the Identity Provider and validated correctly withprocessResponse(); please note that SAML 2.0 specification imposes a limit of max 80 characters for this relayState data and that protection strategies against tampering should better be implemented; it will be a self-routed URL whennull, otherwise no relayState at all will be appended if an empty string is providedauthnRequestParams- the authentication request input parametersstay- True if we want to stay (returns the url string) False to execute redirectionparameters- Use it to send extra parameters in addition to the AuthNRequest- Returns:
- the SSO URL with the AuthNRequest if stay = True
- Throws:
IOExceptionSettingsException
-
logout
public String logout(String relayState, LogoutRequestParams logoutRequestParams, Boolean stay) throws IOException, SettingsException Initiates the SLO process.- Parameters:
relayState- a state information to pass forth and back between the Service Provider and the Identity Provider; in the most simple case, it may be a URL to which the logged out user should be redirected after the logout response has been received back from the Identity Provider and validated correctly withprocessSLO(); please note that SAML 2.0 specification imposes a limit of max 80 characters for this relayState data and that protection strategies against tampering should better be implemented; it will be a self-routed URL whennull, otherwise no relayState at all will be appended if an empty string is providedlogoutRequestParams- the logout request input parametersstay- True if we want to stay (returns the url string) False to execute redirection- Returns:
- the SLO URL with the LogoutRequest if stay = True
- Throws:
IOExceptionSettingsException
-
logout
public void logout(String relayState, LogoutRequestParams logoutRequestParams) throws IOException, SettingsException Initiates the SLO process.- Parameters:
relayState- a state information to pass forth and back between the Service Provider and the Identity Provider; in the most simple case, it may be a URL to which the logged out user should be redirected after the logout response has been received back from the Identity Provider and validated correctly withprocessSLO(); please note that SAML 2.0 specification imposes a limit of max 80 characters for this relayState data and that protection strategies against tampering should better be implemented; it will be a self-routed URL whennull, otherwise no relayState at all will be appended if an empty string is providedlogoutRequestParams- the logout request input parameters- Throws:
IOExceptionSettingsException
-
logout
public String logout(String relayState, String nameId, String sessionIndex, Boolean stay, String nameidFormat, String nameIdNameQualifier, String nameIdSPNameQualifier) throws IOException, SettingsException Deprecated.Initiates the SLO process.- Parameters:
relayState- a state information to pass forth and back between the Service Provider and the Identity Provider; in the most simple case, it may be a URL to which the logged out user should be redirected after the logout response has been received back from the Identity Provider and validated correctly withprocessSLO(); please note that SAML 2.0 specification imposes a limit of max 80 characters for this relayState data and that protection strategies against tampering should better be implemented; it will be a self-routed URL whennull, otherwise no relayState at all will be appended if an empty string is providednameId- The NameID that will be set in the LogoutRequest.sessionIndex- The SessionIndex (taken from the SAML Response in the SSO process).stay- True if we want to stay (returns the url string) False to execute redirectionnameidFormat- The NameID Format that will be set in the LogoutRequest.nameIdNameQualifier- The NameID NameQualifier that will be set in the LogoutRequest.nameIdSPNameQualifier- The NameID SP Name Qualifier that will be set in the LogoutRequest.- Returns:
- the SLO URL with the LogoutRequest if stay = True
- Throws:
IOExceptionSettingsException
-
logout
public String logout(String relayState, LogoutRequestParams logoutRequestParams, Boolean stay, Map<String, String> parameters) throws IOException, SettingsExceptionInitiates the SLO process.- Parameters:
relayState- a state information to pass forth and back between the Service Provider and the Identity Provider; in the most simple case, it may be a URL to which the logged out user should be redirected after the logout response has been received back from the Identity Provider and validated correctly withprocessSLO(); please note that SAML 2.0 specification imposes a limit of max 80 characters for this relayState data and that protection strategies against tampering should better be implemented; it will be a self-routed URL whennull, otherwise no relayState at all will be appended if an empty string is providedlogoutRequestParams- the logout request input parametersstay- True if we want to stay (returns the url string) False to execute redirectionparameters- Use it to send extra parameters in addition to the LogoutRequest- Returns:
- the SLO URL with the LogoutRequest if stay = True
- Throws:
IOExceptionSettingsException
-
logout
@Deprecated public String logout(String relayState, String nameId, String sessionIndex, Boolean stay, String nameidFormat, String nameIdNameQualifier, String nameIdSPNameQualifier, Map<String, String> parameters) throws IOException, SettingsExceptionDeprecated.Initiates the SLO process.- Parameters:
relayState- a state information to pass forth and back between the Service Provider and the Identity Provider; in the most simple case, it may be a URL to which the logged out user should be redirected after the logout response has been received back from the Identity Provider and validated correctly withprocessSLO(); please note that SAML 2.0 specification imposes a limit of max 80 characters for this relayState data and that protection strategies against tampering should better be implemented; it will be a self-routed URL whennull, otherwise no relayState at all will be appended if an empty string is providednameId- The NameID that will be set in the LogoutRequest.sessionIndex- The SessionIndex (taken from the SAML Response in the SSO process).stay- True if we want to stay (returns the url string) False to execute redirectionnameidFormat- The NameID Format that will be set in the LogoutRequest.nameIdNameQualifier- The NameID NameQualifier that will be set in the LogoutRequest.nameIdSPNameQualifier- The NameID SP Name Qualifier that will be set in the LogoutRequest.parameters- Use it to send extra parameters in addition to the LogoutRequest- Returns:
- the SLO URL with the LogoutRequest if stay = True
- Throws:
IOExceptionSettingsException
-
logout
@Deprecated public String logout(String relayState, String nameId, String sessionIndex, Boolean stay, String nameidFormat, String nameIdNameQualifier) throws IOException, SettingsException Deprecated.Initiates the SLO process.- Parameters:
relayState- a state information to pass forth and back between the Service Provider and the Identity Provider; in the most simple case, it may be a URL to which the logged out user should be redirected after the logout response has been received back from the Identity Provider and validated correctly withprocessSLO(); please note that SAML 2.0 specification imposes a limit of max 80 characters for this relayState data and that protection strategies against tampering should better be implemented; it will be a self-routed URL whennull, otherwise no relayState at all will be appended if an empty string is providednameId- The NameID that will be set in the LogoutRequest.sessionIndex- The SessionIndex (taken from the SAML Response in the SSO process).stay- True if we want to stay (returns the url string) False to execute redirectionnameidFormat- The NameID Format will be set in the LogoutRequest.nameIdNameQualifier- The NameID NameQualifier will be set in the LogoutRequest.- Returns:
- the SLO URL with the LogoutRequest if stay = True
- Throws:
IOExceptionSettingsException
-
logout
@Deprecated public String logout(String relayState, String nameId, String sessionIndex, Boolean stay, String nameidFormat) throws IOException, SettingsException Deprecated.Initiates the SLO process.- Parameters:
relayState- a state information to pass forth and back between the Service Provider and the Identity Provider; in the most simple case, it may be a URL to which the logged out user should be redirected after the logout response has been received back from the Identity Provider and validated correctly withprocessSLO(); please note that SAML 2.0 specification imposes a limit of max 80 characters for this relayState data and that protection strategies against tampering should better be implemented; it will be a self-routed URL whennull, otherwise no relayState at all will be appended if an empty string is providednameId- The NameID that will be set in the LogoutRequest.sessionIndex- The SessionIndex (taken from the SAML Response in the SSO process).stay- True if we want to stay (returns the url string) False to execute redirectionnameidFormat- The NameID Format will be set in the LogoutRequest.- Returns:
- the SLO URL with the LogoutRequest if stay = True
- Throws:
IOExceptionSettingsException
-
logout
@Deprecated public String logout(String relayState, String nameId, String sessionIndex, Boolean stay) throws IOException, SettingsException Deprecated.Initiates the SLO process.- Parameters:
relayState- a state information to pass forth and back between the Service Provider and the Identity Provider; in the most simple case, it may be a URL to which the logged out user should be redirected after the logout response has been received back from the Identity Provider and validated correctly withprocessSLO(); please note that SAML 2.0 specification imposes a limit of max 80 characters for this relayState data and that protection strategies against tampering should better be implemented; it will be a self-routed URL whennull, otherwise no relayState at all will be appended if an empty string is providednameId- The NameID that will be set in the LogoutRequest.sessionIndex- The SessionIndex (taken from the SAML Response in the SSO process).stay- True if we want to stay (returns the url string) False to execute redirection- Returns:
- the SLO URL with the LogoutRequest if stay = True
- Throws:
IOExceptionSettingsException
-
logout
@Deprecated public void logout(String relayState, String nameId, String sessionIndex, String nameidFormat, String nameIdNameQualifier, String nameIdSPNameQualifier) throws IOException, SettingsException Deprecated.Initiates the SLO process.- Parameters:
relayState- a state information to pass forth and back between the Service Provider and the Identity Provider; in the most simple case, it may be a URL to which the logged out user should be redirected after the logout response has been received back from the Identity Provider and validated correctly withprocessSLO(); please note that SAML 2.0 specification imposes a limit of max 80 characters for this relayState data and that protection strategies against tampering should better be implemented; it will be a self-routed URL whennull, otherwise no relayState at all will be appended if an empty string is providednameId- The NameID that will be set in the LogoutRequest.sessionIndex- The SessionIndex (taken from the SAML Response in the SSO process).nameidFormat- The NameID Format will be set in the LogoutRequest.nameIdNameQualifier- The NameID NameQualifier that will be set in the LogoutRequest.nameIdSPNameQualifier- The NameID SP Name Qualifier that will be set in the LogoutRequest.- Throws:
IOExceptionSettingsException
-
logout
@Deprecated public void logout(String relayState, String nameId, String sessionIndex, String nameidFormat, String nameIdNameQualifier) throws IOException, SettingsException Deprecated.Initiates the SLO process.- Parameters:
relayState- a state information to pass forth and back between the Service Provider and the Identity Provider; in the most simple case, it may be a URL to which the logged out user should be redirected after the logout response has been received back from the Identity Provider and validated correctly withprocessSLO(); please note that SAML 2.0 specification imposes a limit of max 80 characters for this relayState data and that protection strategies against tampering should better be implemented; it will be a self-routed URL whennull, otherwise no relayState at all will be appended if an empty string is providednameId- The NameID that will be set in the LogoutRequest.sessionIndex- The SessionIndex (taken from the SAML Response in the SSO process).nameidFormat- The NameID Format will be set in the LogoutRequest.nameIdNameQualifier- The NameID NameQualifier will be set in the LogoutRequest.- Throws:
IOExceptionSettingsException
-
logout
@Deprecated public void logout(String relayState, String nameId, String sessionIndex, String nameidFormat) throws IOException, SettingsException Deprecated.Initiates the SLO process.- Parameters:
relayState- a state information to pass forth and back between the Service Provider and the Identity Provider; in the most simple case, it may be a URL to which the logged out user should be redirected after the logout response has been received back from the Identity Provider and validated correctly withprocessSLO(); please note that SAML 2.0 specification imposes a limit of max 80 characters for this relayState data and that protection strategies against tampering should better be implemented; it will be a self-routed URL whennull, otherwise no relayState at all will be appended if an empty string is providednameId- The NameID that will be set in the LogoutRequest.sessionIndex- The SessionIndex (taken from the SAML Response in the SSO process).nameidFormat- The NameID Format will be set in the LogoutRequest.- Throws:
IOExceptionSettingsException
-
logout
@Deprecated public void logout(String relayState, String nameId, String sessionIndex) throws IOException, SettingsException Deprecated.uselogout(String, LogoutRequestParams)withLogoutRequestParams(String, String)insteadInitiates the SLO process.- Parameters:
relayState- a state information to pass forth and back between the Service Provider and the Identity Provider; in the most simple case, it may be a URL to which the logged out user should be redirected after the logout response has been received back from the Identity Provider and validated correctly withprocessSLO(); please note that SAML 2.0 specification imposes a limit of max 80 characters for this relayState data and that protection strategies against tampering should better be implemented; it will be a self-routed URL whennull, otherwise no relayState at all will be appended if an empty string is providednameId- The NameID that will be set in the LogoutRequest.sessionIndex- The SessionIndex (taken from the SAML Response in the SSO process).- Throws:
IOExceptionSettingsException
-
logout
Initiates the SLO process.- Throws:
IOExceptionSettingsException
-
logout
Initiates the SLO process.- Parameters:
relayState- a state information to pass forth and back between the Service Provider and the Identity Provider; in the most simple case, it may be a URL to which the logged out user should be redirected after the logout response has been received back from the Identity Provider and validated correctly withprocessSLO(); please note that SAML 2.0 specification imposes a limit of max 80 characters for this relayState data and that protection strategies against tampering should better be implemented; it will be a self-routed URL whennull, otherwise no relayState at all will be appended if an empty string is provided- Throws:
IOExceptionSettingsException
-
getSSOurl
- Returns:
- The url of the Single Sign On Service
-
getSLOurl
- Returns:
- The url of the Single Logout Service
-
getSLOResponseUrl
- Returns:
- The url of the Single Logout Service Response.
-
processResponse
Process the SAML Response sent by the IdP.- Parameters:
requestId- The ID of the AuthNRequest sent by this SP to the IdP- Throws:
Exception
-
processResponse
Process the SAML Response sent by the IdP.- Throws:
Exception
-
processSLO
Process the SAML Logout Response / Logout Request sent by the IdP.- Parameters:
keepLocalSession- When true will keep the local session, otherwise will destroy itrequestId- The ID of the LogoutRequest sent by this SP to the IdPstay- True if we want to stay (returns the url string) False to execute redirection- Returns:
- the URL with the Logout Message if stay = True
- Throws:
Exception
-
processSLO
Process the SAML Logout Response / Logout Request sent by the IdP.- Parameters:
keepLocalSession- When true will keep the local session, otherwise will destroy itrequestId- The ID of the LogoutRequest sent by this SP to the IdP- Throws:
Exception
-
processSLO
Process the SAML Logout Response / Logout Request sent by the IdP.- Throws:
Exception
-
isAuthenticated
public final boolean isAuthenticated()- Returns:
- the authenticated
-
getAttributesName
- Returns:
- the list of the names of the SAML attributes.
-
getAttributes
- Returns:
- the set of SAML attributes.
-
getAttribute
- Parameters:
name- Name of the attribute- Returns:
- the attribute value
-
getNameId
- Returns:
- the nameID of the assertion
-
getNameIdFormat
- Returns:
- the nameID Format of the assertion
-
getNameIdNameQualifier
- Returns:
- the NameQualifier of the assertion
-
getNameIdSPNameQualifier
- Returns:
- the SPNameQualifier of the assertion
-
getSessionIndex
- Returns:
- the SessionIndex of the assertion
-
getSessionExpiration
- Returns:
- the SessionNotOnOrAfter of the assertion
-
getLastMessageId
- Returns:
- The ID of the last message processed
-
getLastMessageIssueInstant
Returns the issue instant of the last message processed.- Returns:
- The issue instant of the last message processed
-
getLastAssertionId
- Returns:
- The ID of the last assertion processed
-
getLastAssertionNotOnOrAfter
- Returns:
- The NotOnOrAfter values of the last assertion processed
-
getErrors
- Returns:
- an array with the errors, the array is empty when the validation was successful
-
getLastErrorReason
- Returns:
- the reason for the last error
-
getLastValidationException
- Returns:
- the exception for the last error
-
getLastRequestId
- Returns:
- the id of the last request generated (AuthnRequest or LogoutRequest), null if none
-
getLastRequestIssueInstant
Returns the issue instant of the last request generated (AuthnRequest or LogoutRequest).- Returns:
- the issue instant of the last request generated (AuthnRequest or LogoutRequest),
nullif none
-
getSettings
- Returns:
- the Saml2Settings object. The Settings data.
-
isDebugActive
- Returns:
- if debug mode is active
-
buildRequestSignature
public String buildRequestSignature(String samlRequest, String relayState, String signAlgorithm) throws SettingsException Generates the Signature for a SAML Request- Parameters:
samlRequest- The SAML RequestrelayState- The RelayStatesignAlgorithm- Signature algorithm method- Returns:
- a base64 encoded signature
- Throws:
SettingsException
-
buildResponseSignature
public String buildResponseSignature(String samlResponse, String relayState, String signAlgorithm) throws SettingsException Generates the Signature for a SAML Response- Parameters:
samlResponse- The SAML ResponserelayState- The RelayStatesignAlgorithm- Signature algorithm method- Returns:
- the base64 encoded signature
- Throws:
SettingsException
-
buildSignature
private String buildSignature(String samlMessage, String relayState, String signAlgorithm, String type) throws SettingsException, IllegalArgumentException Generates the Signature for a SAML Message- Parameters:
samlMessage- The SAML MessagerelayState- The RelayStatesignAlgorithm- Signature algorithm methodtype- The type of the message- Returns:
- the base64 encoded signature
- Throws:
SettingsExceptionIllegalArgumentException
-
getLastRequestXML
Returns the most recently-constructed/processed XML SAML request (AuthNRequest, LogoutRequest)- Returns:
- the last Request XML
-
getLastResponseXML
Returns the most recently-constructed/processed XML SAML response (SAMLResponse, LogoutResponse). If the SAMLResponse was encrypted, by default tries to return the decrypted XML.- Returns:
- the last Response XML
-
setSamlMessageFactory
Sets the factory thisAuthwill use to create SAML messages.This allows consumers to provide their own extension classes for SAML message XML generation and/or processing.
- Parameters:
samlMessageFactory- the factory to use to create SAML message objects; ifnull, a default provider will be used which creates the standard message implementation provided by this library (i.e.:AuthnRequest,SamlResponse,LogoutRequestandLogoutResponse)
-
login(String, AuthnRequestParams)withAuthnRequestParams(boolean, boolean, boolean)instead