protected void render(final String template, final Map<String, Object> params, HttpServletRequest request, final HttpServletResponse response, final ApplicationLink applicationLink) throws IOException { final RendererContextBuilder builder = new RendererContextBuilder(params); builder.put(ENABLED_CONTEXT_PARAM, applicationLink.getProperty(OAUTH_INCOMING_CONSUMER_KEY) != null); super.render(template, builder.build(), request, response); }
public static RendererContextBuilder createContextBuilder(final ApplicationLink applicationLink, final I18nResolver i18nResolver, final InternalHostApplication internalHostApplication) { final RendererContextBuilder builder = new RendererContextBuilder() .put("localApplicationName", internalHostApplication.getName()) .put("localApplicationType", i18nResolver.getText(internalHostApplication.getType().getI18nKey())) .put("remoteApplicationName", applicationLink.getName()) .put("remoteApplicationType", i18nResolver.getText(applicationLink.getType().getI18nKey())); return builder; }
+ "Application Link and OAuth store are out of sync. Has someone deleted this information?"); } else { builder.put(CONSUMER_KEY_PARAMETER, consumer.getKey()) .put(NAME_PARAMETER, consumer.getName()) .put(DESCRIPTION_PARAMETER, consumer.getDescription()) .put(SHARED_SECRET_PARAMETER, "") .put(OUTGOING_ENABLED, true) .put(SERVICE_PROVIDER_REQUEST_TOKEN_URL_PARAMETER, requestTokenUrl) .put(SERVICE_PROVIDER_ACCESS_TOKEN_URL_PARAMETER, accessTokenUrl) .put(SERVICE_PROVIDER_AUTHORIZE_URL_PARAMETER, authorizeUrl) .put("success-msg", getMessage(request)); builder.put(OUTGOING_ENABLED, false). put("success-msg", getMessage(request)); render(TEMPLATE, builder.build(), request, response);
public RendererContextBuilder(Map<String, Object> context) { this(); for (Map.Entry<String, Object> entry : context.entrySet()) { put(entry.getKey(), entry.getValue()); } }
private void updateIncomingOAuthConfig(HttpServletRequest request, HttpServletResponse response) throws IOException { final ApplicationLink applicationLink = getRequiredApplicationLink(request); final boolean enabled = Boolean.parseBoolean(request.getParameter(OAUTH_INCOMING_ENABLED)); final Map<String, String> fieldErrorMessages = new HashMap<String, String>(); addOrRemoveConsumer(applicationLink, enabled, fieldErrorMessages); final String uiPosition = request.getParameter(UI_POSITION); if (fieldErrorMessages.isEmpty()) { final String message = enabled ? i18nResolver.getText("auth.oauth.config.serviceprovider.consumer.enabled") : i18nResolver.getText("auth.oauth.config.serviceprovider.consumer.disabled"); response.sendRedirect("./" + applicationLink.getId() + "?" + MESSAGE_PARAM + "=" + URIUtil.utf8Encode(message) + "&uiposition=" + uiPosition); } else { final RendererContextBuilder builder = createContextBuilder(applicationLink); builder.put(FIELD_ERROR_MESSAGES_CONTEXT_PARAM, fieldErrorMessages); builder.put(UI_POSITION, uiPosition); render(INCOMING_APPLINKS_TEMPLATE, builder.build(), request, response, applicationLink); } }
protected RendererContextBuilder createContextBuilder(final ApplicationLink applicationLink) { return new RendererContextBuilder() .put("localApplicationName", internalHostApplication.getName()) .put("localApplicationType", i18nResolver.getText(internalHostApplication.getType().getI18nKey())) .put("remoteApplicationName", applicationLink.getName()) .put("remoteApplicationType", i18nResolver.getText(applicationLink.getType().getI18nKey())); }
public RendererContextBuilder(Map<String, Object> context) { for (Map.Entry<String, Object> entry : context.entrySet()) { put(entry.getKey(), entry.getValue()); } }
private void processPeerResponse(final HttpServletRequest request, final HttpServletResponse response, final ApplicationLink link) throws IOException { // returned from peer final RendererContextBuilder contextBuilder = new RendererContextBuilder(); if (!peerWasSuccessful(request)) { contextBuilder.put("error", messageFactory.newI18nMessage("auth.trusted.config.consumer.save.peer.failed", request.getParameter("message"))); } render(link, request, response, contextBuilder.build()); }
@Override protected void doGet(final HttpServletRequest request, final HttpServletResponse response) throws IOException { try { // Enable web sudo protection if needed and if the app we are running in supports it webSudoManager.willExecuteWebSudoRequest(request); final ApplicationLink applicationLink = getRequiredApplicationLink(request); final Consumer consumer = providerStoreService.getConsumer(applicationLink); final RendererContextBuilder builder = createContextBuilder(applicationLink); builder.put("contextPath", request.getContextPath()); builder.put("message", getMessage(request)); if (consumer != null) { builder.put(CONSUMER, consumer); final String publicKey = RSAKeys.toPemEncoding(consumer.getPublicKey()); builder.put(PUBLIC_KEY, publicKey); } builder.put(IS_SYSADMIN, isSysadmin()); render(INCOMING_NON_APPLINKS_TEMPLATE, builder.build(), request, response, applicationLink); } catch (WebSudoSessionException wse) { webSudoManager.enforceWebSudoProtection(request, response); } }
public static RendererContextBuilder createContextBuilder(final ApplicationLink applicationLink, final I18nResolver i18nResolver, final InternalHostApplication internalHostApplication) { final RendererContextBuilder builder = new RendererContextBuilder() .put("localApplicationName", internalHostApplication.getName()) .put("localApplicationType", i18nResolver.getText(internalHostApplication.getType().getI18nKey())) .put("remoteApplicationName", applicationLink.getName()) .put("remoteApplicationType", i18nResolver.getText(applicationLink.getType().getI18nKey())); return builder; }
public RendererContextBuilder(Map<String, Object> context) { this(); for (Map.Entry<String, Object> entry : context.entrySet()) { put(entry.getKey(), entry.getValue()); } }
private Map<String, Object> buildMessageContext(final String redirectUrl) { final RendererContextBuilder builder = new RendererContextBuilder(); webResourceManager.requireResource("com.atlassian.applinks.applinks-plugin:oauth-dance"); final StringWriter stringWriter = new StringWriter(); webResourceManager.includeResources(stringWriter, UrlMode.RELATIVE); final WebResources webResources = new WebResources(); webResources.setIncludedResources(stringWriter.getBuffer().toString()); builder.put("webResources", webResources); builder.put("redirectUrl", redirectUrl); return builder.build(); }
@Override protected void doPost(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException { try { // Enable web sudo protection if needed and if the app we are running in supports it webSudoManager.willExecuteWebSudoRequest(request); final ApplicationLink applicationLink = getRequiredApplicationLink(request); final Map<String, String> fieldErrorMessages = new HashMap<String, String>(); final boolean enabled = Boolean.parseBoolean(checkRequiredFormParameter(request, OAUTH_INCOMING_ENABLED, fieldErrorMessages, "auth.oauth.config.error.enable")); addOrRemoveConsumer(request, applicationLink, fieldErrorMessages, enabled); if (fieldErrorMessages.isEmpty()) { final String message = enabled ? i18nResolver.getText("auth.oauth.config.serviceprovider.consumer.enabled") : i18nResolver.getText("auth.oauth.config.serviceprovider.consumer.disabled"); response.sendRedirect("./" + applicationLink.getId() + "?" + MESSAGE_PARAM + "=" + URIUtil.utf8Encode(message)); } else { final FormFields formFields = new FormFields(request); final RendererContextBuilder builder = createContextBuilder(applicationLink); builder.put("contextPath", request.getContextPath()); builder.put(CONSUMER, formFields); builder.put(PUBLIC_KEY, formFields.getPublicKey()); builder.put("fieldErrorMessages", fieldErrorMessages); builder.put(IS_SYSADMIN, isSysadmin()); render(INCOMING_NON_APPLINKS_TEMPLATE, builder.build(), request, response, applicationLink); } } catch (WebSudoSessionException wse) { webSudoManager.enforceWebSudoProtection(request, response); } }
protected RendererContextBuilder createContextBuilder(final ApplicationLink applicationLink) { final RendererContextBuilder builder = new RendererContextBuilder() .put("localApplicationName", internalHostApplication.getName()) .put("localApplicationType", i18nResolver.getText(internalHostApplication.getType().getI18nKey())) .put("remoteApplicationName", applicationLink.getName()) .put("remoteApplicationType", i18nResolver.getText(applicationLink.getType().getI18nKey())); return builder; }
private void populateIncoming2LOContextParams(HttpServletRequest request, ApplicationLink applicationLink, RendererContextBuilder builder) { // if this is a display of the error, show the user entered parameters. if (request.getParameter(TWO_LO_ERROR_MESSAGE) != null) { builder.put(TWO_LO_ERROR_MESSAGE, request.getParameter(TWO_LO_ERROR_MESSAGE)); builder.put(TWO_LO_ENABLED, Boolean.parseBoolean(request.getParameter(TWO_LO_ENABLED_ERROR_VALUE))); builder.put(TWO_LO_EXECUTE_AS, request.getParameter(TWO_LO_EXECUTE_AS_ERROR_VALUE)); builder.put(TWO_LO_IMPERSONATION_ENABLED, Boolean.parseBoolean(request.getParameter(TWO_LO_IMPERSONATION_ENABLED_ERROR_VALUE))); } // Otherwise, show the actual parameters persisted in the backend. else { Consumer consumer = serviceProviderStoreService.getConsumer(applicationLink); if (consumer != null) { builder.put(TWO_LO_ENABLED, consumer.getTwoLOAllowed()); builder.put(TWO_LO_EXECUTE_AS, consumer.getExecutingTwoLOUser()); builder.put(TWO_LO_IMPERSONATION_ENABLED, consumer.getTwoLOImpersonationAllowed()); // the success message might have to be displayed if the previous operation is a successful save. if (request.getParameter(TWO_LO_SUCCESS_MESSAGE) != null) { builder.put(TWO_LO_SUCCESS_MESSAGE, request.getParameter(TWO_LO_SUCCESS_MESSAGE)); } } } }
protected void render(final HttpServletRequest request, final HttpServletResponse response, final String consumer, final String consumerAppType, final String provider, final String providerAppType, final boolean enabled, final Map<String, Object> renderContext) throws IOException { final Object view = renderContext.get("view"); final String role = request.getServletPath().replaceFirst(".*/([^/?]+).*", "$1").startsWith("inbound") ? "provider" : "consumer"; render(VM_TEMPLATE, new RendererContextBuilder(renderContext) .put("stringUtils", new StringUtils()) .put("enabled", enabled) .put("view", ObjectUtils.defaultIfNull(view, enabled ? "enabled" : "disabled")) .put("nonUAL", !peerHasUAL(request)) .put("formLocation", request.getContextPath() + request.getServletPath() + request.getPathInfo()) .put("consumer", consumer) .put("consumerAppType", consumerAppType) .put("providerAppType", providerAppType) .put("provider", provider) .put("role", role) .build(), request, response); } }
final String message = getMessage(request); if (!StringUtils.isEmpty(message) && fieldErrorMessages.isEmpty()) { builder.put(SUCCESS_MSG_CONTEXT_PARAM, message); builder.put(FIELD_ERROR_MESSAGES_CONTEXT_PARAM, fieldErrorMessages); builder.put(FIELD_ERROR_MESSAGES_CONTEXT_PARAM, fieldErrorMessages); builder.put(SUCCESS_MSG_CONTEXT_PARAM, message); final String remoteOAuthConfigURL = getOAuthConfigRemoteURL(applicationLink, uiPosition, request); if (remoteOAuthConfigURL != null) { builder.put(REMOTE_URL_CONTEXT_PARAM, remoteOAuthConfigURL); builder.put(REMOTE_2LO_URL_CONTEXT_PARAM, remote2LOConfigURL); builder.put(UI_POSITION, uiPosition); builder.put(IS_SYSADMIN, userManager.isSystemAdmin(userManager.getRemoteUsername())); render(INCOMING_APPLINKS_TEMPLATE, builder.build(), request, resp, applicationLink); } catch (WebSudoSessionException wse) { webSudoManager.enforceWebSudoProtection(request, resp);
builder.put("outgoingTwoLoShouldBeEnabled", true); builder.put("outgoingTwoLoShouldBeDisabled", true); builder.put("incoming2LOEnabledOnRemote", twoLOAllowed); builder.put("outgoingTwoLoiShouldBeVisible", true); builder.put("outgoingTwoLoiShouldBeEnabled", true); builder.put("outgoingTwoLoiShouldBeDisabled", true); builder.put("incoming2LOiEnabledOnRemote", twoLOiAllowed); } else { builder.put("outgoingTwoLoiShouldBeVisible", false); if (outgoing2LOSuccessParam != null) { if (Boolean.parseBoolean(outgoing2LOSuccessParam)) { builder.put("outgoingTwoLoSuccessMessage", getMessage(request)); } else { builder.put("outgoingTwoLoErrorMessage", getMessage(request));
private Map<String, Object> buildMessageContext() { final RendererContextBuilder builder = new RendererContextBuilder(); webResourceManager.requireResource("com.atlassian.applinks.applinks-plugin:oauth-dance"); final StringWriter stringWriter = new StringWriter(); webResourceManager.includeResources(stringWriter, UrlMode.RELATIVE); final WebResources webResources = new WebResources(); webResources.setIncludedResources(stringWriter.getBuffer().toString()); builder.put("webResources", webResources); return builder.build(); }