|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.jalios.jcms.HttpUtil
public class HttpUtil
This class contains a set of static utility methods for validation, encoding and decoding of http and html input/output.
As of current implementation, it is mainly a facade in front the OWASP ESAPI library.
Field Summary | |
---|---|
static String |
ALPHANUM_REGEX
Regular expression suitable for use in getStringParameter(HttpServletRequest, String, String, String) . |
static String |
CLASSNAME_REGEX
Regular expression suitable for use in getStringParameter(HttpServletRequest, String, String, String) . |
static String |
CSRF_TOKEN_HEADER_NAME
HTTP Header name from which CSRF token to be validated can be retrieved |
static String |
CSRF_TOKEN_MEMBER_EXTRADBDATA
ExtraDBData attribute name used to store the current and expected value of the CSRF token. |
static String |
CSRF_TOKEN_PARAMETER_NAME
Parameter name from which CSRF token to be validated can be retrieved |
static String |
CSRF_TOKEN_SESSION_ATTRIBUTE
Session attribute name used to store the current and expected value of the CSRF token. |
static String |
CSRF_TOKEN_TIME_MEMBER_EXTRADBDATA
ExtraDBData attribute name used to store the time at which member csrf token was saved (epoch time). |
static String |
DATAID_REGEX
Regular expression suitable for use in getStringParameter(HttpServletRequest, String, String, String) . |
static String |
PROPERTYNAME_REGEX
Regular expression suitable for use in getStringParameter(HttpServletRequest, String, String, String) . |
static String |
REVISION
|
static String |
TEMPLATEUSAGE_REGEX
Regular expression suitable for use in getStringParameter(HttpServletRequest, String, String, String) . |
Fields inherited from interface com.jalios.util.JaliosConstants |
---|
CRLF, MILLIS_IN_ONE_DAY, MILLIS_IN_ONE_HOUR, MILLIS_IN_ONE_MINUTE, MILLIS_IN_ONE_MONTH, MILLIS_IN_ONE_SECOND, MILLIS_IN_ONE_WEEK, MILLIS_IN_ONE_YEAR |
Constructor Summary | |
---|---|
HttpUtil()
|
Method Summary | ||
---|---|---|
static void |
addCookie(javax.servlet.http.HttpServletResponse response,
javax.servlet.http.Cookie cookie)
Add a cookie to the response. |
|
static boolean |
checkCSRF(javax.servlet.http.HttpServletRequest request)
Check if the specified request is valid against CSRF attack. |
|
static void |
clearMemberCSRFToken(Member member)
Remove CSRF token of the specified member |
|
static String |
encodeForHTML(String input)
Encode data for use in HTML using HTML entity encoding |
|
static String |
encodeForHTMLAttribute(String input)
Encode data for use in HTML attributes. |
|
static String |
encodeForJavaScript(String input)
Encode data for insertion inside a data value or function argument in JavaScript. |
|
static String |
encodeForURL(String input)
Encode for use in a URL. |
|
static String |
encodeForXML(String input)
Encode data for use in an XML element. |
|
static String |
encodeForXMLAttribute(String input)
Encode data for use in an XML attribute. |
|
static String |
getAlphaNumParameter(javax.servlet.http.HttpServletRequest request,
String parameterName,
String defaultValue)
Retrieve a String value from specified HTTP request parameter. |
|
static boolean |
getBooleanParameter(javax.servlet.http.HttpServletRequest request,
String parameterName,
boolean defaultValue)
Retrieve a boolean value from specified HTTP request parameter. |
|
static Category |
getCategoryParameter(javax.servlet.http.HttpServletRequest request,
String parameterName)
Retrieve a Category from its id received in parameter. |
|
static String |
getChooserParameter(javax.servlet.http.HttpServletRequest request,
String parameterName)
Retrieve a verified targetInput, targetLabel or other target value used by JCMS Choosers inside javascript code. |
|
static long |
getCSRFMemberTokenMaxAge()
Retrieve the duration in milliseconds above which a member token is considered invalid. |
|
static String |
getCSRFToken(javax.servlet.http.HttpServletRequest request)
Retrieve the value of CSRF token (both session & member) for the current request. |
|
static String |
getCurrentCSRFToken(javax.servlet.http.HttpServletRequest request)
Retrieve the current valid CSRF Token expected on critical requests of the current session. |
|
static String |
getCurrentCSRFToken(javax.servlet.http.HttpSession session)
Retrieve the current valid CSRF Token expected on critical requests of the current session. |
|
static String |
getCurrentMemberCSRFToken(Member member)
Retrieve the current valid CSRF Token expected on critical requests of the specified member. |
|
static String |
getDataIdParameter(javax.servlet.http.HttpServletRequest request,
String parameterName)
Retrieve a Data id from parameter. |
|
static
|
getDataListParameter(javax.servlet.http.HttpServletRequest request,
String parameterName,
Class<T> clazz)
Retrieve a list of Data from ids received in only one value of the parameter (seperated with spaces or coma). |
|
static Data |
getDataParameter(javax.servlet.http.HttpServletRequest request,
String parameterName)
Retrieve a Data from its id received in parameter. |
|
static
|
getDataParameter(javax.servlet.http.HttpServletRequest request,
String parameterName,
Class<T> clazz)
Retrieve a typed Data from its id received in parameter. |
|
static Date |
getDateParameter(javax.servlet.http.HttpServletRequest request,
String parameterName,
DateFormat dateFormat,
Date defaultValue)
Retrieve a Date value from specified HTTP request parameter. |
|
static Date |
getDateParameter(javax.servlet.http.HttpServletRequest request,
String parameterName,
String dateLanguage,
Date defaultValue)
Retrieve a Date (date only) value from specified HTTP request parameter. |
|
static Date |
getDateTimeParameter(javax.servlet.http.HttpServletRequest request,
String parameterName,
String dateLanguage,
Date defaultValue)
Retrieve a Date (date and time) value from specified HTTP request parameter. |
|
static double |
getDoubleParameter(javax.servlet.http.HttpServletRequest request,
String parameterName,
double defaultValue)
Retrieve a double value from specified HTTP request parameter. |
|
static Group |
getGroupParameter(javax.servlet.http.HttpServletRequest request,
String parameterName)
Retrieve a Group from its id received in parameter. |
|
static int |
getIntParameter(javax.servlet.http.HttpServletRequest request,
String parameterName,
int defaultValue)
Retrieve an integer value from specified HTTP request parameter. |
|
static long |
getLongParameter(javax.servlet.http.HttpServletRequest request,
String parameterName,
long defaultValue)
Retrieve a long value from specified HTTP request parameter. |
|
static Member |
getMemberParameter(javax.servlet.http.HttpServletRequest request,
String parameterName)
Retrieve a Member from its id received in parameter. |
|
static Publication |
getPublicationParameter(javax.servlet.http.HttpServletRequest request,
String parameterName)
Retrieve a Publication from its id received in parameter. |
|
static String |
getStringEnumParameter(javax.servlet.http.HttpServletRequest request,
String parameterName,
String defaultValue,
String... possibleValues)
Retrieve a String value from specified HTTP request parameter. |
|
static String |
getStringParameter(javax.servlet.http.HttpServletRequest request,
String parameterName,
String defaultValue,
String regex)
Retrieve a String value from specified HTTP request parameter. |
|
static String[] |
getStringParameterValues(javax.servlet.http.HttpServletRequest request,
String parameterName,
String regex)
Retrieve array of String values from specified HTTP request parameter. |
|
static String |
getUntrustedStringParameter(javax.servlet.http.HttpServletRequest request,
String parameterName,
String defaultValue)
Retrieve any String value from the specified HTTP request parameter. |
|
static String |
getUrlWithCSRFToken(String url,
javax.servlet.http.HttpServletRequest request,
boolean escapeAmpersand)
Adds the current CSRF token to the specified URL and returns it. |
|
static String |
getValidHttpUrl(javax.servlet.http.HttpServletRequest request,
String parameterName)
Retrieve a verified URL parameter value. |
|
static Workspace |
getWorkspaceParameter(javax.servlet.http.HttpServletRequest request,
String parameterName)
Retrieve a Workspace from its id received in parameter. |
|
static boolean |
hasParameter(javax.servlet.http.HttpServletRequest request,
String parameterName)
Check if a parameter was received in the specified request. |
|
static void |
initializeCSRFToken(javax.servlet.http.HttpSession session)
Initialize a new CSRF Token for the current session (if any) |
|
static void |
initializeMemberCSRFToken(Member member,
javax.servlet.http.HttpServletRequest request)
Initialize the CSRF Token for the specified member from the current CSRF token of the request (if any) |
|
static boolean |
isCSRFEnabled()
Check if CSRF attack prevention is enabled for site. |
|
static boolean |
isCSRFMemberTokenAllowed()
Check if CSRF token should be allowed through different session in order to allow a submition after session expiration. |
|
static boolean |
isValidDisplayServletPath(String displayServletPath)
Check if the specified path is valid for use by the display servlet |
|
static boolean |
isValidHttpUrl(String url)
Check that the specified URL (absolute or relative) is a valid URL authorized for use in redirection. |
|
static String |
validateHttpUrl(String url)
Validate an URL and returns it. |
|
static String |
validateString(String value,
String regex)
Validate a String value against specified regular expression. |
|
static String[] |
validateStringValues(String[] values,
String regex)
Validate each value in the specified array of String values against specified regular expression. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String REVISION
public static final String DATAID_REGEX
getStringParameter(HttpServletRequest, String, String, String)
.
Match all characters which could be used as a JCMS data id (JStore/JcmsDB), this includes virtual id such as "$channel.root-cat" : . Beware that this regex does not validate that the id matchs a valid data.
public static final String ALPHANUM_REGEX
getStringParameter(HttpServletRequest, String, String, String)
.
Match all alpha-numeric characters and the underscore (_ as in perl regex) and the dash (-): .
public static final String CLASSNAME_REGEX
getStringParameter(HttpServletRequest, String, String, String)
.
Match Java class names, such as com.jalios.jcms.Content
.
public static final String PROPERTYNAME_REGEX
getStringParameter(HttpServletRequest, String, String, String)
.
Match JCMS property names, such as $channel.root-category
, some.important-property.foo_bar22/zig
.
public static final String TEMPLATEUSAGE_REGEX
getStringParameter(HttpServletRequest, String, String, String)
.
Match JCMS template usage name, such as box
, full
, front
, query
, ...
public static final String CSRF_TOKEN_SESSION_ATTRIBUTE
Do not use directly, instead use initializeCSRFToken(HttpSession)
.
public static final String CSRF_TOKEN_MEMBER_EXTRADBDATA
Do not use directly, instead use initializeMemberCSRFToken(Member, HttpServletRequest)
.
public static final String CSRF_TOKEN_TIME_MEMBER_EXTRADBDATA
Do not use directly, instead use initializeMemberCSRFToken(Member, HttpServletRequest)
.
public static final String CSRF_TOKEN_PARAMETER_NAME
public static final String CSRF_TOKEN_HEADER_NAME
Constructor Detail |
---|
public HttpUtil()
Method Detail |
---|
public static String encodeForXML(String input)
The use of a real XML parser is strongly encouraged. However, in the hopefully rare case that you need to make sure that data is safe for inclusion in an XML document and cannot use a parse, this method provides a safe mechanism to do so.
input
- the text to encode for XML
public static String encodeForXMLAttribute(String input)
The use of a real XML parser is highly encouraged. However, in the hopefully rare case that you need to make sure that data is safe for inclusion in an XML document and cannot use a parse, this method provides a safe mechanism to do so.
input
- the text to encode for use as an XML attribute
public static String encodeForHTML(String input)
Note that the following characters: 00-08, 0B-0C, 0E-1F, and 7F-9F
cannot be used in HTML.
input
- the text to encode for HTML
public static String encodeForHTMLAttribute(String input)
input
- the text to encode for an HTML attribute
public static String encodeForJavaScript(String input)
input
- the text to encode for JavaScript
public static String encodeForURL(String input)
input
- the text to encode for use in a URL
public static String getValidHttpUrl(javax.servlet.http.HttpServletRequest request, String parameterName)
Example :
String redirect = getValidHttpUrl(request, "redirect");
request
- the request from which the parameter will be readparameterName
- the name of the HTTP parameter to be retrieved
public static String validateHttpUrl(String url)
Example :
String redirect = validateHttpUrl("http://www.example.com/");
url
- the value to be verified
public static boolean isValidHttpUrl(String url)
As of current implementation, the following behavior applies :
All URLs are accepted (NO verification performed) when JCMS propery
channel.security.validate-redirect
is set to false (default is true).
Otherwise, the following rules are required :
JCMSRedirectURL
configured in ESAPI.properties
(prevent HTTPSplitting)channel.security.authorized-redirect.*
are accepted
You can enable TRACE
logging on this class for detailed information of validation being performed.
<logger name="com.jalios.jcms.HttpUtil"> <level value="TRACE" /> </logger>
url
- the URL to check
public static boolean isValidDisplayServletPath(String displayServletPath)
displayServletPath
- a servlet path such as "/jcms/c_42/foo-bar"
public static String getChooserParameter(javax.servlet.http.HttpServletRequest request, String parameterName)
Example :
String targetInput = getChooserParameter("targetInput"); String targetLabel = getChooserParameter("targetLabel");
request
- HttpServletRequest from which parameter must be readparameterName
- the name of the HTTP parameter to be retrieved
public static <T> T getDataParameter(javax.servlet.http.HttpServletRequest request, String parameterName, Class<T> clazz)
Examples :
Portal portal = getDataParameter(request, "portal", Portal.class); SmallNews sm = getDataParameter(request, "id", SmallNews.class);
request
- HttpServletRequest from which parameter must be read, must not be nullparameterName
- the name of the HTTP parameter from which data id will be retrieved, must not be nullclazz
- the expected class of Data
public static <T extends Data> List<T> getDataListParameter(javax.servlet.http.HttpServletRequest request, String parameterName, Class<T> clazz)
Examples :
ListgroupList = getDataListParameter(request, "groups", Portal.class); SmallNews sm = getDataParameter(request, "id", SmallNews.class);
request
- HttpServletRequest from which parameter must be read, must not be nullparameterName
- the name of the HTTP parameter from which data ids will be retrieved, must not be nullclazz
- the expected class of Data
public static Data getDataParameter(javax.servlet.http.HttpServletRequest request, String parameterName)
Example :
Data data = getDataParameter(request, "id");
request
- HttpServletRequest from which parameter must be read, must not be nullparameterName
- the name of the HTTP parameter from which data id will be retrieved, must not be null
public static Workspace getWorkspaceParameter(javax.servlet.http.HttpServletRequest request, String parameterName)
Example :
Workspace ws = getWorkspaceParameter(request, "ws");
request
- HttpServletRequest from which parameter must be read, must not be nullparameterName
- the name of the HTTP parameter from which data id will be retrieved, must not be null
public static Category getCategoryParameter(javax.servlet.http.HttpServletRequest request, String parameterName)
Example :
Category cat = getCategoryParameter(request, "cid");
request
- HttpServletRequest from which parameter must be read, must not be nullparameterName
- the name of the HTTP parameter from which data id will be retrieved, must not be null
public static Publication getPublicationParameter(javax.servlet.http.HttpServletRequest request, String parameterName)
Example :
Publication pub = getPublicationParameter(request, "id");
request
- HttpServletRequest from which parameter must be read, must not be nullparameterName
- the name of the HTTP parameter from which data id will be retrieved, must not be null
public static Member getMemberParameter(javax.servlet.http.HttpServletRequest request, String parameterName)
Example :
Member mbr = getMemberParameter(request, "mbrId");
request
- HttpServletRequest from which parameter must be read, must not be nullparameterName
- the name of the HTTP parameter from which data id will be retrieved, must not be null
public static Group getGroupParameter(javax.servlet.http.HttpServletRequest request, String parameterName)
Example :
Group grp = getGroupParameter(request, "grpId");
request
- HttpServletRequest from which parameter must be read, must not be nullparameterName
- the name of the HTTP parameter from which data id will be retrieved, must not be null
public static boolean hasParameter(javax.servlet.http.HttpServletRequest request, String parameterName)
Example :
if (hasParameter(request, "opRefresh")) { //... }This method is the same as doing :
String value = getUntrustedStringParameter(request, parameterName); // request.getParameter(parameterName); return value != null;
request
- HttpServletRequest from which parameter must be read, must not be nullparameterName
- name of the HTTP parameter from which value will be read, must not be null
public static boolean getBooleanParameter(javax.servlet.http.HttpServletRequest request, String parameterName, boolean defaultValue)
Important remark regarding behavior on missing/invalid parameter :
false
when parameter value contains invalid data (neither "true" nor "false").Util.toBoolean(Object, boolean)
.
request
- HttpServletRequest from which parameter must be read, must not be nullparameterName
- name of the HTTP parameter from which value will be read, must not be nulldefaultValue
- the default value to use if parameter is missing or invalid
public static int getIntParameter(javax.servlet.http.HttpServletRequest request, String parameterName, int defaultValue)
request
- HttpServletRequest from which parameter must be read, must not be nullparameterName
- name of the HTTP parameter from which value will be read, must not be nulldefaultValue
- the default value to use if parameter is missing or invalid
public static long getLongParameter(javax.servlet.http.HttpServletRequest request, String parameterName, long defaultValue)
request
- HttpServletRequest from which parameter must be read, must not be nullparameterName
- name of the HTTP parameter from which value will be read, must not be nulldefaultValue
- the default value to use if parameter is missing, empty or invalid
public static double getDoubleParameter(javax.servlet.http.HttpServletRequest request, String parameterName, double defaultValue)
request
- HttpServletRequest from which parameter must be read, must not be nullparameterName
- name of the HTTP parameter from which value will be read, must not be nulldefaultValue
- the default value to use if parameter is missing, empty or invalid
public static Date getDateTimeParameter(javax.servlet.http.HttpServletRequest request, String parameterName, String dateLanguage, Date defaultValue)
The parameter will be parsed using date format specified in property date-time-format
of the specified language.
request
- HttpServletRequest from which parameter must be read, must not be nullparameterName
- name of the HTTP parameter from which value will be parsed, must not be nulldateLanguage
- the language in which the received parameter will be parseddefaultValue
- the default value to use if parameter is missing, empty or invalid
Channel.getDateTimeFormat(String)
public static Date getDateParameter(javax.servlet.http.HttpServletRequest request, String parameterName, String dateLanguage, Date defaultValue)
The parameter will be parsed using date format specified in property date-format
of the specified language.
request
- HttpServletRequest from which parameter must be read, must not be nullparameterName
- name of the HTTP parameter from which value will be parsed, must not be nulldateLanguage
- the language in which the received parameter will be parseddefaultValue
- the default value to use if parameter is missing, empty or invalid
Channel.getDateFormat(String)
public static Date getDateParameter(javax.servlet.http.HttpServletRequest request, String parameterName, DateFormat dateFormat, Date defaultValue)
The parameter will be parsed using the specified date format
request
- HttpServletRequest from which parameter must be read, must not be nullparameterName
- name of the HTTP parameter from which value will be parsed, must not be nulldateFormat
- the DateFormat to use to parse the date parameter, must not be nulldefaultValue
- the default value to use if parameter is missing, empty or invalid
Channel.getDateFormat(String)
public static String getStringEnumParameter(javax.servlet.http.HttpServletRequest request, String parameterName, String defaultValue, String... possibleValues)
The parameter value must match one of the possible value specified, otherwise default value is used.
Example, read the "align" parameter expecting only values from authorized HTML table align :
getStringEnumParameter(request, "align", "left", new String[] { "left", "center", "right" });Verification is case sensitive.
request
- HttpServletRequest from which parameter must be read, must not be nullparameterName
- name of the HTTP parameter from which value will be read, must not be nulldefaultValue
- the default value to use if parameter is missing or invalidpossibleValues
- the values authorized, must not be null
public static String getAlphaNumParameter(javax.servlet.http.HttpServletRequest request, String parameterName, String defaultValue)
The parameter value must match the alpha numeric regular expression ALPHANUM_REGEX
.
request
- HttpServletRequest from which parameter must be read, must not be nullparameterName
- name of the HTTP parameter from which value will be read, must not be nulldefaultValue
- the default value to use if parameter is missing or invalid
public static String getDataIdParameter(javax.servlet.http.HttpServletRequest request, String parameterName)
Contrary to most get*Parameter
method in HttpUtil, this method
returns an empty string if parameter value was missing, empty or invalid.
Beware that this method will NOT check that the id match an existing or valid data.
Example :
In Java : String id = HttpUtil.getDataIdParameter(request, "id"); In JSP : <input name="id" value="<%= getDataIdParameter("id") %>"/>This method is the same as doing :
String id = HttpUtil.getStringParameter(request, parameterName, "", HttpUtil.DATAID_REGEX);
request
- HttpServletRequest from which parameter must be read, must not be nullparameterName
- the name of the HTTP parameter from which data id will be retrieved, must not be null
public static String getStringParameter(javax.servlet.http.HttpServletRequest request, String parameterName, String defaultValue, String regex)
The parameter value must match the specified regular expression.
You are encouraged to use predefined constants for regular expression :
ALPHANUM_REGEX
for alpha numeric characters (eg FooBar_42
) CLASSNAME_REGEX
for Java class names (eg com.jalios.jcms.Content
)PROPERTYNAME_REGEX
for JCMS property key (eg channel.data-write.enabled
)TEMPLATEUSAGE_REGEX
for JCMS template usage name (eg box
, full
, front
, query
)
request
- HttpServletRequest from which parameter must be read, must not be nullparameterName
- name of the HTTP parameter from which value will be read, must not be nulldefaultValue
- the default value to use if parameter is missing or invalidregex
- the regular expression the string is expected to match, must not be null
public static String validateString(String value, String regex)
You are encouraged to use predefined constants for regular expression :
ALPHANUM_REGEX
for alpha numeric characters (eg FooBar_42
) CLASSNAME_REGEX
for Java class names (eg com.jalios.jcms.Content
)PROPERTYNAME_REGEX
for JCMS property key (eg channel.data-write.enabled
)TEMPLATEUSAGE_REGEX
for JCMS template usage name (eg box
, full
, front
, query
)
value
- value to validateregex
- the regular expression the string is expected to matchn, must not be null
public static String[] getStringParameterValues(javax.servlet.http.HttpServletRequest request, String parameterName, String regex)
The parameter values must match the specified regular expression.
You are encouraged to use predefined constants for regular expression :
ALPHANUM_REGEX
for alpha numeric characters (eg FooBar_42
) CLASSNAME_REGEX
for Java class names (eg com.jalios.jcms.Content
)PROPERTYNAME_REGEX
for JCMS property key (eg channel.data-write.enabled
)TEMPLATEUSAGE_REGEX
for JCMS template usage name (eg box
, full
, front
, query
)
request
- HttpServletRequest from which parameter must be read, must not be nullparameterName
- name of the HTTP parameter from which value will be read, must not be nullregex
- the regular expression strings are expected to match, must not be null
public static String[] validateStringValues(String[] values, String regex)
You are encouraged to use predefined constants for regular expression :
ALPHANUM_REGEX
for alpha numeric characters (eg FooBar_42
) CLASSNAME_REGEX
for Java class names (eg com.jalios.jcms.Content
)PROPERTYNAME_REGEX
for JCMS property key (eg channel.data-write.enabled
)TEMPLATEUSAGE_REGEX
for JCMS template usage name (eg box
, full
, front
, query
)
values
- the values to validateregex
- the regular expression strings are expected to match, must not be null
public static String getUntrustedStringParameter(javax.servlet.http.HttpServletRequest request, String parameterName, String defaultValue)
This method should be AVOIDED AT ALL COST, and used only on last restort, make sure you PROPERLY ENCODE the returned value in the output..
request
- HttpServletRequest from which parameter must be read, must not be nullparameterName
- name of the HTTP parameter from which value will be read, must not be nulldefaultValue
- the default value to use if parameter is missing
public static void addCookie(javax.servlet.http.HttpServletResponse response, javax.servlet.http.Cookie cookie)
If the JCMS property channel.security.check-cookie.enabled
is
set to false, this method will simply use the underlying JavaEE implementation of
HttpServletResponse.addCookie(Cookie)
.
If property is set to true (which is the default behavior), this method will provide additionnal security check :
Validator.HTTPCookieName= Validator.HTTPCookieValue=
HttpUtilities.ForceHttpOnlyCookies=true HttpUtilities.ForceSecureCookies=true
response
- the HttpServletResponse in which to send the cookiecookie
- the cookie to send in the responsepublic static boolean isCSRFEnabled()
public static String getCSRFToken(javax.servlet.http.HttpServletRequest request)
request
- the curren HttpServletRequest
public static void initializeCSRFToken(javax.servlet.http.HttpSession session)
session
- the HttpSession in which CSRF token is addedpublic static String getCurrentCSRFToken(javax.servlet.http.HttpSession session)
session
- the current HttpSession
public static String getCurrentCSRFToken(javax.servlet.http.HttpServletRequest request)
request
- the curren HttpServletRequest
public static boolean isCSRFMemberTokenAllowed()
Initialized from property channel.security.csrf.allow-token-through-session
If enabled, security is decreased as it allows more time for an attacker to retrieve the token, but usability increase as the end user is allowed to submit a form after session expiration.
public static long getCSRFMemberTokenMaxAge()
Initialized from property channel.security.csrf.member-token-max-age
public static void initializeMemberCSRFToken(Member member, javax.servlet.http.HttpServletRequest request)
member
- the logged Memberrequest
- the current HttpServletRequestpublic static void clearMemberCSRFToken(Member member)
member
- the member for which CSRF token should be removedpublic static String getCurrentMemberCSRFToken(Member member)
This method must be used only if "token through session" option has been enabled.
member
- the current Member
public static boolean checkCSRF(javax.servlet.http.HttpServletRequest request)
request
- the HttpServletRequest to validate
public static String getUrlWithCSRFToken(String url, javax.servlet.http.HttpServletRequest request, boolean escapeAmpersand)
If CSRF is disable, URL is returned as is.
url
- the URL to completerequest
- the current request used to find the current CSRF tokenescapeAmpersand
- will use "&" if true, "&" if false
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |