Package com.google.gwt.user.server
Class Util
java.lang.Object
com.google.gwt.user.server.Util
A bunch of useful methods.
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T extends Annotation>
TgetClassAnnotation(Class<?> clazz, Class<T> annotationClass) Find an instance of the specified annotation, walking up the inheritance tree if necessary.static javax.servlet.http.CookiegetCookie(javax.servlet.http.HttpServletRequest request, String cookieName, boolean allowDuplicates) Retrieves named cookie from supplied request.static booleanisMethodXsrfProtected(Method method, Class<? extends Annotation> xsrfAnnotation, Class<? extends Annotation> noXsrfAnnotation, Class<?> xsrfTokenInterface) Checks if specified method is XSRF protected based on the following logic: Method level annotations override class level annotations.
-
Method Details
-
getClassAnnotation
Find an instance of the specified annotation, walking up the inheritance tree if necessary. Copied fromAnnotationUtil.The super chain is walked first, so if an ancestor superclass has the requested annotation, it will be preferred over a directly implemented interface.
- Type Parameters:
T- Annotation type to search for- Parameters:
clazz- root class to search, may be nullannotationClass- class object of Annotation subclass to search for- Returns:
- the requested annotation or null if none
-
getCookie
public static javax.servlet.http.Cookie getCookie(javax.servlet.http.HttpServletRequest request, String cookieName, boolean allowDuplicates) Retrieves named cookie from supplied request. IfallowDuplicatesis set totrue, method will throwIllegalStateExceptionif duplicate cookies are found, which can be a sign of a cookie overwrite attack.- Parameters:
request- HTTP request to retrieve cookie from.cookieName- Cookie name.allowDuplicates- iftrueduplicate cookies are allowed, otherwiseIllegalStateExceptionis thrown if duplicate cookies are detected.- Returns:
Cookieif specified cookie is present,nullotherwise.- Throws:
IllegalArgumentException- if duplicate cookies are detected.
-
isMethodXsrfProtected
public static boolean isMethodXsrfProtected(Method method, Class<? extends Annotation> xsrfAnnotation, Class<? extends Annotation> noXsrfAnnotation, Class<?> xsrfTokenInterface) Checks if specified method is XSRF protected based on the following logic:- Method level annotations override class level annotations.
- If method is annotated with
xsrfAnnotationthis method returnstrue - If method is annotated with
noXsrfAnnotation, this method returnsfalse. - If class is annotated with
xsrfAnnotationand method is not annotated, this method returnstrue. - If class is annotated with
noXsrfAnnotationand method is not annotated, this method returnsfalse. - If no annotations are present and class has a method with return value
assignable from
xsrfTokenInterface, this method returnstrue. - If no annotations are present this method returns
false.
- See Also:
-