Package com.sun.identity.saml2.profile
Class SPACSUtils
- java.lang.Object
-
- com.sun.identity.saml2.profile.SPACSUtils
-
public class SPACSUtils extends Object
This class is used by a service provider (SP) to process the response from an identity provider for the SP's Assertion Consumer Service.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static List<Attribute>getAttrs(Assertion authnAssertion, boolean needAttributeEncrypted, Set<PrivateKey> decryptionKeys)Gets the attributes for this assertion in a new List.static StringgetIntermediateURL(String orgName, String hostEntityId, SAML2MetaManager sm)Retrieves intermediate redirect url from SP sso config.static booleangetNeedAttributeEncrypted(boolean needAssertionEncrypted, SPSSOConfigElement spssoconfig)static StringgetPrincipalWithoutLogin(Subject assertionSubject, Assertion authnAssertion, String realm, String spEntityId, SAML2MetaManager metaManager, String idpEntityId, String storageKey)Returns the username if there was one from the Assertion we were able to map into a local user account.static StringgetRelayState(String relayStateID, String orgName, String hostEntityId, SAML2MetaManager sm)Obtains relay state.static ResponseInfogetResponse(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, String orgName, String hostEntityId, SAML2MetaManager metaManager)RetrievesSAMLResponsefrom http request.static List<Attribute>getSAMLAttributes(Assertion assertion, boolean needAttributeEncrypted, Set<PrivateKey> privateKeys)Gets the attributes from an assert's AttributeStates.static StringprepareForLocalLogin(String realm, String hostEntityId, SAML2MetaManager sm, ResponseInfo respInfo, String requestURI)Saves response for later retrieval and retrieves local auth url fromSPSSOConfig.static ObjectprocessResponse(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, PrintWriter out, String metaAlias, Object session, ResponseInfo respInfo, String realm, String hostEntityId, SAML2MetaManager metaManager, SAML2EventLogger auditor)Authenticates user withResponse.static MapprocessResponseForFedlet(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, PrintWriter out)Processes response from Identity Provider to Fedlet (SP).static voidsaveInfoInMemory(SessionProvider sessionProvider, Object session, String sessionIndex, String metaAlias, NameIDInfo info, boolean isIDPProxy, boolean isTransient)static voidsetAttrMapInSession(SessionProvider sessionProvider, Map attrMap, Object session)Sets the attribute map in the session
-
-
-
Method Detail
-
getResponse
public static ResponseInfo getResponse(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, String orgName, String hostEntityId, SAML2MetaManager metaManager) throws SAML2Exception, IOException
RetrievesSAMLResponsefrom http request. It handles three cases:1. using http method get using request parameter "resID". This is the case after local login is done. 2. using http method get using request parameter "SAMLart". This is the case for artifact profile. 3. using http method post. This is the case for post profile.- Parameters:
request- http servlet requestresponse- http servlet responseorgName- realm or organization name the service provider resides inhostEntityId- Entity ID of the hosted service providermetaManager-SAML2MetaManagerinstance.- Returns:
ResponseInfoinstance.- Throws:
SAML2ExceptionIOException
-
processResponse
public static Object processResponse(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, PrintWriter out, String metaAlias, Object session, ResponseInfo respInfo, String realm, String hostEntityId, SAML2MetaManager metaManager, SAML2EventLogger auditor) throws SAML2Exception
Authenticates user withResponse. Auth session upgrade will be called if input session is not null. Otherwise, saml2 auth module is called. The name of the auth module is retrieved fromSPSSOConfig. If not found, "SAML2" will be used.- Parameters:
request- HTTP Servlet requestresponse- HTTP Servlet response.out- the print writer for writing out presentationmetaAlias- metaAlias for the service providersession- input session object. It could be null.respInfo-ResponseInfoto be verified.realm- realm or organization name of the service provider.hostEntityId- hosted service provider Entity ID.metaManager-SAML2MetaManagerinstance for meta operation.auditor- aSAML2EventLoggerauditor object to hook into tracking information for the saml request- Returns:
Objectwhich holds result of the session.- Throws:
SAML2Exception- if the processing failed.
-
getNeedAttributeEncrypted
public static boolean getNeedAttributeEncrypted(boolean needAssertionEncrypted, SPSSOConfigElement spssoconfig)
-
saveInfoInMemory
public static void saveInfoInMemory(SessionProvider sessionProvider, Object session, String sessionIndex, String metaAlias, NameIDInfo info, boolean isIDPProxy, boolean isTransient) throws SAML2Exception
- Throws:
SAML2Exception
-
setAttrMapInSession
public static void setAttrMapInSession(SessionProvider sessionProvider, Map attrMap, Object session) throws SessionException
Sets the attribute map in the session- Parameters:
sessionProvider- Session providerattrMap- the Attribute Mapsession- the valid session object- Throws:
SessionException
-
getRelayState
public static String getRelayState(String relayStateID, String orgName, String hostEntityId, SAML2MetaManager sm)
Obtains relay state. Retrieves the relay state from relay state cache. If input relay state is null, retrieve it fromSPSSOConfig.- Parameters:
relayStateID- relay state value received from http request.orgName- realm or organization name the service provider resides inhostEntityId- Entity ID of the hosted service providersm-SAML2MetaManagerinstance.- Returns:
- final relay state. Or
nullif the input relayStateID is null and no default relay state is configured.
-
getIntermediateURL
public static String getIntermediateURL(String orgName, String hostEntityId, SAML2MetaManager sm)
Retrieves intermediate redirect url from SP sso config. This url is used if you want to goto some place before the final relay state.- Parameters:
orgName- realm or organization name the service provider resides inhostEntityId- Entity ID of the hosted service providersm-SAML2MetaManagerinstance.- Returns:
- intermediate redirect url; or
nullif the url is is not configured or an error occured during the retrieval process.
-
prepareForLocalLogin
public static String prepareForLocalLogin(String realm, String hostEntityId, SAML2MetaManager sm, ResponseInfo respInfo, String requestURI)
Saves response for later retrieval and retrieves local auth url fromSPSSOConfig. If the url does not exist, generate one from request URI. If still cannot get it, (shouldn't happen), get it fromSystemConfigurationUtil.- Parameters:
realm- Realm or organization name the service provider resides in.hostEntityId- Entity ID of the hosted service provider.sm-SAML2MetaManagerinstance to perform metadata operations.respInfo- The to be cachedResponseInfo.requestURI- The HTTP request URI.- Returns:
- The local login url.
-
getSAMLAttributes
public static List<Attribute> getSAMLAttributes(Assertion assertion, boolean needAttributeEncrypted, Set<PrivateKey> privateKeys)
Gets the attributes from an assert's AttributeStates.- Parameters:
assertion- The assertion from which to pull the AttributeStates.needAttributeEncrypted- Whether attributes must be encrypted (or else rejected).privateKeys- Private keys used to decrypt those encrypted attributes.- Returns:
- a list of attributes pulled from the provided assertion.
-
processResponseForFedlet
public static Map processResponseForFedlet(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, PrintWriter out) throws SAML2Exception, IOException, SessionException, jakarta.servlet.ServletException
Processes response from Identity Provider to Fedlet (SP). This will do all required protocol processing, include signature, issuer and audience validation etc. A map containing processing result will be returned.
Here is a list of keys and values for the returned map:
SAML2Constants.ATTRIBUTE_MAP -- Attribute map containing all attributes passed down from IDP inside the Assertion. The value is ajava.util.Mapwhose keys are attribute names and values arejava.util.Setof string values for the attributes.
SAML2Constants.RELAY_STATE -- Relay state, value is a string
SAML2Constants.IDPENTITYID -- IDP entity ID, value is a string
SAML2Constants.RESPONSE -- Response object, value is an instance of com.sun.identity.saml2.protocol.Response SAML2Constants.ASSERTION -- Assertion object, value is an instance of com.sun.identity.saml2.assertion.Assertion SAML2Constants.SUBJECT -- Subject object, value is an instance of com.sun.identity.saml2.assertion.Subject SAML2Constants.NAMEID -- NameID object, value is an instance of com.sun.identity.saml2.assertion.NameID- Parameters:
request- HTTP Servlet requestresponse- HTTP Servlet response.out- the print writer for writing out presentation- Returns:
Mapwhich holds result of the processing.- Throws:
SAML2Exception- if the processing failed due to server error.IOException- if the processing failed due to IO error.SessionException- if the processing failed due to session error.jakarta.servlet.ServletException- if the processing failed due to request error.
-
getPrincipalWithoutLogin
public static String getPrincipalWithoutLogin(Subject assertionSubject, Assertion authnAssertion, String realm, String spEntityId, SAML2MetaManager metaManager, String idpEntityId, String storageKey) throws SAML2Exception
Returns the username if there was one from the Assertion we were able to map into a local user account. Returns null if not. Should only be used from the SP side. Should only be called in conjuncture with the Auth Module. In addition, it performs what attribute federation it can. This method is a picked apart version of the "processResponse" function.- Throws:
SAML2Exception
-
getAttrs
public static List<Attribute> getAttrs(Assertion authnAssertion, boolean needAttributeEncrypted, Set<PrivateKey> decryptionKeys)
Gets the attributes for this assertion in a new List.- Parameters:
authnAssertion- Assertion from which to reead the attributes.needAttributeEncrypted- Whether the attributes must be encrypted.decryptionKeys- The keys used to decrypt the attributes, if they're encrypted.- Returns:
- a List of the attributes in this assertion.
-
-