Class FSUtils
- java.lang.Object
-
- com.sun.identity.federation.common.FSUtils
-
public class FSUtils extends Object
This class contain constants used in the SDK.
-
-
Field Summary
Fields Modifier and Type Field Description static ResourceBundlebundlestatic StringBUNDLE_NAMEstatic Debugdebugstatic StringdeploymentURIstatic StringFSID_PREFIXstatic IDFFMetaManagermetaInstancestatic IFSConstantssc
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidcheckHTTPRequestLength(jakarta.servlet.http.HttpServletRequest request)Checks content length of a http request to avoid dos attack.static StringfindPreferredIDP(String realm, jakarta.servlet.http.HttpServletRequest request)Finds the preferred IDP from the HttpServletRequest.static voidforwardRequest(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, String url)Forwards or redirects to a new URL.static StringgenerateAssertionHandle()Generates assertion handle.static StringgenerateID()Generates an ID String with length of IFSConstants.ID_LENGTH.static StringgenerateSourceID(String entityID)Generates source ID Stringstatic StringgetAuthDomainURL(String orgDN)static IDFFMetaManagergetIDFFMetaManager()Returns an instance of the IDFF meta manager class.static StringgetlbCookieName()static StringgetlbCookieValue()static ListgetRemoteServiceURLs(jakarta.servlet.http.HttpServletRequest request)Gets remote service URLsstatic booleanisSameContainer(jakarta.servlet.http.HttpServletRequest request, String url)Test if url in argument is in the same web container as current opensso web apps serving the request.static booleanneedSetLBCookieAndRedirect(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, boolean isIDP)Detects if a request simply needs loadbalancer cookies adding and to be redirected to be handled elsewhere.static voidpostToTarget(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, String SAMLmessageName, String SAMLmessageValue, String relayStateName, String relayStateValue, String targetURL)Forwards to the auto submitting JSP so that the SAML message is re-posted totargetURL.static StringremoveNewLineChars(String s)Removes new line characters (useful for Base64 decoding)static booleanrequireAddCookie(jakarta.servlet.http.HttpServletRequest request)static booleanrequireRedirect(jakarta.servlet.http.HttpServletRequest request)static booleanrequireStopAfterFailedBounce(jakarta.servlet.http.HttpServletResponse response, Exception cause)Reports whether a failed load balancer cookie bounce has to stop the caller.static voidsetlbCookie(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response)Sets load balancer cookie.static voidsetLocale(String localeName)Sets the locale of the resource bundlestatic StringstringToBase64(String succinctID)Converts a string to Base64 encoded string.
-
-
-
Field Detail
-
deploymentURI
public static String deploymentURI
-
BUNDLE_NAME
public static final String BUNDLE_NAME
- See Also:
- Constant Field Values
-
sc
public static IFSConstants sc
-
bundle
public static ResourceBundle bundle
-
debug
public static Debug debug
-
FSID_PREFIX
public static final String FSID_PREFIX
- See Also:
- Constant Field Values
-
metaInstance
public static IDFFMetaManager metaInstance
-
-
Method Detail
-
setLocale
public static void setLocale(String localeName)
Sets the locale of the resource bundle
-
generateID
public static String generateID()
Generates an ID String with length of IFSConstants.ID_LENGTH.- Returns:
- string the ID String; or null if it fails.
-
generateSourceID
public static String generateSourceID(String entityID)
Generates source ID String- Parameters:
entityID- the entity ID of the source site- Returns:
- source ID
-
generateAssertionHandle
public static String generateAssertionHandle()
Generates assertion handle.- Returns:
- 20-byte random string to be used to form an artifact.
-
stringToBase64
public static String stringToBase64(String succinctID)
Converts a string to Base64 encoded string.- Parameters:
succinctID- provider's succinctID string- Returns:
- Base64 encoded string
-
checkHTTPRequestLength
public static void checkHTTPRequestLength(jakarta.servlet.http.HttpServletRequest request) throws jakarta.servlet.ServletExceptionChecks content length of a http request to avoid dos attack. In case IDFF inter-op with other IDFF vendor who may not provide content length in HttpServletRequest. We decide to support no length restriction for Http communication. Here, we use a special value (e.g. 0) to indicate that no enforcement is required.- Parameters:
request-HttpServletRequestinstance to be checked.- Throws:
jakarta.servlet.ServletException- if context length of the request exceeds maximum content length allowed.
-
isSameContainer
public static boolean isSameContainer(jakarta.servlet.http.HttpServletRequest request, String url)Test if url in argument is in the same web container as current opensso web apps serving the request.- Parameters:
request- HttpServletRequesturl- the URL to test against the current web container- Returns:
- true if request and url are in the same web container else false
-
forwardRequest
public static void forwardRequest(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, String url)Forwards or redirects to a new URL. This method will do forwarding if the target url is in the same web deployment URI as current web apps. Otherwise will do redirecting.- Parameters:
request- HttpServletRequestresponse- HttpServletResponseurl- the target URL to be forwarded to redirected.
-
findPreferredIDP
public static String findPreferredIDP(String realm, jakarta.servlet.http.HttpServletRequest request)
Finds the preferred IDP from the HttpServletRequest.- Parameters:
realm- The realm under which the entity resides.request- HttpServletRequest.- Returns:
- String preferred IDP entity ID; or
nullfor failure or unable to find in the request.
-
removeNewLineChars
public static String removeNewLineChars(String s)
Removes new line characters (useful for Base64 decoding)- Parameters:
s- String- Returns:
- result String
-
getIDFFMetaManager
public static IDFFMetaManager getIDFFMetaManager()
Returns an instance of the IDFF meta manager class.- Returns:
IDFFMetaManagerinstance; ornullif it cannot retrieve the instance.
-
requireAddCookie
public static boolean requireAddCookie(jakarta.servlet.http.HttpServletRequest request)
-
requireRedirect
public static boolean requireRedirect(jakarta.servlet.http.HttpServletRequest request)
-
needSetLBCookieAndRedirect
public static boolean needSetLBCookieAndRedirect(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, boolean isIDP)Detects if a request simply needs loadbalancer cookies adding and to be redirected to be handled elsewhere.Gated on
com.sun.identity.federation.cookieHashRedirectEnabled, which is off by default; seerequireAddCookie(jakarta.servlet.http.HttpServletRequest)andrequireRedirect(jakarta.servlet.http.HttpServletRequest)for the rest of the gate.- Parameters:
request- The HTTP request in question.response- The response associated with the request.isIDP- Whether this entity is acting as an IDP.- Returns:
falseif the caller still owns the response and has to carry on,trueif the request has been bounced and the caller must return without writing anything further. A bounce that failed after committing the response also returnstrue, seerequireStopAfterFailedBounce(jakarta.servlet.http.HttpServletResponse, java.lang.Exception).
-
requireStopAfterFailedBounce
public static boolean requireStopAfterFailedBounce(jakarta.servlet.http.HttpServletResponse response, Exception cause)Reports whether a failed load balancer cookie bounce has to stop the caller.Every caller reads a
falsefromneedSetLBCookieAndRedirect(jakarta.servlet.http.HttpServletRequest, jakarta.servlet.http.HttpServletResponse, boolean)as "no bounce was needed, carry on", which is only safe while the response is still untouched. The forward to the auto submit JSP can fail after the JSP has already written the SAML message and the container has flushed it - a signed assertion larger than the response buffer plus a client that aborts is enough. Carrying on from there would consume the one-time-use assertion, mint a session, and then callsendErrororsendRedirecton a committed response. So once the response is committed the caller is told the request was handled.A forward that failed while its output was still buffered leaves the caller in charge, but the half rendered auto submit form has to go: appending the caller's own page to it would produce one document carrying both, and the leftover
<body onload="document.forms[0].submit()">would submit the stale SAML message. So the buffer is dropped before handing the response back.Only the buffer:
reset()would also clear the headers, and by this pointsetlbCookie(jakarta.servlet.http.HttpServletRequest, jakarta.servlet.http.HttpServletResponse)has already put the load balancer cookie on the response. Dropping that would send the client away without the cookie the whole bounce exists to deliver, so the no-cache headers the sink set are left in place as the lesser cost.The same limit applies to the GET branch, where the failure came out of
sendRedirect: the status line andLocationit had already set stay on the response, and the servlet API offers no way to remove a header. A caller that carries on there would have its page discarded by a client following the redirect. Reaching that needssendRedirectto throw without committing, which Tomcat does not do unless the context is configured to send a redirect body.- Parameters:
response- The response associated with the request.cause- The failure that came out of the forward.- Returns:
trueif the response is already committed and the caller must stop.
-
getRemoteServiceURLs
public static List getRemoteServiceURLs(jakarta.servlet.http.HttpServletRequest request)
Gets remote service URLs- Parameters:
request- http request- Returns:
- remote service URLs
-
setlbCookie
public static void setlbCookie(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response)Sets load balancer cookie.- Parameters:
response- HttpServletResponse object
-
getlbCookieName
public static String getlbCookieName()
-
getlbCookieValue
public static String getlbCookieValue()
-
postToTarget
public static void postToTarget(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, String SAMLmessageName, String SAMLmessageValue, String relayStateName, String relayStateValue, String targetURL) throws SAML2ExceptionForwards to the auto submitting JSP so that the SAML message is re-posted totargetURL.IDFF and SAML2 re-post through the very same
autosubmitaccessrights.jsp, so this is a thin delegation toSAML2Utils.postToTarget(jakarta.servlet.http.HttpServletRequest, jakarta.servlet.http.HttpServletResponse, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)rather than a second implementation: that JSP renders the values with bare JSP EL, and one sink is what keeps the encoding it needs from drifting away on one of the two paths.- Parameters:
request- The HTTP request in question.response- The response associated with the request.SAMLmessageName- Name of the SAML message parameter.SAMLmessageValue- Value of the SAML message parameter.relayStateName- Name of the relay state parameter.relayStateValue- Value of the relay state parameter, may be null.targetURL- The URL the message is re-posted to.- Throws:
SAML2Exception- if the forward fails.
-
-