/** * Additional descriptive text about the consumer application. */ public String getDescription() { return token.getConsumer().getDescription(); }
private List<OrphanedTrustCertificate> findOrphanedOAuthServiceProviders() { final List<OrphanedTrustCertificate> orphanedTrustCertificates = new ArrayList<OrphanedTrustCertificate>(); final List<String> registeredServiceProviders = findRegisteredServiceProviders(); final Iterable<Consumer> allServiceProviders = consumerService.getAllServiceProviders(); for (Consumer serviceProvider : allServiceProviders) { if (!registeredServiceProviders.contains(serviceProvider.getKey())) { log.debug("Found orphaned Service Provider with consumer key '" + serviceProvider.getKey() + "' and name '" + serviceProvider.getName() + "'"); orphanedTrustCertificates.add( new OrphanedTrustCertificate(serviceProvider.getKey(), serviceProvider.getDescription(), OrphanedTrustCertificate.Type.OAUTH_SERVICE_PROVIDER) ); } } return orphanedTrustCertificates; }
private List<OrphanedTrustCertificate> findOrphanedOAuthConsumers() { final List<OrphanedTrustCertificate> orphanedTrustCertificates = new ArrayList<>(); final Set<String> recognisedConsumerKeys = new HashSet<>(); for (final ApplicationLink link : applicationLinkService.getApplicationLinks()) { final Consumer consumer = serviceProviderStoreService.getConsumer(link); if (consumer != null) { recognisedConsumerKeys.add(consumer.getKey()); } } for (final Consumer consumer : serviceProviderConsumerStore.getAll()) { if (!recognisedConsumerKeys.contains(consumer.getKey())) { orphanedTrustCertificates.add( new OrphanedTrustCertificate(consumer.getKey(), consumer.getDescription(), OrphanedTrustCertificate.Type.OAUTH) ); } } return orphanedTrustCertificates; }
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); }
/** * Converts a {@code Consumer} to an {@code OAuthConsumer}, uses the {@code sharedSecret} in the * {@code OAuthConsumer}s constructor so that it is suitable for signing. * * @param consumer {@code Consumer} to be converted to an {@code OAuthConsumer} * @param sharedSecret shared secret to use to sign requests * @param oauthServiceProvider {@code OAuthServiceProvider} to set as the {@link OAuthConsumer#serviceProvider} attribute * @return {@code OAuthConsumer} converted from the {@code Consumer} */ public static OAuthConsumer asOAuthConsumer(Consumer consumer, String sharedSecret, OAuthServiceProvider oauthServiceProvider) { checkNotNull(consumer, "consumer"); checkNotNull(oauthServiceProvider, "oauthServiceProvider"); String callback = consumer.getCallback() != null ? consumer.getCallback().toString() : null; OAuthConsumer oauthConsumer = new OAuthConsumer(callback, consumer.getKey(), sharedSecret, oauthServiceProvider); oauthConsumer.setProperty(ConsumerProperty.NAME, consumer.getName()); oauthConsumer.setProperty(ConsumerProperty.DESCRIPTION, consumer.getDescription()); if (consumer.getSignatureMethod() == SignatureMethod.RSA_SHA1) { oauthConsumer.setProperty(OAuth.OAUTH_SIGNATURE_METHOD, OAuth.RSA_SHA1); oauthConsumer.setProperty(RSA_SHA1.PUBLIC_KEY, consumer.getPublicKey()); } else { oauthConsumer.setProperty(OAuth.OAUTH_SIGNATURE_METHOD, OAuth.HMAC_SHA1); } return oauthConsumer; }
Consumer updatedConsumer = new Consumer.InstanceBuilder(consumer.getKey()) .name(consumer.getName()) .description(consumer.getDescription()) .publicKey(consumer.getPublicKey()) .signatureMethod(consumer.getSignatureMethod())
/** * Convert a given {@code token} to an {@link net.oauth.OAuthConsumer} * * @param token the {@link com.atlassian.oauth.serviceprovider.ServiceProviderToken} to convert * @return the {@link net.oauth.OAuthConsumer} */ public static OAuthConsumer toOAuthConsumer(ServiceProviderToken token) { String callback = token.getCallback() != null ? token.getCallback().toString() : null; final OAuthConsumer consumer = new OAuthConsumer(callback, token.getConsumer().getKey(), null, null); consumer.setProperty(NAME, token.getConsumer().getName()); consumer.setProperty(DESCRIPTION, token.getConsumer().getDescription()); consumer.setProperty(OAuth.OAUTH_SIGNATURE_METHOD, OAuth.RSA_SHA1); consumer.setProperty(RSA_SHA1.PUBLIC_KEY, token.getConsumer().getPublicKey()); return consumer; }
public static Consumer.InstanceBuilder consumerBuilder(@Nonnull Consumer consumer) { checkNotNull(consumer, "consumer"); Consumer.InstanceBuilder builder = new Consumer.InstanceBuilder(consumer.getKey()) .name(consumer.getName()) .description(consumer.getDescription()) .signatureMethod(consumer.getSignatureMethod()) .callback(consumer.getCallback()) .twoLOAllowed(consumer.getTwoLOAllowed()) .executingTwoLOUser(consumer.getExecutingTwoLOUser()) .twoLOImpersonationAllowed(consumer.getTwoLOImpersonationAllowed()); if (consumer.getPublicKey() != null) { builder.publicKey(consumer.getPublicKey()); } return builder; } }
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)
@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()); }
@Test public void testServiceProviderConsumerStoreCanStoreConfiguration() throws Exception { PublicKey publicKey = RSAKeys.fromPemEncodingToPublicKey(CONSUMER_PUBLIC_KEY); final Consumer consumer = Consumer.key(CONSUMER_KEY) .name("Test Consumer Name") .publicKey(publicKey) .description("Consumer Description") .callback(URI.create(appProp.getBaseUrl() + "/consumer/oauthcallback1")) .build(); consumerStore.put(consumer); final Consumer savedConsumer = consumerStore.get(CONSUMER_KEY); assertEquals(CONSUMER_KEY, savedConsumer.getKey()); assertEquals("Test Consumer Name", savedConsumer.getName()); assertEquals(publicKey, savedConsumer.getPublicKey()); assertEquals("Consumer Description", savedConsumer.getDescription()); assertEquals(URI.create(appProp.getBaseUrl() + "/consumer/oauthcallback1"), savedConsumer.getCallback()); }
.description(consumer.getDescription()) .publicKey(consumer.getPublicKey()) .signatureMethod(consumer.getSignatureMethod()) .description(consumer.getDescription()) .publicKey(consumer.getPublicKey()) .signatureMethod(consumer.getSignatureMethod())