Class HeaderUtils


  • public class HeaderUtils
    extends Object

    Created by Jeff Gaynor
    on 8/16/22 at 5:12 PM

    • Constructor Detail

      • HeaderUtils

        public HeaderUtils()
    • Method Detail

      • getAuthHeader

        public static List<String> getAuthHeader​(javax.servlet.http.HttpServletRequest request,
                                                 String type)
        This gets the tokens from the authorization header. There are several types and it is possible to have several values passed in, so this returns an array of string rather than a single value. A downside with passing along several values this way is there is no way to disambiguate them, e.g. a client id from a client secret. If there is no authorization header or there are no tokens of the stated type, the returned value is an empty list.
        Parameters:
        request -
        type - The type of token, e.g. "Bearer" or "Basic"
        Returns:
      • hasBasicHeader

        public static boolean hasBasicHeader​(javax.servlet.http.HttpServletRequest request)
      • hasBearerHeader

        public static boolean hasBearerHeader​(javax.servlet.http.HttpServletRequest request)
      • getBasicHeader

        public static String getBasicHeader​(javax.servlet.http.HttpServletRequest request)
        This is the header itself that is base 64 encoded. To get the parsed header, use getCredentialsFromHeaders(HttpServletRequest)
        Parameters:
        request -
        Returns:
      • getBearerAuthHeader

        public static String getBearerAuthHeader​(javax.servlet.http.HttpServletRequest request)
      • throwException

        protected static void throwException​(String message)
      • headerToJSON

        public static net.sf.json.JSONObject headerToJSON​(javax.servlet.http.HttpServletRequest httpServletRequest)
      • headerToJSON

        public static net.sf.json.JSONObject headerToJSON​(javax.servlet.http.HttpServletRequest httpServletRequest,
                                                          List<String> filter)
        Takes the request and converts it to JSON, normalizing the header names to lower case. Any name on the filter list is omitted. Note that the filter names are assumed to be lower case. This puts single values as strings and aggregates as arrays of strings. Used in OA4MP!
        Parameters:
        httpServletRequest -
        filter -
        Returns:
      • getFirstParameterValue

        public static String getFirstParameterValue​(javax.servlet.http.HttpServletRequest request,
                                                    String key)
        Gets the first parameter value for the given key
        Parameters:
        request -
        key -
        Returns:
      • getFirstParameters

        public static Map<String,​String> getFirstParameters​(javax.servlet.http.HttpServletRequest req)
        Utility to extract all of the parameters from a request. Since the parameters are all string arrays, this takes a little finagling. Generally we do not support multiple values for parameters, so taking the first is reasonable.
        Parameters:
        req -
        Returns: