Package swiss.trustbroker.common.util
Class WebUtil
java.lang.Object
swiss.trustbroker.common.util.WebUtil
Log-able web input (where we do not expected any StringUtil.clean modified data) and other helpers.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final String -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddCacheHeaders(jakarta.servlet.http.HttpServletResponse response, int maxAgeSecs, String etag, Instant lastModified, Instant now) "etag" must contain leading and trailing quotesstatic voidaddCookies(jakarta.servlet.http.HttpServletResponse response, List<jakarta.servlet.http.Cookie> cookies) static StringappendQueryParameters(String url, Map<String, String> parameters) cookiesToStrings(List<jakarta.servlet.http.Cookie> cookieList) static StringcookieToString(jakarta.servlet.http.Cookie cookie) static jakarta.servlet.http.CookiecreateCookie(CookieParameters params) static Optional<jakarta.servlet.http.Cookie> deduplicateSetCookie(Map<String, List<jakarta.servlet.http.Cookie>> addedCookies, jakarta.servlet.http.Cookie newCookie) static StringgetAbsoluteUrl(String baseUrl, String otherUrl) static Stringstatic StringgetBasicAuthorizationHeader(String clientId, String clientSecret) static StringgetBearerAuthorizationHeader(String accessToken) static StringgetClientIp(jakarta.servlet.http.HttpServletRequest request) static StringgetClientIp(jakarta.servlet.http.HttpServletRequest request, boolean tagged) static String[]getClientIps(jakarta.servlet.http.HttpServletRequest request, boolean tagged) static Stringstatic StringgetCookieSameSite(String defaultSameSite, String perimeterUrl, String requestUrl, Optional<Boolean> crossSiteRequest, Optional<Boolean> insecureRequest) static StringgetGatewayIp(jakarta.servlet.http.HttpServletRequest request) static StringgetGatewayIp(jakarta.servlet.http.HttpServletRequest request, boolean tagged) static String[]getGatewayIps(jakarta.servlet.http.HttpServletRequest request) static Stringstatic StringgetOrigin(jakarta.servlet.http.HttpServletRequest request) static StringgetOriginOrReferer(jakarta.servlet.http.HttpServletRequest request) static StringgetParameter(String name, jakarta.servlet.http.HttpServletRequest request) static StringgetReferer(jakarta.servlet.http.HttpServletRequest request) static StringgetSameSite(boolean isSameSite) static StringgetServiceContext(jakarta.servlet.http.HttpServletRequest request) static StringSite extraction based on InternetDomainName, returns the full host name if it cannot be extracted (e.g.static StringgetUrlHost(String url) static StringgetUrlWithQuery(jakarta.servlet.http.HttpServletRequest request) static StringgetUserAgent(jakarta.servlet.http.HttpServletRequest request) static URIgetValidatedUri(String url) static StringgetValidOrigin(String origin) static StringgetValidOrigin(URI uri) static StringgetValidRefererWithoutPath(String referer) static booleanisAllowedOrigin(Collection<Collection<String>> allowedUrlSets, String origin) static booleanisAllowedOriginOrReferer(Collection<String> allowedUrls, String originOrReferer, String validatedOriginOrReferer) Validate origin/referer against allow list.static booleanisAllowedReferer(Collection<Collection<String>> allowedUrlSets, String referer) static booleanReturns true if the resource has not been modified based on the browser headers If-None-Match/If-Modified-Since.static booleanisCorsRequest(jakarta.servlet.http.HttpServletRequest request) isCrossSiteRequest(jakarta.servlet.http.HttpServletRequest request) static booleanisNullOrigin(String origin) static booleanisSameSite(URI uri1, URI uri2) static booleanisSameSiteDynamic(String sameSiteConfig) static booleanisValidAbsoluteUrl(String url) static booleanisValidRelativeUrl(String url) static Stringstatic org.apache.commons.lang3.tuple.Pair<String, List<org.apache.commons.lang3.tuple.Pair<String, String>>> splitQueryParameters(String url, boolean htmlEncodeParameters) static StringurlDecodeValue(String value) static StringurlEncodeValue(String value)
-
Field Details
-
HTTP_HEADER_X_FORWARDED_FOR
- See Also:
-
HTTP_HEADER_X_ORIGINAL_FORWARDED_FOR
- See Also:
-
HTTP_HEADER_X_SIMULATED_FORWARDED_FOR
- See Also:
-
HTTP_HEADER_X_REAL_IP
- See Also:
-
HTTP_REMOTE_USER
- See Also:
-
MEDIA_TYPE_SOAP_12
- See Also:
-
HTTP_BASIC
- See Also:
-
HTTP_HEADER_SEC_FETCH_MODE
- See Also:
-
SEC_FETCH_MODE_CORS
- See Also:
-
HTTP_HEADER_SEC_FETCH_SITE
- See Also:
-
SEC_FETCH_SITE_CROSS_SITE
- See Also:
-
COOKIE_SAME_SITE
- See Also:
-
COOKIE_SAME_SITE_NONE
- See Also:
-
COOKIE_SAME_SITE_LAX
- See Also:
-
COOKIE_SAME_SITE_STRICT
- See Also:
-
COOKIE_SAME_SITE_DYNAMIC
- See Also:
-
CACHE_CONTROL_NO_CACHE
- See Also:
-
PRAGMA_NO_CACHE
- See Also:
-
CACHE_CONTROL_MAX_AGE
- See Also:
-
-
Method Details
-
getHeader
-
getParameter
-
getCookie
-
deduplicateSetCookie
-
cookiesToStrings
-
cookieToString
-
getAny
-
getUserAgent
-
getClientIp
-
getClientIp
-
getGatewayIp
-
getGatewayIps
-
getGatewayIp
-
getClientIps
public static String[] getClientIps(jakarta.servlet.http.HttpServletRequest request, boolean tagged) -
getServiceContext
-
getOrigin
-
getOriginOrReferer
-
getReferer
-
addCookies
public static void addCookies(jakarta.servlet.http.HttpServletResponse response, List<jakarta.servlet.http.Cookie> cookies) -
getUrlWithQuery
-
urlEncodeValue
-
urlDecodeValue
-
appendQueryParameters
-
splitQueryParameters
-
removeQueryParameters
-
createCookie
-
getCookieSameSite
-
getSameSite
- Parameters:
isSameSite- e.g. result of isSameSite(URI, URI)- Returns:
- sameSite flag - has to be NONE if RPs that are cross site to XTB, STRICT if they are same site (LAX does not work in the former case for SAML posts, and is not as restrictive as possible in the latter case)
-
isSameSiteDynamic
- Parameters:
sameSiteConfig-- Returns:
- true if the config is null or has the special XTB value Dynamic
-
isSameSite
- Returns:
- true if URIs are not null, absolute, and same site (same site and same scheme, port does not matter)
- See Also:
-
getSite
Site extraction based on InternetDomainName, returns the full host name if it cannot be extracted (e.g. for localhost, localdomain)- Returns:
- site of URI with the restriction above or null if it cannot be extracted
- See Also:
-
getValidatedUri
-
getUrlHost
-
isValidAbsoluteUrl
-
isValidRelativeUrl
-
getAbsoluteUrl
-
getValidRefererWithoutPath
-
getValidOrigin
-
isNullOrigin
-
getValidOrigin
-
isCorsRequest
public static boolean isCorsRequest(jakarta.servlet.http.HttpServletRequest request) -
isCrossSiteRequest
-
addCacheHeaders
public static void addCacheHeaders(jakarta.servlet.http.HttpServletResponse response, int maxAgeSecs, String etag, Instant lastModified, Instant now) "etag" must contain leading and trailing quotes- See Also:
-
isCached
public static boolean isCached(String etag, String ifNoneMatch, Instant cacheTime, String ifModifiedSince) Returns true if the resource has not been modified based on the browser headers If-None-Match/If-Modified-Since. "etag" must contain leading and trailing quotes- See Also:
-
isAllowedOriginOrReferer
public static boolean isAllowedOriginOrReferer(Collection<String> allowedUrls, String originOrReferer, String validatedOriginOrReferer) Validate origin/referer against allow list.- Parameters:
allowedUrls- allowed URLs (AC whitelist etc.)originOrReferer- original URL from requestvalidatedOriginOrReferer- optional validated variant fromgetValidOriginorgetValidatedUri- Returns:
- true if the URL is in the allowed list, ignoring the path (which origin would not have, and for referer we do not care about).
-
isAllowedOrigin
-
isAllowedReferer
public static boolean isAllowedReferer(Collection<Collection<String>> allowedUrlSets, String referer) -
getBasicAuthorizationHeader
-
getBearerAuthorizationHeader
-