Package org.pac4j.core.context
Class WebContextHelper
- java.lang.Object
-
- org.pac4j.core.context.WebContextHelper
-
- All Implemented Interfaces:
HttpConstants
public final class WebContextHelper extends java.lang.Object implements HttpConstants
A helper for the web context.- Since:
- 1.8.1
- Author:
- Jerome Leleu
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.pac4j.core.context.HttpConstants
HttpConstants.HTTP_METHOD
-
-
Field Summary
-
Fields inherited from interface org.pac4j.core.context.HttpConstants
ACCEPT_HEADER, ACCESS_CONTROL_ALLOW_CREDENTIALS_HEADER, ACCESS_CONTROL_ALLOW_HEADERS_HEADER, ACCESS_CONTROL_ALLOW_METHODS_HEADER, ACCESS_CONTROL_ALLOW_ORIGIN_HEADER, ACCESS_CONTROL_EXPOSE_HEADERS_HEADER, ACCESS_CONTROL_MAX_AGE_HEADER, AJAX_HEADER_NAME, AJAX_HEADER_VALUE, APPLICATION_FORM_ENCODED_HEADER_VALUE, APPLICATION_JSON, AUTHENTICATE_HEADER, AUTHORIZATION_HEADER, BAD_REQUEST, BASIC_HEADER_PREFIX, BEARER_HEADER_PREFIX, CONTENT_TYPE_HEADER, CREATED, DEFAULT_CONNECT_TIMEOUT, DEFAULT_HTTP_PORT, DEFAULT_HTTPS_PORT, DEFAULT_READ_TIMEOUT, DIGEST_HEADER_PREFIX, FACES_PARTIAL_AJAX_PARAMETER, FORBIDDEN, FOUND, HTML_CONTENT_TYPE, LOCATION_HEADER, NO_CONTENT, OK, SCHEME_HTTP, SCHEME_HTTPS, SEE_OTHER, TEMPORARY_REDIRECT, UNAUTHORIZED
-
-
Constructor Summary
Constructors Constructor Description WebContextHelper()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.String
createCookieHeader(Cookie cookie)
Custom method for adding cookie because the servlet-api version doesn't support SameSite attributes.static Cookie
getCookie(java.util.Collection<Cookie> cookies, java.lang.String name)
Get a specific cookie by its name.static Cookie
getCookie(WebContext context, java.lang.String name)
Get a specific cookie by its name.static boolean
isDelete(WebContext context)
Whether it is a DELETE request.static boolean
isGet(WebContext context)
Whether it is a GET request.static boolean
isHttp(WebContext context)
Whether the request is HTTP.static boolean
isHttps(WebContext context)
Whether the request is HTTPS.static boolean
isHttpsOrSecure(WebContext context)
Whether the request is HTTPS or secure.static boolean
isPatch(WebContext context)
Whether it is a PATCH request.static boolean
isPost(WebContext context)
Whether it is a POST request.static boolean
isPut(WebContext context)
Whether it is a PUT request.
-
-
-
Method Detail
-
getCookie
public static Cookie getCookie(java.util.Collection<Cookie> cookies, java.lang.String name)
Get a specific cookie by its name.- Parameters:
cookies
- provided cookiesname
- the name of the cookie- Returns:
- the cookie
-
getCookie
public static Cookie getCookie(WebContext context, java.lang.String name)
Get a specific cookie by its name.- Parameters:
context
- the current web contextname
- the name of the cookie- Returns:
- the cookie
-
isGet
public static boolean isGet(WebContext context)
Whether it is a GET request.- Parameters:
context
- the web context- Returns:
- whether it is a GET request
-
isPost
public static boolean isPost(WebContext context)
Whether it is a POST request.- Parameters:
context
- the web context- Returns:
- whether it is a POST request
-
isPut
public static boolean isPut(WebContext context)
Whether it is a PUT request.- Parameters:
context
- the web context- Returns:
- whether it is a PUT request
-
isPatch
public static boolean isPatch(WebContext context)
Whether it is a PATCH request.- Parameters:
context
- the web context- Returns:
- whether it is a PATCH request
-
isDelete
public static boolean isDelete(WebContext context)
Whether it is a DELETE request.- Parameters:
context
- the web context- Returns:
- whether it is a DELETE request
-
isHttpsOrSecure
public static boolean isHttpsOrSecure(WebContext context)
Whether the request is HTTPS or secure.- Parameters:
context
- the current web context- Returns:
- whether the request is HTTPS or secure
-
isHttp
public static boolean isHttp(WebContext context)
Whether the request is HTTP.- Parameters:
context
- the current web context- Returns:
- whether the request is HTTP
-
isHttps
public static boolean isHttps(WebContext context)
Whether the request is HTTPS.- Parameters:
context
- the current web context- Returns:
- whether the request is HTTPS
-
createCookieHeader
public static java.lang.String createCookieHeader(Cookie cookie)
Custom method for adding cookie because the servlet-api version doesn't support SameSite attributes. Sets the default SameSite policy to lax which is what most browsers do if the cookie doesn't specify a SameSite policy.- Parameters:
cookie
- pac4j Cookie object
-
-