@Override
public Connection
create(@Context SecurityContext sec, @ConvertGroup(from = Default.class, to = AllValidations.class) final Connection connection) {
final Date rightNow = new Date();
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);
}