class OAuthAuthorityUtils {

    public static final String extractHeaderToken(HttpServletRequest request) {
        Enumeration<String> headers = request.getHeaders(OAuthAuthorityConsts.AUTH_HEADER);
        while (headers.hasMoreElements()) {
            // typically there is only one (most servers enforce that)
            String value = headers.nextElement();
            if ((value.toLowerCase().startsWith(OAuthAuthorityConsts.BEARER_TYPE))) {
                String authHeaderValue = value.substring(OAuthAuthorityConsts.BEARER_TYPE.length()).trim();
                int commaIndex = authHeaderValue.indexOf(',');
                if (commaIndex > 0) {
                    authHeaderValue = authHeaderValue.substring(0, commaIndex);
                }
                return authHeaderValue;
            }
        }

        return null;
    }

    private  OAuthAuthorityUtils();

}