private Connection recreateConnection(Connection existingConnection, Connector newConnector) { Optional<Connector> connectorToUse = existingConnection.getConnector().map(old -> newConnector); Map<String, String> confProperties = new TreeMap<>(existingConnection.getConfiguredProperties()); confProperties.keySet().retainAll(newConnector.getProperties().keySet()); return new Connection.Builder() .createFrom(existingConnection) .connector(connectorToUse) .icon(newConnector.getIcon()) .configuredProperties(confProperties) .build(); }
@Override public Connection create(@Context SecurityContext sec, @ConvertGroup(from = Default.class, to = AllValidations.class) final Connection connection) { final Date rightNow = new Date(); // Lets make sure we store encrypt secrets. Map<String, String> configuredProperties =connection.getConfiguredProperties(); if( connection.getConnectorId().isPresent() ) { Map<String, ConfigurationProperty> connectorProperties = getConnectorProperties(connection.getConnectorId().get()); configuredProperties = encryptionComponent.encryptPropertyValues(configuredProperties, connectorProperties); } final Connection updatedConnection = new Connection.Builder() .createFrom(connection) .createdDate(rightNow) .lastUpdated(rightNow) .configuredProperties(configuredProperties) .userId(sec.getUserPrincipal().getName()) .build(); final Set<CredentialFlowState> flowStates = CredentialFlowState.Builder.restoreFrom(state::restoreFrom, request); final Connection connectionToCreate = flowStates.stream().map(s -> { final Cookie removal = new Cookie(s.persistenceKey(), ""); removal.setPath("/"); removal.setMaxAge(0); response.addCookie(removal); return credentials.apply(updatedConnection, s); }).findFirst().orElse(updatedConnection); return Creator.super.create(sec, connectionToCreate); }
public Connection toCurrentConnection(Connection c) { Connection connection = getDataManager().fetch(Connection.class, c.getId().get()); if (connection.getConnectorId().isPresent()) { final Connector connector = getDataManager().fetch(Connector.class, connection.getConnectorId().get()); connection = new Connection.Builder().createFrom(connection).connector(connector).build(); } return connection; }
public void testGenerate() throws Exception { IntegrationDeployment deployment = newIntegration( new SimpleStep.Builder() .stepKind("endpoint") .connection(new Connection.Builder() .id("timer-connection") .connector(TIMER_CONNECTOR) ).build()) .build(), new SimpleStep.Builder() .stepKind("endpoint") .connection(new Connection.Builder() .id("http-connection") .connector(HTTP_CONNECTOR)
.build(); final Connection connection = new Connection.Builder().connector(connector) .putConfiguredProperty("clientId", "some-clientId").build();
.build(); final Connection connection = new Connection.Builder().connector(connector) .putConfiguredProperty("clientId", "some-clientId").build();
new Connection.Builder() .createFrom(connection) .connector(connector)
@Override public void update(final String id, @ConvertGroup(from = Default.class, to = AllValidations.class) final Connection connection) { // Lets make sure we store encrypt secrets. Map<String, String> configuredProperties = connection.getConfiguredProperties(); if( connection.getConnectorId().isPresent() ) { Map<String, ConfigurationProperty> connectorProperties = getConnectorProperties(connection.getConnectorId().get()); configuredProperties = encryptionComponent.encryptPropertyValues(configuredProperties, connectorProperties); } final Connection updatedConnection = new Connection.Builder() .createFrom(connection) .configuredProperties(configuredProperties) .lastUpdated(new Date()) .build(); Updater.super.update(id, updatedConnection); // TODO: do this async perhaps.. // We may need to trigger creating bulletins for some integrations. for (String integrationId : getDataManager().fetchIds(Integration.class)) { integrationHandler.updateBulletinBoard(integrationId); } }
@Test public void findTags() { Integration integration = new Integration.Builder() .addTag("tag1") .addTag("tag2") .build(); Connection connection = new Connection.Builder() .addTag("tag2") .addTag("tag3") .build(); ListResult<String> allTags = new TagFinder() .add(ListResult.of(integration)) .add(ListResult.of(connection)) .getResult(); Assert.assertEquals( 3, allTags.getTotalCount()); Assert.assertTrue(allTags.getItems().contains("tag1") ); Assert.assertTrue(allTags.getItems().contains("tag2") ); Assert.assertTrue(allTags.getItems().contains("tag3") ); }
@Parameters public static Iterable<Object[]> parameters() { final Connection existingNameNoId = new Connection.Builder().name("Existing").build(); final Connection existingNameWithSameId = new Connection.Builder().name("Existing").id("same").build(); final Connection existingNameWithDifferentId = new Connection.Builder().name("Existing").id("different") .build(); final Connection uniqueNameNoId = new Connection.Builder().name("Unique").build(); final Integration existingButDeleted = new Integration.Builder().name("Existing").id("different").build(); return Arrays.asList(// new Object[] {existingNameNoId, false}, // new Object[] {existingNameWithSameId, true}, // new Object[] {existingNameWithDifferentId, false}, // new Object[] {uniqueNameNoId, true}, // new Object[] {existingButDeleted, true}// ); } }
/** * Default implementation that applies {@link SocialProperties} and * {@link AccessGrant} to {@link Connection.Builder}. */ @Override public final Connection applyTo(final Connection connection, final AccessGrant accessGrant) { final Connection.Builder mutableConnection = new Connection.Builder().createFrom(connection) .lastUpdated(new Date()); Applicator.applyProperty(mutableConnection, clientIdProperty, socialProperties.getAppId()); Applicator.applyProperty(mutableConnection, clientSecretProperty, socialProperties.getAppSecret()); Applicator.applyProperty(mutableConnection, accessTokenProperty, accessGrant.getAccessToken()); Applicator.applyProperty(mutableConnection, refreshTokenProperty, accessGrant.getRefreshToken()); additionalApplication(mutableConnection, accessGrant); return mutableConnection.build(); }
@Override public Connection applyTo(final Connection connection, final OAuthToken token) { final Connection.Builder mutableConnection = new Connection.Builder().createFrom(connection) .lastUpdated(new Date()); Applicator.applyProperty(mutableConnection, accessTokenValueProperty, token.getValue()); Applicator.applyProperty(mutableConnection, accessTokenSecretProperty, token.getSecret()); Applicator.applyProperty(mutableConnection, consumerKeyProperty, consumerKey); Applicator.applyProperty(mutableConnection, consumerSecretProperty, consumerSecret); return mutableConnection.build(); }
@Test public void byDefaultDerivedShouldBeFalse() { Connection connection = new Connection.Builder() .connector(new Connector.Builder() .id(KeyGenerator.createKey()) .build()) .build(); assertThat(connection.isDerived()).isFalse(); }
protected final Step newEndpointStep(String connectorId, String actionId, Consumer<Connection.Builder> connectionConsumer, Consumer<Step.Builder> stepConsumer) throws IOException { Connector connector = resourceManager.mandatoryLoadConnector(connectorId); ConnectorAction action = resourceManager.mandatoryLookupAction(connector, actionId); Connection.Builder connectionBuilder = new Connection.Builder().connector(connector); connectionConsumer.accept(connectionBuilder); Step.Builder stepBuilder = new Step.Builder().stepKind(StepKind.endpoint).action(action).connection(connectionBuilder.build()); stepConsumer.accept(stepBuilder); return stepBuilder.build(); }
public Connection apply(final Connection updatedConnection, final CredentialFlowState flowState) { final CredentialProvider credentialProvider = providerFrom(flowState); final Connection withDerivedFlag = new Connection.Builder().createFrom(updatedConnection).isDerived(true).build(); return credentialProvider.applyTo(withDerivedFlag, flowState); }
@Override public Connection get(final String id) { Connection connection = Getter.super.get(id); if (connection.getConnectorId().isPresent()) { final Connector connector = getDataManager().fetch(Connector.class, connection.getConnectorId().get()); connection = new Connection.Builder().createFrom(connection).connector(connector).build(); } return connection; }