static { if (Classes.isAvailable(HTTP_SERVLET_REQUEST_FQCN)) { HTTP_SERVLET_REQUEST_WRAPPER_CLASS = Classes.forName(HTTP_SERVLET_REQUEST_WRAPPER_FQCN); } else { HTTP_SERVLET_REQUEST_WRAPPER_CLASS = null; } }
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; }
/** * Return the {@link ConfigFactory} implementation class to use, either the default {@link * com.stormpath.sdk.servlet.config.impl.DefaultConfigFactory} or a custom class if specified. * * @param servletContext current servlet context * @return the ConfigFactory implementation class to use * @see #CONFIG_FACTORY_CLASS_PARAM_NAME * @see com.stormpath.sdk.servlet.config.impl.DefaultConfigFactory */ protected Class<?> determineConfigFactoryClass(ServletContext servletContext) { String className = servletContext.getInitParameter(CONFIG_FACTORY_CLASS_PARAM_NAME); className = Strings.trimWhitespace(className); if (className != null) { try { return Classes.forName(className); } catch (UnknownClassException ex) { throw new IllegalStateException( "Failed to load custom ConfigFactory class [" + className + "]", ex); } } else { return DefaultConfigFactory.class; } }
/** * Instantiates a {@link Config} based on the specified ServletContext. * * <p>This implementation {@link #determineConfigFactoryClass(javax.servlet.ServletContext) * determines} a {@link com.stormpath.sdk.servlet.config.ConfigFactory} implementation class to * use. That class is instantiated, returned, and invoked. * * <p>This allows custom {@code ConfigFactory} implementations to be specified via a * ServletContext init-param if desired. If not specified, the default {@link * com.stormpath.sdk.servlet.config.impl.DefaultConfigFactory} implementation will be used. * * @param sc current servlet context * @return the constructed Stormpath config instance */ protected Config doCreateConfig(ServletContext sc) { Class<?> clazz = determineConfigFactoryClass(sc); if (!ConfigFactory.class.isAssignableFrom(clazz)) { throw new IllegalStateException( "Custom ConfigFactory class [" + clazz.getName() + "] is not of required type [" + ConfigFactory.class.getName() + "]"); } ConfigFactory factory = (ConfigFactory) Classes.newInstance(clazz); return factory.createConfig(sc); }