private Consumer getConsumer(final String consumerKey) { return consumerService.getConsumerByKey(consumerKey) == null ? consumerService.getConsumer() : consumerService.getConsumerByKey(consumerKey); }
private boolean jwtWasIssuedByHost(String issuer) { try { final String consumerKey = consumerService.getConsumer().getKey(); log.debug("jwtWasIssuedByHost: consumer-key='{}', issuer='{}'", consumerKey, issuer); return consumerKey.equals(issuer); } catch(ConsumerCreationException e) { log.error("Could not get the consumer that provides issuer Id.", e); } return false; }
private String getHostClientKey() { return consumerService.getConsumer().getKey(); }
final Consumer existingConsumerDuplicatedServiceName = consumerService.getConsumer(name); final Consumer existingConsumerDuplicatedKey = consumerService.getConsumerByKey(consumerKey); if (existingConsumerDuplicatedServiceName != null) {
private String getHostClientKey() { return consumerService.getConsumer().getKey(); }
@Override @Nonnull public Optional<String> generate(HttpMethod httpMethod, URI url, Map<String, String[]> parameters, String secret, Optional<UserProfile> user) { checkArgument(null != parameters, "Parameters Map argument cannot be null"); checkArgument(null != secret, "Secret cannot be null"); final String authValue = jwtEncoder.encodeJwt(httpMethod, url, addonBaseUrl, parameters, consumerService.getConsumer().getKey(), secret, user); return Optional.of(JWT_AUTH_HEADER_PREFIX + authValue); } }
@Override @Nonnull public Optional<String> generate(HttpMethod httpMethod, URI url, Map<String, String[]> parameters, String secret, Optional<UserProfile> user) { checkArgument(null != parameters, "Parameters Map argument cannot be null"); checkArgument(null != secret, "Secret cannot be null"); final String authValue = jwtEncoder.encodeJwt(httpMethod, url, addonBaseUrl, parameters, consumerService.getConsumer().getKey(), secret, user); return Optional.of(JWT_AUTH_HEADER_PREFIX + authValue); } }
private String getConsumerKey(ApplicationLink applicationLink) { final Map<String, String> config = authenticationConfigurationManager.getConfiguration(applicationLink.getId(), OAuthAuthenticationProvider.class); if (config.containsKey(AddServiceProviderManuallyServlet.CONSUMER_KEY_OUTBOUND)) { return config.get(AddServiceProviderManuallyServlet.CONSUMER_KEY_OUTBOUND); } return consumerService.getConsumer().getKey(); }
@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 ConsumerToken asToken(HttpServletRequest request) { return ConsumerToken.newAccessToken(request.getParameter("token")) .tokenSecret(request.getParameter("token-secret")) .consumer(consumer.getConsumer()) .build(); }
public void removeAllConsumerTokens(final ApplicationLink applicationLink) { Preconditions.checkNotNull(applicationLink, "applicationLink"); final Map<String, String> configuration = configurationManager.getConfiguration(applicationLink.getId(), OAuthAuthenticationProvider.class); verifyOAuthOutgoingEnabled(applicationLink.getId()); if (configuration.containsKey(ApplinksOAuth.AUTH_CONFIG_CONSUMER_KEY_OUTBOUND)) { final String consumerKey = configuration.get(ApplinksOAuth.AUTH_CONFIG_CONSUMER_KEY_OUTBOUND); consumerTokenStore.removeTokensForConsumer(consumerKey); } else { final String consumerKey = consumerService.getConsumer().getKey(); final Map<ConsumerTokenStore.Key, ConsumerToken> consumerTokens = consumerTokenStore.getConsumerTokens(consumerKey); for (ConsumerTokenStore.Key key : consumerTokens.keySet()) { final Map<String, String> tokenProperties = consumerTokens.get(key).getProperties(); if (tokenProperties.containsKey(APPLINKS_APPLICATION_LINK_ID) && tokenProperties.get(APPLINKS_APPLICATION_LINK_ID).equals(applicationLink.getId().get())) { consumerTokenStore.remove(key); } } } }
@PUT @Path("consumer/{applinkId}/{username}") public Response createConsumerAccessToken(@PathParam("applinkId") String applinkId, @PathParam("username") String username, RestAccessToken restToken) throws TypeNotInstalledException { ApplicationId applicationId = new ApplicationId(applinkId); ApplicationLink link = getApplicationLink(applicationId); ConsumerToken token = ConsumerToken.newAccessToken(restToken.getToken()) .tokenSecret(restToken.getTokenSecret()) .consumer(consumerService.getConsumer()) // this app's consumer .build(); consumerTokenStoreService.removeConsumerToken(applicationId, username); consumerTokenStoreService.addConsumerToken(link, username, token); return Response.created(URI.create("")) .entity(new RestAccessToken(token)) .build(); }
@Override public String signUrl(HttpMethod method, URI targetPath, Map<String, String[]> params) { assertThatTargetPathAndParamsDoNotDuplicateParams(targetPath, params); String encodedJwt = jwtEncoder.encodeJwt(method, targetPath, getBaseUrl(), params, consumerService.getConsumer().getKey(), requireSharedSecret(), Optional.empty()); final UriBuilder uriBuilder = new UriBuilder(Uri.fromJavaUri(URI.create(createGetUrl(targetPath, params)))); uriBuilder.addQueryParameter(JwtConstants.JWT_PARAM_NAME, encodedJwt); return uriBuilder.toString(); }
@Override public String signGetUrl(URI targetPath, Map<String, String[]> params) { assertThatTargetPathAndParamsDoNotDuplicateParams(targetPath, params); String encodedJwt = jwtEncoder.encodeJwt(HttpMethod.GET, targetPath, getBaseUrl(), params, consumerService.getConsumer().getKey(), requireSharedSecret(), Optional.empty()); final UriBuilder uriBuilder = new UriBuilder(Uri.fromJavaUri(URI.create(createGetUrl(targetPath, params)))); uriBuilder.addQueryParameter(JwtConstants.JWT_PARAM_NAME, encodedJwt); return uriBuilder.toString(); }
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); }
private void cleanOAuth() { String consumerKey = consumerService.getConsumer().getKey(); final Map<ConsumerTokenStore.Key, ConsumerToken> consumerTokens = consumerTokenStore.getConsumerTokens(consumerKey); for (ConsumerTokenStore.Key key : consumerTokens.keySet()) { consumerTokenStore.remove(key); } for (final ApplicationLink link : ImmutableList.copyOf(linkService.getApplicationLinks())) { Map<String, String> config = authenticationConfigurationManager.getConfiguration(link.getId(), OAuthAuthenticationProvider.class); if (config != null && config.containsKey(AUTH_CONFIG_CONSUMER_KEY_OUTBOUND)) { final String key = config.get(AUTH_CONFIG_CONSUMER_KEY_OUTBOUND); consumerTokenStore.removeTokensForConsumer(key); } authenticationConfigurationManager.unregisterProvider(link.getId(), OAuthAuthenticationProvider.class); } // as a service provider (inbound): get rid of all the consumers for (final Consumer consumer : serviceProviderConsumerStore.getAll()) { serviceProviderTokenStore.removeByConsumer(consumer.getKey()); serviceProviderConsumerStore.remove(consumer.getKey()); } // as a consumer (outbound): get rid of all the service providers we talked to for (final Consumer consumer : consumerService.getAllServiceProviders()) { consumerService.removeConsumerByKey(consumer.getKey()); } } }