Search in sources :

Example 1 with SocialProperties

use of org.springframework.boot.autoconfigure.social.SocialProperties in project syndesis by syndesisio.

the class CredentialProviderRegistry method providerWithId.

@Override
public CredentialProvider providerWithId(final String providerId) {
    final Connector connector = dataManager.fetch(Connector.class, providerId);
    if (connector == null) {
        throw new IllegalArgumentException("Unable to find connector with id: " + providerId);
    }
    final SocialProperties socialProperties;
    final String providerToUse;
    final Optional<String> authentication = connector.propertyTaggedWith(Credentials.AUTHENTICATION_TYPE_TAG);
    if (authentication.isPresent()) {
        providerToUse = authentication.get();
        if ("oauth2".equalsIgnoreCase(authentication.get())) {
            socialProperties = new OAuth2ConnectorProperties(connector);
        } else {
            socialProperties = new ConnectorSettings(connector);
        }
    } else {
        socialProperties = new ConnectorSettings(connector);
        providerToUse = providerId;
    }
    final CredentialProvider providerWithId = credentialProviderFactories.get(providerToUse).create(socialProperties);
    if (providerWithId == null) {
        throw new IllegalArgumentException("Unable to locate credential provider with id: " + providerId);
    }
    return providerWithId;
}
Also used : Connector(io.syndesis.common.model.connection.Connector) SocialProperties(org.springframework.boot.autoconfigure.social.SocialProperties)

Example 2 with SocialProperties

use of org.springframework.boot.autoconfigure.social.SocialProperties in project syndesis by syndesisio.

the class OAuth1ApplicatorTest method shouldApplyTokens.

@Test
public void shouldApplyTokens() {
    final SocialProperties properties = new SocialProperties() {
    };
    properties.setAppId("appId");
    properties.setAppSecret("appSecret");
    final OAuth1Applicator applicator = new OAuth1Applicator(properties);
    applicator.setAccessTokenSecretProperty("accessTokenSecretProperty");
    applicator.setAccessTokenValueProperty("accessTokenValueProperty");
    applicator.setConsumerKeyProperty("consumerKeyProperty");
    applicator.setConsumerSecretProperty("consumerSecretProperty");
    final Connection connection = new Connection.Builder().build();
    final Connection result = applicator.applyTo(connection, new OAuthToken("tokenValue", "tokenSecret"));
    final Connection expected = new Connection.Builder().putConfiguredProperty("accessTokenSecretProperty", "tokenSecret").putConfiguredProperty("accessTokenValueProperty", "tokenValue").putConfiguredProperty("consumerKeyProperty", "appId").putConfiguredProperty("consumerSecretProperty", "appSecret").build();
    assertThat(result).isEqualToIgnoringGivenFields(expected, "lastUpdated");
    assertThat(result.getLastUpdated()).isPresent();
}
Also used : OAuthToken(org.springframework.social.oauth1.OAuthToken) Connection(io.syndesis.common.model.connection.Connection) SocialProperties(org.springframework.boot.autoconfigure.social.SocialProperties) Test(org.junit.Test)

Example 3 with SocialProperties

use of org.springframework.boot.autoconfigure.social.SocialProperties in project syndesis by syndesisio.

the class OAuth2ApplicatorTest method shouldApplyAccessGrants.

@Test
public void shouldApplyAccessGrants() {
    final SocialProperties properties = new SocialProperties() {
    };
    properties.setAppId("appId");
    properties.setAppSecret("appSecret");
    final OAuth2Applicator applicator = new OAuth2Applicator(properties);
    applicator.setAccessTokenProperty("accessTokenProperty");
    applicator.setClientIdProperty("clientIdProperty");
    applicator.setClientSecretProperty("clientSecretProperty");
    applicator.setRefreshTokenProperty("refreshTokenProperty");
    final Connection connection = new Connection.Builder().build();
    final Connection result = applicator.applyTo(connection, new AccessGrant("accessToken", "scope", "refreshToken", 1L));
    final Connection expected = new Connection.Builder().putConfiguredProperty("accessTokenProperty", "accessToken").putConfiguredProperty("clientIdProperty", "appId").putConfiguredProperty("clientSecretProperty", "appSecret").putConfiguredProperty("refreshTokenProperty", "refreshToken").build();
    assertThat(result).isEqualToIgnoringGivenFields(expected, "lastUpdated");
    assertThat(result.getLastUpdated()).isPresent();
}
Also used : AccessGrant(org.springframework.social.oauth2.AccessGrant) Connection(io.syndesis.common.model.connection.Connection) SocialProperties(org.springframework.boot.autoconfigure.social.SocialProperties) Test(org.junit.Test)

Aggregations

SocialProperties (org.springframework.boot.autoconfigure.social.SocialProperties)3 Connection (io.syndesis.common.model.connection.Connection)2 Test (org.junit.Test)2 Connector (io.syndesis.common.model.connection.Connector)1 OAuthToken (org.springframework.social.oauth1.OAuthToken)1 AccessGrant (org.springframework.social.oauth2.AccessGrant)1