Package edu.uiuc.ncsa.security.servlet
Class HeaderUtils
- java.lang.Object
-
- edu.uiuc.ncsa.security.servlet.HeaderUtils
-
public class HeaderUtils extends Object
Created by Jeff Gaynor
on 8/16/22 at 5:12 PM
-
-
Field Summary
Fields Modifier and Type Field Description static String
BASIC_HEADER
static String
BEARER_HEADER
static int
ID_INDEX
static int
SECRET_INDEX
-
Constructor Summary
Constructors Constructor Description HeaderUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static List<String>
getAuthHeader(javax.servlet.http.HttpServletRequest request, String type)
This gets the tokens from the authorization header.static String
getBasicHeader(javax.servlet.http.HttpServletRequest request)
This is the header itself that is base 64 encoded.static String
getBearerAuthHeader(javax.servlet.http.HttpServletRequest request)
static String[]
getCredentialsFromHeaders(javax.servlet.http.HttpServletRequest request)
static String[]
getCredentialsFromHeaders(javax.servlet.http.HttpServletRequest request, String type)
static Map<String,String>
getFirstParameters(javax.servlet.http.HttpServletRequest req)
Utility to extract all of the parameters from a request.static String
getFirstParameterValue(javax.servlet.http.HttpServletRequest request, String key)
Gets the first parameter value for the given keystatic Identifier
getIDFromHeaders(javax.servlet.http.HttpServletRequest request)
static String
getSecretFromHeaders(javax.servlet.http.HttpServletRequest request)
static boolean
hasBasicHeader(javax.servlet.http.HttpServletRequest request)
static boolean
hasBearerHeader(javax.servlet.http.HttpServletRequest request)
static net.sf.json.JSONObject
headerToJSON(javax.servlet.http.HttpServletRequest httpServletRequest)
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.protected static void
throwException(String message)
-
-
-
Field Detail
-
BASIC_HEADER
public static final String BASIC_HEADER
- See Also:
- Constant Field Values
-
BEARER_HEADER
public static final String BEARER_HEADER
- See Also:
- Constant Field Values
-
ID_INDEX
public static int ID_INDEX
-
SECRET_INDEX
public static int SECRET_INDEX
-
-
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, usegetCredentialsFromHeaders(HttpServletRequest)
- Parameters:
request
-- Returns:
-
getBearerAuthHeader
public static String getBearerAuthHeader(javax.servlet.http.HttpServletRequest request)
-
getCredentialsFromHeaders
public static String[] getCredentialsFromHeaders(javax.servlet.http.HttpServletRequest request, String type) throws UnsupportedEncodingException
- Throws:
UnsupportedEncodingException
-
getCredentialsFromHeaders
public static String[] getCredentialsFromHeaders(javax.servlet.http.HttpServletRequest request) throws UnsupportedEncodingException
- Throws:
UnsupportedEncodingException
-
getSecretFromHeaders
public static String getSecretFromHeaders(javax.servlet.http.HttpServletRequest request) throws UnsupportedEncodingException
- Throws:
UnsupportedEncodingException
-
getIDFromHeaders
public static Identifier getIDFromHeaders(javax.servlet.http.HttpServletRequest request) throws UnsupportedEncodingException
- Throws:
UnsupportedEncodingException
-
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:
-
-