Package com.sun.identity.saml2.profile
Class IDPSSOUtil
- java.lang.Object
-
- com.sun.identity.saml2.profile.IDPSSOUtil
-
public class IDPSSOUtil extends Object
The utility class is used by the identity provider to process the authentication request from a service provider and send back a proper response. The identity provider can also send unsolicited response to a service provider to do single sign on and/or federation.
-
-
Field Summary
Fields Modifier and Type Field Description static CircleOfTrustManagercotManagerstatic SAML2MetaManagermetaManagerstatic StringNAMEID_FORMATstatic StringNULL
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voiddoSSOFederate(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, PrintWriter out, AuthnRequest authnReq, String spEntityID, String idpMetaAlias, String nameIDFormat, String relayState, Object newSession, SAML2EventLogger auditor)Does SSO with existing federation or new federationstatic voiddoSSOFederate(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, PrintWriter out, AuthnRequest authnReq, String spEntityID, String idpMetaAlias, String nameIDFormat, String relayState, SAML2EventLogger auditor)Does SSO with existing federation or new federationstatic StringgetACSurl(String spEntityID, String realm, AuthnRequest authnReq, jakarta.servlet.http.HttpServletRequest request, StringBuffer rBinding)Returns the assertion consumer serviceURLstatic StringgetACSurl(String spEntityID, String realm, String acsURL, String binding, Integer index, jakarta.servlet.http.HttpServletRequest request, StringBuffer rBinding)Returns the assertion consumer serviceURL.static StringgetACSurlFromMetaByBinding(String spEntityID, String realm, String desiredBinding, StringBuffer returnedBinding)Returns the assertion consumer serviceURLfrom meta data by bindingstatic StringgetACSurlFromMetaByIndex(String spEntityID, String realm, int acsIndex, StringBuffer returnedBinding)Returns the assertion consumer serviceURLfrom meta data by bindingstatic StringgetAttributeValueFromIDPSSOConfig(String realm, String hostEntityId, String attrName)static StringgetAuthenticationServiceURL(String realm, String hostEntityId, jakarta.servlet.http.HttpServletRequest request)Returns the authentication serviceURLof the identity providerstatic StringgetBindingForAcsUrl(String spEntityID, String realm, String acsURL)Returns the assertion consumer service url binding from the metadata.protected static ConditionsgetConditions(String audienceEntityID, int notBeforeSkewTime, int effectiveTime)Returns aSAML Conditionsobjectstatic StringgetDefaultACSurl(String spEntityID, String realm, StringBuffer returnedBinding)Returns the default assertion consumer service url and binding from the metadata.protected static intgetEffectiveTime(String realm, String idpEntityID)Returns the effective time from the IDP extended metadata .static SAML2IdentityProviderAdaptergetIDPAdapterClass(String realm, String idpEntityID)Returns aSAML2IdentityProviderAdapterstatic IDPAuthnContextMappergetIDPAuthnContextMapper(String realm, String idpEntityID)Returns anIDPAuthnContextMapperstatic IDPECPSessionMappergetIDPECPSessionMapper(String realm, String idpEntityID)Returns anIDPECPSessionMapperprotected static intgetNotBeforeSkewTime(String realm, String idpEntityID)Returns the NotBefore skew time from the IDP extended metadata .static ResponsegetResponse(jakarta.servlet.http.HttpServletRequest request, Object session, AuthnRequest authnReq, String recipientEntityID, String idpEntityID, String idpMetaAlias, String realm, String nameIDFormat, String acsURL, String affiliationID, AuthnContext matchingAuthnContext)Returns aSAML Responseobject.static StringgetSessionIndex(Object session)Returns the session index of anIDPSessionstatic longgetValidTimeofResponse(String realm, String idpEntityID, Response response)static booleanisValidSessionInRealm(String realm, Object session)Check that the authenticated session belongs to the same realm where the IDP is defined.static voidsendResponse(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, PrintWriter out, String cachedResID)Sends a response to service providerstatic voidsendResponse(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, PrintWriter out, String acsBinding, String spEntityID, String idpEntityID, String idpMetaAlias, String realm, String relayState, String acsURL, Response res, Object session)Sends a response to service providerstatic voidsendResponseArtifact(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, String idpEntityID, String spEntityID, String realm, String acsURL, String relayState, Response res, Object session, Map props)This method opens a URL connection to the target specified and sends artifact response to it using theHttpServletResponseobject.static voidsendResponseECP(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, PrintWriter out, String idpEntityID, String realm, String acsURL, Response res)This method sends SAML Response back to ECP.static voidsendResponseToACS(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, PrintWriter out, Object session, AuthnRequest authnReq, String spEntityID, String idpEntityID, String idpMetaAlias, String realm, String nameIDFormat, String relayState, AuthnContext matchingAuthnContext)SendsResponsecontaining anAssertionback to the requesting service providerstatic voidsendResponseWithStatus(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, PrintWriter out, String idpMetaAlias, String idpEntityID, String realm, AuthnRequest authnReq, String relayState, String spEntityID, String firstlevelStatusCodeValue, String secondlevelStatusCodeValue)A convenience method to construct response with First-level and Second-level status code for SAML authentication requests.static byte[]stringToByteArray(String input)
-
-
-
Field Detail
-
NAMEID_FORMAT
public static final String NAMEID_FORMAT
- See Also:
- Constant Field Values
-
NULL
public static final String NULL
- See Also:
- Constant Field Values
-
metaManager
public static SAML2MetaManager metaManager
-
cotManager
public static CircleOfTrustManager cotManager
-
-
Method Detail
-
doSSOFederate
public static void doSSOFederate(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, PrintWriter out, AuthnRequest authnReq, String spEntityID, String idpMetaAlias, String nameIDFormat, String relayState, SAML2EventLogger auditor) throws SAML2ExceptionDoes SSO with existing federation or new federation- Parameters:
request- theHttpServletRequestobjectresponse- theHttpServletResponseobjectout- the print writer for writing out presentationauthnReq- theAuthnRequestobjectspEntityID- the entity id of the service provideridpMetaAlias- the meta alias of the identity providernameIDFormat- theNameIDFormatrelayState- the relay stateauditor- the auditor for logging SAML2 Events - may be null- Throws:
SAML2Exception- if the operation is not successful
-
doSSOFederate
public static void doSSOFederate(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, PrintWriter out, AuthnRequest authnReq, String spEntityID, String idpMetaAlias, String nameIDFormat, String relayState, Object newSession, SAML2EventLogger auditor) throws SAML2ExceptionDoes SSO with existing federation or new federation- Parameters:
request- theHttpServletRequestobjectresponse- theHttpServletResponseobjectout- the print writer for writing out presentationauthnReq- theAuthnRequestobjectspEntityID- the entity id of the service provideridpMetaAlias- the meta alias of the identity providernameIDFormat- theNameIDFormatrelayState- the relay statenewSession- Session used in IDP Proxy Caseauditor- the auditor for logging SAML2 Events- Throws:
SAML2Exception- if the operation is not successful
-
sendResponseToACS
public static void sendResponseToACS(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, PrintWriter out, Object session, AuthnRequest authnReq, String spEntityID, String idpEntityID, String idpMetaAlias, String realm, String nameIDFormat, String relayState, AuthnContext matchingAuthnContext) throws SAML2ExceptionSendsResponsecontaining anAssertionback to the requesting service provider- Parameters:
request- theHttpServletRequestobjectresponse- theHttpServletResponseobjectout- the print writer for writing out presentationsession- user sessionauthnReq- theAuthnRequestobjectspEntityID- the entity id of the service provideridpEntityID- the entity id of the identity provideridpMetaAlias- the meta alias of the identity providerrealm- the realmnameIDFormat- theNameIDFormatrelayState- the relay statematchingAuthnContext- theAuthnContextused to find authentication type and scheme.- Throws:
SAML2Exception
-
sendResponseWithStatus
public static void sendResponseWithStatus(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, PrintWriter out, String idpMetaAlias, String idpEntityID, String realm, AuthnRequest authnReq, String relayState, String spEntityID, String firstlevelStatusCodeValue, String secondlevelStatusCodeValue) throws SAML2ExceptionA convenience method to construct response with First-level and Second-level status code for SAML authentication requests.- Parameters:
request- The servlet request.response- The servlet response.out- The print writer for writing out presentation.idpMetaAlias- The IdP's metaAlias.idpEntityID- The IdP's entity ID.realm- The realm where the IdP belongs to.authnReq- The SAML AuthnRequest sent by the SP.relayState- The RelayState value.spEntityID- The SP's entity ID.firstlevelStatusCodeValue- First-level status code value passed.secondlevelStatusCodeValue- Second-level status code value passed.- Throws:
SAML2Exception- If there was an error while creating or sending the response back to the SP.
-
sendResponse
public static void sendResponse(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, PrintWriter out, String cachedResID) throws SAML2ExceptionSends a response to service provider- Parameters:
request- The servlet request.response- The servlet response.out- The print writer for writing out presentation.cachedResID- the key used to retrieve response information from the response information cache- Throws:
SAML2Exception- if the operation is not successful
-
sendResponse
public static void sendResponse(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, PrintWriter out, String acsBinding, String spEntityID, String idpEntityID, String idpMetaAlias, String realm, String relayState, String acsURL, Response res, Object session) throws SAML2ExceptionSends a response to service provider- Parameters:
response- theHttpServletResponseobjectacsBinding- the assertion consumer service bindingspEntityID- the entity id of the service provideridpEntityID- the entity id of the identity provideridpMetaAlias- the meta alias of the identity providerrealm- the realm namerelayState- the relay stateacsURL- the assertion consumer serviceurlres- theSAML Responseobject- Throws:
SAML2Exception- if the operation is not successful
-
getResponse
public static Response getResponse(jakarta.servlet.http.HttpServletRequest request, Object session, AuthnRequest authnReq, String recipientEntityID, String idpEntityID, String idpMetaAlias, String realm, String nameIDFormat, String acsURL, String affiliationID, AuthnContext matchingAuthnContext) throws SAML2Exception
Returns aSAML Responseobject.- Parameters:
request- The HTTP request.session- The user's session object.authnReq- TheAuthnRequestobject.recipientEntityID- The entity ID of the response recipient.idpEntityID- The entity ID of the identity provider.realm- The realm name.nameIDFormat- TheNameIDFormat.acsURL- TheACSserviceurl.affiliationID- AffiliationID for IDP initiated SSO.matchingAuthnContext- theAuthnContextused to find authentication type and scheme.- Returns:
- the
SAML Responseobject. - Throws:
SAML2Exception- if the operation is not successful.
-
getIDPAuthnContextMapper
public static IDPAuthnContextMapper getIDPAuthnContextMapper(String realm, String idpEntityID) throws SAML2Exception
Returns anIDPAuthnContextMapper- Parameters:
realm- the realm nameidpEntityID- the entity id of the identity provider- Returns:
- the
IDPAuthnContextMapper - Throws:
SAML2Exception- if the operation is not successful
-
getIDPECPSessionMapper
public static IDPECPSessionMapper getIDPECPSessionMapper(String realm, String idpEntityID) throws SAML2Exception
Returns anIDPECPSessionMapper- Parameters:
realm- the realm nameidpEntityID- the entity id of the identity provider- Returns:
- the
IDPECPSessionMapper - Throws:
SAML2Exception- if the operation is not successful
-
getConditions
protected static Conditions getConditions(String audienceEntityID, int notBeforeSkewTime, int effectiveTime) throws SAML2Exception
Returns aSAML Conditionsobject- Parameters:
audienceEntityID- the entity id of the audienceeffectiveTime- the effective time of the assertion- Returns:
- the
SAML Conditionsobject - Throws:
SAML2Exception- if the operation is not successful
-
getACSurl
public static String getACSurl(String spEntityID, String realm, AuthnRequest authnReq, jakarta.servlet.http.HttpServletRequest request, StringBuffer rBinding) throws SAML2Exception
Returns the assertion consumer serviceURL- Parameters:
spEntityID- the entity id of the service providerrealm- the realm name of the identity providerauthnReq- theAuthnRequestobjectrequest- theHttpServletRequestobjectrBinding- the binding used to send backResponse- Returns:
- the assertion consumer service
URL - Throws:
SAML2Exception- if the operation is not successful
-
getACSurl
public static String getACSurl(String spEntityID, String realm, String acsURL, String binding, Integer index, jakarta.servlet.http.HttpServletRequest request, StringBuffer rBinding) throws SAML2Exception
Returns the assertion consumer serviceURL.- Parameters:
spEntityID- The entity id of the service provider.realm- The realm name of the identity provider.acsURL- AssertionConsumerServiceURL in AuthnRequest.binding- ProtocolBinding in AuthnRequest.index- AssertionConsumerServiceIndex in AuthnRequest.request- TheHttpServletRequestobject.rBinding- The binding used to send backResponse.- Returns:
- The assertion consumer service
URL. - Throws:
SAML2Exception- if the operation is not successful.
-
getDefaultACSurl
public static String getDefaultACSurl(String spEntityID, String realm, StringBuffer returnedBinding) throws SAML2Exception
Returns the default assertion consumer service url and binding from the metadata.- Parameters:
spEntityID- the entity id of the service providerrealm- the realm name of the identity provider- Returns:
- the assertion consumer service url with returned binding.
- Throws:
SAML2Exception- if the operation is not successful
-
getBindingForAcsUrl
public static String getBindingForAcsUrl(String spEntityID, String realm, String acsURL) throws SAML2Exception
Returns the assertion consumer service url binding from the metadata.- Parameters:
spEntityID- the entity id of the service providerrealm- the realm name of the identity provider- Returns:
- the assertion consumer service url binding
- Throws:
SAML2Exception- if the operation is not successful
-
getACSurlFromMetaByBinding
public static String getACSurlFromMetaByBinding(String spEntityID, String realm, String desiredBinding, StringBuffer returnedBinding) throws SAML2Exception
Returns the assertion consumer serviceURLfrom meta data by binding- Parameters:
spEntityID- the entity id of the service providerrealm- the realm name of the identity providerdesiredBinding- the desired bindingreturnedBinding- the binding used to send backResponse- Returns:
- the assertion consumer service
URL - Throws:
SAML2Exception- if the operation is not successful
-
getACSurlFromMetaByIndex
public static String getACSurlFromMetaByIndex(String spEntityID, String realm, int acsIndex, StringBuffer returnedBinding) throws SAML2Exception
Returns the assertion consumer serviceURLfrom meta data by binding- Parameters:
spEntityID- the entity id of the service providerrealm- the realm name of the identity provideracsIndex- theACSindexreturnedBinding- the binding used to send backResponse- Returns:
- the assertion consumer service
URL - Throws:
SAML2Exception- if the operation is not successful
-
sendResponseArtifact
public static void sendResponseArtifact(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, String idpEntityID, String spEntityID, String realm, String acsURL, String relayState, Response res, Object session, Map props) throws SAML2ExceptionThis method opens a URL connection to the target specified and sends artifact response to it using theHttpServletResponseobject.- Parameters:
response- theHttpServletResponseobjectidpEntityID- the entity id of the identity providerrealm- the realm name of the identity provideracsURL- the assertion consumer serviceURLrelayState- the value of theRelayStateres- theSAML Responseobjectsession- user sessionprops- property map including nameIDString for logging- Throws:
SAML2Exception- if the operation is not successful
-
sendResponseECP
public static void sendResponseECP(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, PrintWriter out, String idpEntityID, String realm, String acsURL, Response res) throws SAML2ExceptionThis method sends SAML Response back to ECP.- Parameters:
request- The servlet request.response- The servlet response.out- The print writer for writing out presentation.idpEntityID- the entity id of the identity providerrealm- the realm name of the identity provideracsURL- the assertion consumer serviceURLres- theSAML Responseobject- Throws:
SAML2Exception- if the operation is not successful
-
getSessionIndex
public static String getSessionIndex(Object session)
Returns the session index of anIDPSession- Parameters:
session- the session corresponding to theIDPSession- Returns:
- the session index string
-
getAuthenticationServiceURL
public static String getAuthenticationServiceURL(String realm, String hostEntityId, jakarta.servlet.http.HttpServletRequest request)
Returns the authentication serviceURLof the identity provider- Parameters:
realm- the realm name of the identity providerhostEntityId- the entity id of the identity providerrequest- theHttpServletRequestobject- Returns:
- the authentication service
URLof the identity provider
-
getAttributeValueFromIDPSSOConfig
public static String getAttributeValueFromIDPSSOConfig(String realm, String hostEntityId, String attrName)
-
getEffectiveTime
protected static int getEffectiveTime(String realm, String idpEntityID)
Returns the effective time from the IDP extended metadata . If the attreibute is not defined in the metadata then defaults to a value of 600 seconds (5 minutes).- Returns:
- the effective time value in seconds.
-
getNotBeforeSkewTime
protected static int getNotBeforeSkewTime(String realm, String idpEntityID)
Returns the NotBefore skew time from the IDP extended metadata . If the attreibute is not defined in the metadata then defaults to a value of 600 seconds (5 minutes).- Returns:
- the NotBefore skew value in seconds.
-
stringToByteArray
public static byte[] stringToByteArray(String input)
-
getValidTimeofResponse
public static long getValidTimeofResponse(String realm, String idpEntityID, Response response) throws SAML2Exception
- Throws:
SAML2Exception
-
getIDPAdapterClass
public static SAML2IdentityProviderAdapter getIDPAdapterClass(String realm, String idpEntityID) throws SAML2Exception
Returns aSAML2IdentityProviderAdapter- Parameters:
realm- the realm nameidpEntityID- the entity id of the identity provider- Returns:
- the
SAML2IdenityProviderAdapter - Throws:
SAML2Exception- if the operation is not successful
-
isValidSessionInRealm
public static boolean isValidSessionInRealm(String realm, Object session)
Check that the authenticated session belongs to the same realm where the IDP is defined.- Parameters:
realm- The realm where the IdP is defined.session- The Session object of the authenticated user.- Returns:
- true If the session was initiated in the same realm as the session's realm.
-
-