Search in sources :

Example 1 with CredentialProvider

use of io.syndesis.server.credential.CredentialProvider in project syndesis by syndesisio.

the class TestCredentialProviderFactory method create.

@Override
public CredentialProvider create(final SocialProperties properties) {
    @SuppressWarnings("unchecked") final OAuth2ConnectionFactory<Object> connectionFactory = mock(OAuth2ConnectionFactory.class);
    when(connectionFactory.generateState()).thenReturn("test-state");
    properties.setAppId("appId");
    properties.setAppSecret("appSecret");
    final OAuth2Applicator applicator = new OAuth2Applicator(properties);
    applicator.setAccessTokenProperty("accessToken");
    applicator.setClientIdProperty("clientId");
    applicator.setClientSecretProperty("clientSecret");
    applicator.setRefreshTokenProperty("refreshToken");
    final CredentialProvider credentialProvider = new OAuth2CredentialProvider<>("test-provider", connectionFactory, applicator);
    @SuppressWarnings({ "unchecked", "rawtypes" }) final Class<MultiValueMap<String, String>> additionalParametersType = (Class) MultiValueMap.class;
    final OAuth2Operations operations = spy(new OAuth2Template("testClientId", "testClientSecret", "https://test/oauth2/authorize", "https://test/oauth2/token"));
    doReturn(new AccessGrant("token")).when(operations).exchangeForAccess(Matchers.anyString(), Matchers.anyString(), Matchers.any(additionalParametersType));
    when(connectionFactory.getOAuthOperations()).thenReturn(operations);
    return credentialProvider;
}
Also used : OAuth2Applicator(io.syndesis.server.credential.OAuth2Applicator) OAuth2CredentialProvider(io.syndesis.server.credential.OAuth2CredentialProvider) OAuth2Template(org.springframework.social.oauth2.OAuth2Template) AccessGrant(org.springframework.social.oauth2.AccessGrant) OAuth2CredentialProvider(io.syndesis.server.credential.OAuth2CredentialProvider) CredentialProvider(io.syndesis.server.credential.CredentialProvider) OAuth2Operations(org.springframework.social.oauth2.OAuth2Operations) MultiValueMap(org.springframework.util.MultiValueMap)

Example 2 with CredentialProvider

use of io.syndesis.server.credential.CredentialProvider in project syndesis by syndesisio.

the class SetupITCase method updateOauthApp.

