package com.perforce.workspace.tjuricek.p4oauth.util; import com.perforce.workspace.tjuricek.p4oauth.config.P4OAuthConfig; import javax.servlet.http.HttpServletRequest; import java.util.Optional; /** * A bunch of additional "query methods" we add to the HttpServletRequest via * the HttpServletRequestHelper wrapping object. */ public interface RequestQueryUtils { HttpServletRequest getHttpServletRequest(); P4OAuthConfig getConfig(); /** * Return true if the wrapped request has the indicated method. * * @param method The method name, case-sensitive */ default boolean hasMethod(String method) { return getHttpServletRequest().getMethod().equals(method); } default boolean pathStartsWith(String testPath) { String context = getConfig().getContextRoot(); if (context != null) { testPath = context + testPath; } return getHttpServletRequest().getPathInfo().startsWith(testPath); } /** * Returns true if the wrapped request has the specified parameter with * the indicated string value. * * @param key The parameter name, case-sensitive * @param value The paramter value, case-sensitive */ default boolean paramEquals(String key, String value) { return getParam(key).flatMap(v -> Optional.of(value.equals(v))).orElse(false); } /** * Returns true if the indicated parameter is not empty. * * @param key The parameter name, case-sensitive */ default boolean paramNotEmpty(String key){ return getParam(key).flatMap(v -> Optional.of(!v.isEmpty())).orElse(false); } /** * Fetches the parameter value, but wraps it in an Optional for easier * processing. * * @see javax.servlet.http.HttpServletRequest#getParameter(String) * * @param key The parameter name, case-sensitive */ default Optional<String> getParam(String key) { String param = getHttpServletRequest().getParameter(key); if (param == null) { return Optional.empty(); } else { return Optional.of(param); } } /** * Fetches the header value, but wraps it in an Optional for easier * processing. * * @see javax.servlet.http.HttpServletRequest#getHeader(String) * * @param key The parameter name, case-sensitive */ default Optional<String> getHeader(String key) { String param = getHttpServletRequest().getHeader(key); if (param == null) { return Optional.empty(); } else { return Optional.of(param); } } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#2 | 9095 | tjuricek | Added some basic test data and renamed "workspace" to "workshop" in package name | ||
#1 | 9089 | tjuricek |
Moving some code that worked via some manual validation to the workshop. This just implements a basic code authorization grant scheme. Automated tests are forthcoming, awating some gradle plugin work that should sit outside of this project. |