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); }
@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); } }