public boolean incomingEnabled(final ApplicationLink applicationLink) { final Consumer consumer = serviceProviderStoreService.getConsumer(applicationLink); return consumer != null && consumer.getTwoLOAllowed() && consumer.getTwoLOImpersonationAllowed(); }
@Nonnull public static OAuthConfig fromConsumer(@Nullable Consumer consumer) { if (consumer == null) { return OAuthConfig.createDisabledConfig(); } return OAuthConfig.fromConfig( consumer.getThreeLOAllowed(), consumer.getTwoLOAllowed(), consumer.getTwoLOImpersonationAllowed() ); }
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)); } } } }
boolean twoLOiAllowed = (consumer != null) && consumer.getTwoLOImpersonationAllowed(); if (twoLOiAllowed && !Boolean.parseBoolean(outgoing2LOiEnabledParam)) { builder.put("outgoingTwoLoiShouldBeEnabled", true);
if (!consumer.getTwoLOImpersonationAllowed()) { LOG.info("2-Legged-OAuth with Impersonation request has been attempted but 2-Legged-OAuth with Impersonation is not enabled for consumer:'{}'. Cannot access resource as user '{}'", consumer.getName(), userId); sendError(response, HttpServletResponse.SC_UNAUTHORIZED, message);
@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() ); } }
@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()); }
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; } }
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 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()); }
@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 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()); }
assertTrue(savedConsumer.getTwoLOImpersonationAllowed()); assertFalse(savedConsumer2.getTwoLOAllowed()); assertEquals("2lo_user_changed", savedConsumer2.getExecutingTwoLOUser()); assertFalse(savedConsumer2.getTwoLOImpersonationAllowed());