@Test
public void updateOauthApp() {
    // Validate initial state assumptions.
    getOauthApps();
    OAuthAppHandler.OAuthApp twitter = new OAuthAppHandler.OAuthApp();
    twitter.clientId = "test-id";
    twitter.clientSecret = "test-secret";
    http(HttpMethod.PUT, "/api/v1/setup/oauth-apps/twitter", twitter, null, tokenRule.validToken(), HttpStatus.NO_CONTENT);
    ResponseEntity<OAuthAppHandler.OAuthApp[]> result = get("/api/v1/setup/oauth-apps", OAuthAppHandler.OAuthApp[].class);
    List<OAuthAppHandler.OAuthApp> apps = Arrays.asList(result.getBody());
    assertThat(apps.size()).isEqualTo(2);
    twitter = apps.stream().filter(x -> "twitter".equals(x.id)).findFirst().get();
    assertThat(twitter.id).isEqualTo("twitter");
    assertThat(twitter.name).isEqualTo("Twitter");
    assertThat(twitter.icon).isEqualTo("fa-twitter");
    assertThat(twitter.clientId).isEqualTo("test-id");
    assertThat(twitter.clientSecret).isEqualTo("test-secret");
    // Now that we have configured the app, we should be able to create the
    // connection factory.
    // The connection factory is setup async so we might need to wait a little bit
    // for it to register.
    given().ignoreExceptions().await().atMost(10, SECONDS).pollInterval(1, SECONDS).until(() -> {
        final CredentialProvider twitterCredentialProvider = locator.providerWithId("twitter");
        // preparing is something we could not do with a `null` ConnectionFactory
        assertThat(twitterCredentialProvider).isNotNull().isInstanceOfSatisfying(OAuth1CredentialProvider.class, p -> {
            final Connection connection = new Connection.Builder().build();
            final CredentialFlowState flowState = new OAuth1CredentialFlowState.Builder().accessToken(new OAuthToken("value", "secret")).connectorId("connectorId").build();
            final Connection appliedTo = p.applyTo(connection, flowState);
            // test that the updated values are used
            assertThat(appliedTo.getConfiguredProperties()).contains(entry("consumerKey", "test-id"), entry("consumerSecret", "test-secret"));
        });
        return true;
    });
}
Also used : Arrays(java.util.Arrays) CredentialFlowState(io.syndesis.server.credential.CredentialFlowState) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) HttpMethod(org.springframework.http.HttpMethod) Autowired(org.springframework.beans.factory.annotation.Autowired) Test(org.junit.Test) OAuthToken(org.springframework.social.oauth1.OAuthToken) Assertions.entry(org.assertj.core.api.Assertions.entry) Awaitility.given(org.awaitility.Awaitility.given) OAuth1CredentialFlowState(io.syndesis.server.credential.OAuth1CredentialFlowState) HttpStatus(org.springframework.http.HttpStatus) List(java.util.List) Connection(io.syndesis.common.model.connection.Connection) CredentialProvider(io.syndesis.server.credential.CredentialProvider) CredentialProviderLocator(io.syndesis.server.credential.CredentialProviderLocator) ResponseEntity(org.springframework.http.ResponseEntity) OAuth1CredentialProvider(io.syndesis.server.credential.OAuth1CredentialProvider) OAuthAppHandler(io.syndesis.server.endpoint.v1.handler.setup.OAuthAppHandler) SECONDS(java.util.concurrent.TimeUnit.SECONDS) CredentialFlowState(io.syndesis.server.credential.CredentialFlowState) OAuth1CredentialFlowState(io.syndesis.server.credential.OAuth1CredentialFlowState) Connection(io.syndesis.common.model.connection.Connection) OAuth1CredentialFlowState(io.syndesis.server.credential.OAuth1CredentialFlowState) OAuthAppHandler(io.syndesis.server.endpoint.v1.handler.setup.OAuthAppHandler) OAuthToken(org.springframework.social.oauth1.OAuthToken) CredentialProvider(io.syndesis.server.credential.CredentialProvider) OAuth1CredentialProvider(io.syndesis.server.credential.OAuth1CredentialProvider) Test(org.junit.Test)

Aggregations

CredentialProvider (io.syndesis.server.credential.CredentialProvider)2 Connection (io.syndesis.common.model.connection.Connection)1 CredentialFlowState (io.syndesis.server.credential.CredentialFlowState)1 CredentialProviderLocator (io.syndesis.server.credential.CredentialProviderLocator)1 OAuth1CredentialFlowState (io.syndesis.server.credential.OAuth1CredentialFlowState)1 OAuth1CredentialProvider (io.syndesis.server.credential.OAuth1CredentialProvider)1 OAuth2Applicator (io.syndesis.server.credential.OAuth2Applicator)1 OAuth2CredentialProvider (io.syndesis.server.credential.OAuth2CredentialProvider)1 OAuthAppHandler (io.syndesis.server.endpoint.v1.handler.setup.OAuthAppHandler)1 Arrays (java.util.Arrays)1 List (java.util.List)1 SECONDS (java.util.concurrent.TimeUnit.SECONDS)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Assertions.entry (org.assertj.core.api.Assertions.entry)1 Awaitility.given (org.awaitility.Awaitility.given)1 Test (org.junit.Test)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 HttpMethod (org.springframework.http.HttpMethod)1 HttpStatus (org.springframework.http.HttpStatus)1 ResponseEntity (org.springframework.http.ResponseEntity)1