@Override public void save() throws IOException { if (privateKey != null && publicKey != null) { FileUtils.writeStringToFile(privateKeyFile, RSAKeys.toPemEncoding(privateKey)); FileUtils.writeStringToFile(publicKeyFile, RSAKeys.toPemEncoding(publicKey)); } }
@Override public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { response.setContentType("application/xml;charset=UTF-8"); Consumer consumer = store.getConsumer(); Map<String, Object> context = ImmutableMap.of( "consumer", consumer, "encodedPublicKey", RSAKeys.toPemEncoding(consumer.getPublicKey()) ); try { renderer.render("view.xml.vm", context, response.getWriter()); } catch (RenderingException e) { throw new ServletException(e); } catch (ConsumerCreationException e) { throw new ServletException(e); } } }
private String createEventDataInternal(String pluginKey, String eventType, Optional<OAuthClient> oauthClient) { final Consumer consumer = checkNotNull(consumerService.getConsumer()); // checkNotNull() otherwise we NPE below ConnectAddonEventDataBuilder dataBuilder = newConnectAddonEventData(); String baseUrl = applicationProperties.getBaseUrl(UrlMode.CANONICAL); dataBuilder.withBaseUrl(nullToEmpty(baseUrl)) .withPluginKey(pluginKey) .withClientKey(nullToEmpty(consumer.getKey())) .withPublicKey(nullToEmpty(RSAKeys.toPemEncoding(consumer.getPublicKey()))) .withPluginsVersion(nullToEmpty(getConnectPluginVersion())) .withServerVersion(nullToEmpty(applicationProperties.getBuildNumber())) .withServiceEntitlementNumber(nullToEmpty(licenseRetriever.getServiceEntitlementNumber(pluginKey))) .withProductType(nullToEmpty(productAccessor.getKey())) .withDescription(nullToEmpty(consumer.getDescription())) .withEventType(eventType); if (darkFeatureManager.isFeatureEnabledForCurrentUser(DARK_FEATURE_OAUTH2_IMPERSONATION)) { dataBuilder.withOauthClient(oauthClient); } else { dataBuilder.withSharedSecret(oauthClient.map(OAuthClient::getSharedSecret).orElse(null)); } ConnectAddonEventData data = dataBuilder.build(); return ConnectModulesGsonFactory.toJson(data); }
private String createEventDataInternal(String pluginKey, String eventType, Optional<OAuthClient> oauthClient) { final Consumer consumer = checkNotNull(consumerService.getConsumer()); // checkNotNull() otherwise we NPE below ConnectAddonEventDataBuilder dataBuilder = newConnectAddonEventData(); String baseUrl = applicationProperties.getBaseUrl(UrlMode.CANONICAL); dataBuilder.withBaseUrl(nullToEmpty(baseUrl)) .withPluginKey(pluginKey) .withClientKey(nullToEmpty(consumer.getKey())) .withPublicKey(nullToEmpty(RSAKeys.toPemEncoding(consumer.getPublicKey()))) .withPluginsVersion(nullToEmpty(getConnectPluginVersion())) .withServerVersion(nullToEmpty(applicationProperties.getBuildNumber())) .withServiceEntitlementNumber(nullToEmpty(licenseRetriever.getServiceEntitlementNumber(pluginKey))) .withProductType(nullToEmpty(productAccessor.getKey())) .withDescription(nullToEmpty(consumer.getDescription())) .withEventType(eventType); if (impersonationIsEnabled()) { dataBuilder.withOauthClient(oauthClient.map(c -> new OAuthClientBean(c.getClientId(), c.getSharedSecret()))); } else { dataBuilder.withSharedSecret(oauthClient.map(OAuthClient::getSharedSecret).orElse(null)); } ConnectAddonEventData data = dataBuilder.build(); return ConnectModulesGsonFactory.toJson(data); }
@Nonnull public ConsumerEntity build() { String publicKey; if (consumer.getPublicKey() != null) { publicKey = RSAKeys.toPemEncoding(consumer.getPublicKey()); } else { publicKey = null; } return new ConsumerEntity(self, consumer.getKey(), consumer.getName(), consumer.getDescription(), consumer.getSignatureMethod().name(), publicKey, consumer.getCallback(), consumer.getTwoLOAllowed(), consumer.getExecutingTwoLOUser(), consumer.getTwoLOImpersonationAllowed() ); } }
public RestConsumer(@Nonnull Consumer consumer) { checkNotNull(consumer, "consumer"); put(KEY, consumer.getKey()); put(NAME, consumer.getName()); putIfNotNull(DESCRIPTION, consumer.getDescription()); put(SIGNATURE_METHOD, consumer.getSignatureMethod().name()); if (consumer.getPublicKey() != null) { put(PUBLIC_KEY, RSAKeys.toPemEncoding(consumer.getPublicKey())); } putAsString(CALLBACK, consumer.getCallback()); put(TWO_LO_ALLOWED, consumer.getTwoLOAllowed()); putIfNotNull(EXECUTING_TWO_LO_USER, consumer.getExecutingTwoLOUser()); put(TWO_LO_IMPERSONATION_ALLOWED, consumer.getTwoLOImpersonationAllowed()); }
@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); } }
/** * Get the {@link com.marvelution.jenkins.plugins.jira.model.ConsumerInfo} of the local instance * * @param request the {@link javax.servlet.http.HttpServletRequest}, used to determine the application root url * @return the ConsumerInfo * @throws IOException in case errors */ public static ConsumerInfo getOwnConsumerInfo(HttpServletRequest request) throws IOException { String url = ApplicationLinkStore.getStore().getApplicationUrl(); String id = ApplicationLinkStore.getStore().getApplicationId(); ConsumerInfo consumerInfo = new ConsumerInfo(); try { Class.forName("jenkins.model.Jenkins"); consumerInfo.setKey("jenkins:" + id); consumerInfo.setDescription("Jenkins at " + url); } catch (ClassNotFoundException e) { consumerInfo.setKey("jenkins:" + id); consumerInfo.setDescription("Hudson at " + url); } String name = ApplicationLinkStore.getStore().getApplicationName(); if (StringUtils.isBlank(name)) { name = Hudson.getInstance().getDisplayName(); } consumerInfo.setName(name); consumerInfo.setPublicKey(RSAKeys.toPemEncoding(JIRAPlugin.getPlugin().getPublicKey())); return consumerInfo; }