/** * Find the most appropriate consumer info renderer for the request and token. If none can be found from the * dynamically imported services, falls back to the {@code basicConsumerInformationRenderer}. * * @param request users request * @param token token being authorized * @return {@code ConsumerInformationRenderer} to use for rendering consumer info on authorization page */ private ConsumerInformationRenderer findConsumerInfoRenderer(HttpServletRequest request, ServiceProviderToken token) { try { return new DynamicSafeConsumerInformationRenderer(find(consumerInfoRenderers, canRender(token, request)), basicConsumerInformationRenderer); } catch (NoSuchElementException e) { return basicConsumerInformationRenderer; } }
public void render(HttpServletRequest request, HttpServletResponse response, ServiceProviderToken token) throws IOException { response.setContentType("text/html;charset=UTF-8"); ConsumerInformationRenderer consumerInfoRenderer = findConsumerInfoRenderer(request, token); Map<String, Object> context = new HashMap<>(); context.put("applicationProperties", applicationProperties); context.put("token", token.getToken()); context.put("csrfToken", xsrfTokenAccessor.getXsrfToken(request, response, true)); context.put("csrfTokenParamName", xsrfTokenValidator.getXsrfParameterName()); context.put("consumer", token.getConsumer()); context.put("consumerRenderer", new AuthorizationConsumerRenderer(consumerInfoRenderer, token, request, response.getWriter())); context.put("accessTokensAdminUri", applicationProperties.getBaseUrl() + AccessTokensServlet.PATH); String callback = request.getParameter(OAUTH_CALLBACK); if (callback != null) { context.put("callback", callback); } try { renderer.render("templates/auth/authorize.vm", unmodifiableMap(context), response.getWriter()); } catch (RenderingException e) { throw new ConsumerInformationRenderException("Could not render consumer information", e); } }