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; }
stepBuilder.connection( new Connection.Builder() .createFrom(connection) .connector(connector) .build()
@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); } }
/** * 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(); }
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; }
@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(); }