Consumer updatedConsumer = new Consumer.InstanceBuilder("consumerkey-" + options.id) .name("consumername-" + options.id) .description("consumerdesc-" + options.id) .publicKey(publickey) .signatureMethod(Consumer.SignatureMethod.HMAC_SHA1) .callback(new URI("http://callback.com")) .twoLOAllowed(options.add2LO) .executingTwoLOUser("2LOuser") .twoLOImpersonationAllowed(options.add2LOi) .build(); serviceProviderConsumerStore.put(updatedConsumer); link.putProperty(OAUTH_INCOMING_CONSUMER_KEY, updatedConsumer.getKey());
.name("Hardcoded Consumer") .publicKey(publicKey) .description("Hardcoded Consumer") .callback(URI.create("http://localhost:8080/consumer/oauthcallback")) .build(); consumerStore.put(hardcodedConsumer); .name("Hardcoded Consumer - Without Callback") .publicKey(publicKey) .description("Hardcoded Consumer - Without Callback") .build(); consumerStore.put(hardcodedConsumerWithoutCallback); .name("Hardcoded 2LO Consumer") .publicKey(publicKey) .description("Hardcoded 2LO Consumer") .twoLOAllowed(true) .executingTwoLOUser("barney") .build(); consumerStore.put(hardcoded2LOConsumer); .name("Hardcoded 2LO Only Consumer") .publicKey(publicKey) .description("Hardcoded 2LO Consumer") .threeLOAllowed(false) .twoLOAllowed(true) .executingTwoLOUser("barney") .build(); consumerStore.put(hardcoded2LOOnlyConsumer);
SERVICE_PROVIDER_AUTHORIZE_URL, authorizeUrl)); final Consumer consumer = Consumer.key(consumerKey) .name(name) .signatureMethod(Consumer.SignatureMethod.HMAC_SHA1) .description(description) .build(); consumerService.add(name, consumer, sharedSecret); } else /* disable */ {
Consumer updatedConsumer = new Consumer.InstanceBuilder(consumer.getKey()) .name(consumer.getName()) .description(consumer.getDescription()) .publicKey(consumer.getPublicKey()) .signatureMethod(consumer.getSignatureMethod()) .callback(consumer.getCallback()) .twoLOAllowed(consumerEntity.isTwoLOAllowed()) .executingTwoLOUser(consumerEntity.getExecutingTwoLOUser()) .twoLOImpersonationAllowed(consumerEntity.isTwoLOImpersonationAllowed()) .build(); Consumer updatedConsumer = new Consumer.InstanceBuilder(consumer.getKey()) .name(consumer.getName()) .description(consumer.getDescription()) .publicKey(consumer.getPublicKey()) .signatureMethod(consumer.getSignatureMethod()) .callback(consumer.getCallback()) .twoLOAllowed(consumerEntity.isTwoLOAllowed()) .executingTwoLOUser(consumerEntity.getExecutingTwoLOUser()) .twoLOImpersonationAllowed(consumerEntity.isTwoLOImpersonationAllowed()) .build();
Consumer updatedConsumer = new Consumer.InstanceBuilder(consumer.getKey()) .name(consumer.getName()) .description(consumer.getDescription()) .publicKey(consumer.getPublicKey()) .signatureMethod(consumer.getSignatureMethod()) .callback(consumer.getCallback()) .twoLOAllowed(twoLoEnabled) .executingTwoLOUser(twoLoEnabled ? executeAsUser : null) .twoLOImpersonationAllowed(twoLoIEnabled) .build();
final Consumer consumer = Consumer.key(key).name(name).publicKey(publicKey).description(description).callback(callback) .twoLOAllowed(twoLOAllowed).executingTwoLOUser(executingTwoLOUser).twoLOImpersonationAllowed(twoLOImpersonationAllowed) .build(); providerStoreService.addConsumer(consumer, applicationLink); } catch (Exception e) {
.name(name) .publicKey(publicKey) .description(description) .callback(callback) .build(); } catch (SAXException | IOException | DOMException e) { throw new ResponseException("Unable to parse consumer information", e);
.name("Test Consumer Name") .publicKey(publicKey) .description("Consumer Description") .callback(URI.create(appProp.getBaseUrl() + "/consumer/oauthcallback1")) .twoLOAllowed(true) .executingTwoLOUser("2lo_user") .twoLOImpersonationAllowed(true) .build(); consumerStore.put(consumer); .name("Test Consumer Name") .publicKey(publicKey) .description("Consumer Description") .callback(URI.create(appProp.getBaseUrl() + "/consumer/oauthcallback1")) .twoLOAllowed(false) .executingTwoLOUser("2lo_user_changed") .twoLOImpersonationAllowed(false) .build(); consumerStore.put(consumer2);
@Test public void testServiceProviderConsumerStoreCanHandle3LOConfigurationChanges() 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")) .threeLOAllowed(false) .build(); consumerStore.put(consumer); final Consumer savedConsumer = consumerStore.get(CONSUMER_KEY); assertFalse(savedConsumer.getThreeLOAllowed()); final Consumer consumer2 = Consumer.key(CONSUMER_KEY) .name("Test Consumer Name") .publicKey(publicKey) .description("Consumer Description") .callback(URI.create(appProp.getBaseUrl() + "/consumer/oauthcallback1")) .threeLOAllowed(true) .build(); consumerStore.put(consumer2); final Consumer savedConsumer2 = consumerStore.get(CONSUMER_KEY); assertTrue(savedConsumer2.getThreeLOAllowed()); }
/** * Converts an {@code OAuthConsumer} to a {@code Consumer}. * * @param consumer {@code OAuthConsumer} to convert to a {@code Consumer} * @return {@code Consumer} converted from the {@code OAuthConsumer} */ public static Consumer fromOAuthConsumer(OAuthConsumer consumer) { checkNotNull(consumer, "consumer"); String name = (String) consumer.getProperty(ConsumerProperty.NAME); URI callback = consumer.callbackURL != null ? URI.create(consumer.callbackURL) : null; String description = (String) consumer.getProperty(ConsumerProperty.DESCRIPTION); InstanceBuilder builder = Consumer.key(consumer.consumerKey).name(name).description(description).callback(callback); if (consumer.getProperty(OAuth.OAUTH_SIGNATURE_METHOD).equals(OAuth.HMAC_SHA1)) { builder.signatureMethod(SignatureMethod.HMAC_SHA1); } else { // we could check if it's a string or byte[] and do the conversion, but for now let's keep things simple PublicKey publicKey = (PublicKey) consumer.getProperty(RSA_SHA1.PUBLIC_KEY); builder.publicKey(publicKey); } return builder.build(); }
public void updateIncomingConfig(@Nonnull ApplicationLink applink, @Nonnull OAuthConfig incoming) throws ConsumerInformationUnavailableException { checkNotNull(applink, "applink"); checkNotNull(incoming, "incoming"); if (!incoming.isEnabled()) { try { serviceProviderStoreService.removeConsumer(applink); } catch (IllegalStateException e) { log.debug("Attempting to remove non-existing consumer for Application Link '{}'", applink); log.trace("Stack trace for link '{}'", applink, e); } } else { Consumer updatedConsumer = consumerBuilder(getOrFetchConsumer(applink)) .twoLOAllowed(incoming.isTwoLoEnabled()) .twoLOImpersonationAllowed(incoming.isTwoLoImpersonationEnabled()) .build(); serviceProviderStoreService.addConsumer(updatedConsumer, applink); } }
@Test public void testServiceProviderConsumerStoreCanStoreConsumerWith2LOEnabledIndependently() 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")) .threeLOAllowed(false) .twoLOAllowed(true) .build(); consumerStore.put(consumer); final Consumer savedConsumer = consumerStore.get(CONSUMER_KEY); assertFalse(savedConsumer.getThreeLOAllowed()); assertTrue(savedConsumer.getTwoLOAllowed()); assertFalse(savedConsumer.getTwoLOImpersonationAllowed()); }
@Test public void testServiceProviderConsumerStoreCanStoreConsumerWith2LOWithImpersonationEnabledIndependently() 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")) .threeLOAllowed(false) .twoLOImpersonationAllowed(true) .build(); consumerStore.put(consumer); final Consumer savedConsumer = consumerStore.get(CONSUMER_KEY); assertFalse(savedConsumer.getThreeLOAllowed()); assertFalse(savedConsumer.getTwoLOAllowed()); assertTrue(savedConsumer.getTwoLOImpersonationAllowed()); }
@Test public void testDefault2LOParametersAreAppropriateIfLeftUntouched() 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); assertFalse(savedConsumer.getTwoLOAllowed()); assertNull(savedConsumer.getExecutingTwoLOUser()); assertFalse(savedConsumer.getTwoLOImpersonationAllowed()); }
public Consumer updateHostConsumerInformation(String name, String description, URI callback) { ConsumerAndSecret cas = hostCasProvider.get(); Consumer oldConsumer = cas.getConsumer(); Consumer newConsumer = Consumer.key(oldConsumer.getKey()) .signatureMethod(oldConsumer.getSignatureMethod()) .publicKey(oldConsumer.getPublicKey()) .name(name) .description(description) .callback(callback) .build(); if (newConsumer.getSignatureMethod() == SignatureMethod.HMAC_SHA1) { cas = new ConsumerAndSecret(cas.getServiceName(), newConsumer, cas.getSharedSecret()); } else { cas = new ConsumerAndSecret(cas.getServiceName(), newConsumer, cas.getPrivateKey()); } return hostCasProvider.put(cas).getConsumer(); }
@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()); }
@GET public Response execute(@QueryParam("refappTaId") final String refappTrustedAppsId, @QueryParam("refappOaId") final String refappOAuthId) { final PluginSettings ps = getPluginSettings(); if (refappTrustedAppsId != null) { ps.put("trustedapps", ImmutableList.of(refappTrustedAppsId)); ps.put("trustedapp." + refappTrustedAppsId, createTrustedProperties()); } if (refappOAuthId != null) { serviceProviderConsumerStore.put(new Consumer.InstanceBuilder(refappOAuthId) .name("Test orphaned consumer") .description("Atlassian RefImpl at http://localhost:5992/refapp2") .publicKey(getTestOAuthKey()) .build()); } return noContent().build(); }
@Test public void testServiceProviderConsumerStoreCanStoreOAuth2LOConfiguration() 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")) .twoLOAllowed(true) .executingTwoLOUser("2lo_user") .build(); consumerStore.put(consumer); final Consumer savedConsumer = consumerStore.get(CONSUMER_KEY); assertTrue(savedConsumer.getTwoLOAllowed()); assertEquals("2lo_user", savedConsumer.getExecutingTwoLOUser()); }
@Test public void testServiceProviderConsumerStoreCanStoreOAuth2LOImpersonationConfiguration() 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")) .twoLOImpersonationAllowed(true) .build(); consumerStore.put(consumer); final Consumer savedConsumer = consumerStore.get(CONSUMER_KEY); assertTrue(savedConsumer.getTwoLOImpersonationAllowed()); }
@Test public void testServiceProviderConsumerStoreCanStoreOAuth3LOConfiguration() 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")) .threeLOAllowed(false) .build(); consumerStore.put(consumer); final Consumer savedConsumer = consumerStore.get(CONSUMER_KEY); assertFalse(savedConsumer.getThreeLOAllowed()); }