@Override public String getHeader(String name) { return httpRequest.getHeader(name); }
@Override public Map<String, String[]> getParameterMap() { return httpRequest.getParameters(); }
@Override public Enumeration<String> getHeaderNames() { return Collections.enumeration(httpRequest.getHeaders().keySet()); }
private String getJwtResponse(Object httpRequestObject) { String jwtResponse; if (HttpRequest.class.isAssignableFrom(httpRequestObject.getClass())) { HttpRequest httpRequest = (HttpRequest) httpRequestObject; Assert.isTrue(httpRequest.getMethod() == HttpMethod.GET, "Only Http GET method is supported."); jwtResponse = httpRequest.getParameter(JWT_RESPONSE); } else { //This must never happen, if the object request is of HttpServletRequest type the HTTP_SERVLET_REQUEST_WRAPPER_CLASS //must be already loaded and therefore cannot be null. if (HTTP_SERVLET_REQUEST_WRAPPER_CLASS == null) { throw new RuntimeException("DefaultHttpServletRequestWrapper not loaded error occurred while handling httpRequest of type: " + httpRequestObject.getClass().getName()); } Constructor<? extends HttpServletRequestWrapper> ctor = Classes.getConstructor(HTTP_SERVLET_REQUEST_WRAPPER_CLASS, Object.class); HttpServletRequestWrapper httpServletRequestWrapper = Classes.instantiate(ctor, httpRequestObject); HttpMethod method = HttpMethod.fromName(httpServletRequestWrapper.getMethod()); Assert.isTrue(HttpMethod.GET == method, "Only Http GET method is supported."); jwtResponse = httpServletRequestWrapper.getParameter(JWT_RESPONSE); } if (!Strings.hasText(jwtResponse)) { throw new InvalidJwtException(InvalidJwtException.JWT_REQUIRED_ERROR); } return jwtResponse; }
protected RequestLocation[] getRequestLocations(HttpRequest request, boolean addHeaderLocation) { HttpMethod method = request.getMethod(); String contentType = request.getHeader(CONTENT_TYPE_HEADER); List<RequestLocation> requestLocationList = new ArrayList<RequestLocation>(); if (addHeaderLocation) { requestLocationList.add(RequestLocation.HEADER); } EnumSet<HttpMethod> bodyLocationMethods = EnumSet.of(HttpMethod.POST, HttpMethod.DELETE, HttpMethod.PUT); if (bodyLocationMethods.contains(method) && hasContentType(contentType, MediaType.APPLICATION_FORM_URLENCODED_VALUE)) { requestLocationList.add(RequestLocation.BODY); } RequestLocation[] requestLocations = new RequestLocation[requestLocationList.size()]; return requestLocationList.toArray(requestLocations); } }
public AuthenticationRequest createFrom(HttpRequest httpRequest) { String authzHeaderValue = httpRequest.getHeader(AUTHORIZATION_HEADER); String[] schemeAndValue = getSchemeAndValue(authzHeaderValue); if (schemeAndValue == null) { RequestLocation[] requestLocations = getRequestLocations(httpRequest, false); if (requestLocations.length > 0) { return OAuthAuthenticationRequestFactory.INSTANCE.createRequest(httpRequest, requestLocations); } } else { if (schemeAndValue[0].equalsIgnoreCase(BEARER_AUTHENTICATION_SCHEME)) { RequestLocation[] requestLocations = getRequestLocations(httpRequest, true); return OAuthAuthenticationRequestFactory.INSTANCE.createRequest(httpRequest, requestLocations); } if (schemeAndValue[0].equalsIgnoreCase(BASIC_AUTHENTICATION_SCHEME)) { if (hasContentType(httpRequest.getHeader(CONTENT_TYPE_HEADER), MediaType.APPLICATION_FORM_URLENCODED_VALUE)) { Map<String, String[]> parameterMap = httpRequest.getParameters(); if (parameterMap != null && parameterMap.containsKey(GRANT_TYPE_PARAMETER)) { return OAuthAuthenticationRequestFactory.INSTANCE.createTokenRequest(httpRequest); } } return new DefaultBasicApiAuthenticationRequest(httpRequest); } } throw ApiAuthenticationExceptionFactory.newApiAuthenticationException(InvalidAuthenticationException.class); }
@Override public String getMethod() { return httpRequest.getMethod().name(); }
@Override public String getQueryString() { return httpRequest.getQueryParameters(); }
private String getJwtResponse(Object httpRequestObject) { String jwtResponse; if (HttpRequest.class.isAssignableFrom(httpRequestObject.getClass())) { HttpRequest httpRequest = (HttpRequest) httpRequestObject; Assert.isTrue(httpRequest.getMethod() == HttpMethod.GET, "Only Http GET method is supported."); jwtResponse = httpRequest.getParameter(JWT_RESPONSE); } else { //This must never happen, if the object request is of HttpServletRequest type the HTTP_SERVLET_REQUEST_WRAPPER_CLASS //must be already loaded and therefore cannot be null. if (HTTP_SERVLET_REQUEST_WRAPPER_CLASS == null) { throw new RuntimeException("DefaultHttpServletRequestWrapper not loaded error occurred while handling httpRequest of type: " + httpRequestObject.getClass().getName()); } Constructor<? extends HttpServletRequestWrapper> ctor = Classes.getConstructor(HTTP_SERVLET_REQUEST_WRAPPER_CLASS, Object.class); HttpServletRequestWrapper httpServletRequestWrapper = Classes.instantiate(ctor, httpRequestObject); HttpMethod method = HttpMethod.fromName(httpServletRequestWrapper.getMethod()); Assert.isTrue(HttpMethod.GET == method, "Only Http GET method is supported."); jwtResponse = httpServletRequestWrapper.getParameter(JWT_RESPONSE); } if (!Strings.hasText(jwtResponse)) { throw new InvalidJwtException(InvalidJwtException.JWT_REQUIRED_ERROR); } return jwtResponse; }
protected RequestLocation[] getRequestLocations(HttpRequest request, boolean addHeaderLocation) { HttpMethod method = request.getMethod(); String contentType = request.getHeader(CONTENT_TYPE_HEADER); List<RequestLocation> requestLocationList = new ArrayList<RequestLocation>(); if (addHeaderLocation) { requestLocationList.add(RequestLocation.HEADER); } EnumSet<HttpMethod> bodyLocationMethods = EnumSet.of(HttpMethod.POST, HttpMethod.DELETE, HttpMethod.PUT); if (bodyLocationMethods.contains(method) && hasContentType(contentType, MediaType.APPLICATION_FORM_URLENCODED_VALUE)) { requestLocationList.add(RequestLocation.BODY); } RequestLocation[] requestLocations = new RequestLocation[requestLocationList.size()]; return requestLocationList.toArray(requestLocations); } }
public AuthenticationRequest createFrom(HttpRequest httpRequest) { String authzHeaderValue = httpRequest.getHeader(AUTHORIZATION_HEADER); String[] schemeAndValue = getSchemeAndValue(authzHeaderValue); if (schemeAndValue == null) { RequestLocation[] requestLocations = getRequestLocations(httpRequest, false); if (requestLocations.length > 0) { return OAuthAuthenticationRequestFactory.INSTANCE.createRequest(httpRequest, requestLocations); } } else { if (schemeAndValue[0].equalsIgnoreCase(BEARER_AUTHENTICATION_SCHEME)) { RequestLocation[] requestLocations = getRequestLocations(httpRequest, true); return OAuthAuthenticationRequestFactory.INSTANCE.createRequest(httpRequest, requestLocations); } if (schemeAndValue[0].equalsIgnoreCase(BASIC_AUTHENTICATION_SCHEME)) { if (hasContentType(httpRequest.getHeader(CONTENT_TYPE_HEADER), MediaType.APPLICATION_FORM_URLENCODED_VALUE)) { Map<String, String[]> parameterMap = httpRequest.getParameters(); if (parameterMap != null && parameterMap.containsKey(GRANT_TYPE_PARAMETER)) { return OAuthAuthenticationRequestFactory.INSTANCE.createTokenRequest(httpRequest); } } return new DefaultBasicApiAuthenticationRequest(httpRequest); } } throw ApiAuthenticationExceptionFactory.newApiAuthenticationException(InvalidAuthenticationException.class); }
@Override public String getMethod() { return httpRequest.getMethod().name(); }
@Override public String getQueryString() { return httpRequest.getQueryParameters(); }
private String getJwtResponse(Object httpRequestObject) { String jwtResponse; if (HttpRequest.class.isAssignableFrom(httpRequestObject.getClass())) { HttpRequest httpRequest = (HttpRequest) httpRequestObject; Assert.isTrue(httpRequest.getMethod() == HttpMethod.GET, "Only Http GET method is supported."); jwtResponse = httpRequest.getParameter(JWT_RESPONSE); } else { //This must never happen, if the object request is of HttpServletRequest type the HTTP_SERVLET_REQUEST_WRAPPER_CLASS //must be already loaded and therefore cannot be null. if (HTTP_SERVLET_REQUEST_WRAPPER_CLASS == null) { throw new RuntimeException("DefaultHttpServletRequestWrapper not loaded error occurred while handling httpRequest of type: " + httpRequestObject.getClass().getName()); } Constructor<? extends HttpServletRequestWrapper> ctor = Classes.getConstructor(HTTP_SERVLET_REQUEST_WRAPPER_CLASS, Object.class); HttpServletRequestWrapper httpServletRequestWrapper = Classes.instantiate(ctor, httpRequestObject); HttpMethod method = HttpMethod.fromName(httpServletRequestWrapper.getMethod()); Assert.isTrue(HttpMethod.GET == method, "Only Http GET method is supported."); jwtResponse = httpServletRequestWrapper.getParameter(JWT_RESPONSE); } if (!Strings.hasText(jwtResponse)) { throw new InvalidJwtException(InvalidJwtException.JWT_REQUIRED_ERROR); } return jwtResponse; }
@Override public Map<String, String[]> getParameterMap() { return httpRequest.getParameters(); }
@Override public String getHeader(String name) { return httpRequest.getHeader(name); }
@Override public Enumeration<String> getHeaderNames() { return Collections.enumeration(httpRequest.getHeaders().keySet()); }
private String getJwtResponse(Object httpRequestObject) { String jwtResponse; if (HttpRequest.class.isAssignableFrom(httpRequestObject.getClass())) { HttpRequest httpRequest = (HttpRequest) httpRequestObject; Assert.isTrue(httpRequest.getMethod() == HttpMethod.GET, "Only Http GET method is supported."); jwtResponse = httpRequest.getParameter(JWT_RESPONSE); } else { //This must never happen, if the object request is of HttpServletRequest type the HTTP_SERVLET_REQUEST_WRAPPER_CLASS //must be already loaded and therefore cannot be null. if (HTTP_SERVLET_REQUEST_WRAPPER_CLASS == null) { throw new RuntimeException("DefaultHttpServletRequestWrapper not loaded error occurred while handling httpRequest of type: " + httpRequestObject.getClass().getName()); } Constructor<? extends HttpServletRequestWrapper> ctor = Classes.getConstructor(HTTP_SERVLET_REQUEST_WRAPPER_CLASS, Object.class); HttpServletRequestWrapper httpServletRequestWrapper = Classes.instantiate(ctor, httpRequestObject); HttpMethod method = HttpMethod.fromName(httpServletRequestWrapper.getMethod()); Assert.isTrue(HttpMethod.GET == method, "Only Http GET method is supported."); jwtResponse = httpServletRequestWrapper.getParameter(JWT_RESPONSE); } if (!Strings.hasText(jwtResponse)) { throw new InvalidJwtException(InvalidJwtException.JWT_REQUIRED_ERROR); } return jwtResponse; }
@Override public Enumeration<String> getParameterNames() { return Collections.enumeration(httpRequest.getParameters().keySet()); }
private DefaultBasicApiAuthenticationRequest(HttpServletRequestWrapper httpServletRequestWrapper, HttpRequest httpRequest) { this.httpServletRequestWrapper = httpServletRequestWrapper; this.httpRequest = httpRequest; Assert.isTrue(hasHttpServletRequest() || hasHttpRequest()); String authzHeaderValue; if (hasHttpRequest()) { authzHeaderValue = httpRequest.getHeader(ApiAuthenticationRequestFactory.AUTHORIZATION_HEADER); } else { authzHeaderValue = httpServletRequestWrapper.getHeader(ApiAuthenticationRequestFactory.AUTHORIZATION_HEADER); } String[] authTokens = getAuthenticationTokens(authzHeaderValue); id = authTokens[0]; secret = authTokens[1]; }