SYCOPE-910 - Introduce new Camel propagation component - part I
Project: http://git-wip-us.apache.org/repos/asf/syncope/repo Commit: http://git-wip-us.apache.org/repos/asf/syncope/commit/6ae50200 Tree: http://git-wip-us.apache.org/repos/asf/syncope/tree/6ae50200 Diff: http://git-wip-us.apache.org/repos/asf/syncope/diff/6ae50200 Branch: refs/heads/master Commit: 6ae5020032be616fcdf44510ea0572586cff0814 Parents: 012f97b Author: Colm O hEigeartaigh <cohei...@apache.org> Authored: Thu Jul 28 14:08:00 2016 +0100 Committer: Colm O hEigeartaigh <cohei...@apache.org> Committed: Thu Jul 28 14:08:00 2016 +0100 ---------------------------------------------------------------------- .../core/provisioning/camel/AnyType.java | 23 ++++ .../camel/component/PropagateComponent.java | 71 ++++++++++ .../camel/component/PropagateEndpoint.java | 138 +++++++++++++++++++ .../camel/component/PropagateType.java | 23 ++++ .../processor/AnyObjectDeleteProcessor.java | 63 --------- .../AnyObjectDeprovisionProcessor.java | 68 --------- .../processor/AnyObjectProvisionProcessor.java | 66 --------- .../camel/processor/CreateProcessor.java | 91 ------------ .../camel/processor/GroupDeleteProcessor.java | 95 ------------- .../processor/GroupDeprovisionProcessor.java | 68 --------- .../processor/GroupProvisionProcessor.java | 66 --------- .../camel/processor/UpdateProcessor.java | 92 ------------- .../camel/processor/UserDeleteProcessor.java | 74 ---------- .../processor/UserDeprovisionProcessor.java | 68 --------- .../camel/processor/UserProvisionProcessor.java | 93 ------------- .../camel/producer/AbstractProducer.java | 57 ++++++++ .../camel/producer/CreateProducer.java | 86 ++++++++++++ .../camel/producer/DeleteProducer.java | 118 ++++++++++++++++ .../camel/producer/DeprovisionProducer.java | 94 +++++++++++++ .../camel/producer/ProvisionProducer.java | 107 ++++++++++++++ .../camel/producer/UpdateProducer.java | 83 +++++++++++ .../org/apache/camel/component/propagate | 19 +++ .../src/main/resources/anyObjectRoutes.xml | 10 +- .../src/main/resources/groupRoutes.xml | 10 +- .../src/main/resources/userRoutes.xml | 10 +- .../syncope/fit/core/CamelRouteITCase.java | 4 +- 26 files changed, 836 insertions(+), 861 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/syncope/blob/6ae50200/ext/camel/provisioning-camel/src/main/java/org/apache/syncope/core/provisioning/camel/AnyType.java ---------------------------------------------------------------------- diff --git a/ext/camel/provisioning-camel/src/main/java/org/apache/syncope/core/provisioning/camel/AnyType.java b/ext/camel/provisioning-camel/src/main/java/org/apache/syncope/core/provisioning/camel/AnyType.java new file mode 100644 index 0000000..d1d9b9e --- /dev/null +++ b/ext/camel/provisioning-camel/src/main/java/org/apache/syncope/core/provisioning/camel/AnyType.java @@ -0,0 +1,23 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.syncope.core.provisioning.camel; + +public enum AnyType { + + user, group, any + +} http://git-wip-us.apache.org/repos/asf/syncope/blob/6ae50200/ext/camel/provisioning-camel/src/main/java/org/apache/syncope/core/provisioning/camel/component/PropagateComponent.java ---------------------------------------------------------------------- diff --git a/ext/camel/provisioning-camel/src/main/java/org/apache/syncope/core/provisioning/camel/component/PropagateComponent.java b/ext/camel/provisioning-camel/src/main/java/org/apache/syncope/core/provisioning/camel/component/PropagateComponent.java new file mode 100644 index 0000000..a904b47 --- /dev/null +++ b/ext/camel/provisioning-camel/src/main/java/org/apache/syncope/core/provisioning/camel/component/PropagateComponent.java @@ -0,0 +1,71 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.syncope.core.provisioning.camel.component; + +import java.util.Map; + +import org.apache.camel.Endpoint; +import org.apache.camel.impl.UriEndpointComponent; +import org.apache.syncope.core.persistence.api.dao.AnyObjectDAO; +import org.apache.syncope.core.persistence.api.dao.GroupDAO; +import org.apache.syncope.core.persistence.api.dao.UserDAO; +import org.apache.syncope.core.provisioning.api.data.GroupDataBinder; +import org.apache.syncope.core.provisioning.api.propagation.PropagationManager; +import org.apache.syncope.core.provisioning.api.propagation.PropagationTaskExecutor; +import org.springframework.beans.factory.annotation.Autowired; + +public class PropagateComponent extends UriEndpointComponent { + + @Autowired + protected PropagationManager propagationManager; + + @Autowired + protected PropagationTaskExecutor taskExecutor; + + @Autowired + protected UserDAO userDAO; + + @Autowired + protected GroupDAO groupDAO; + + @Autowired + protected AnyObjectDAO anyObjectDAO; + + @Autowired + protected GroupDataBinder groupDataBinder; + + public PropagateComponent() { + super(PropagateEndpoint.class); + } + + protected Endpoint createEndpoint(final String uri, final String remaining, + final Map<String, Object> parameters) throws Exception { + PropagateType type = PropagateType.valueOf(remaining); + PropagateEndpoint endpoint = new PropagateEndpoint(uri, this); + endpoint.setPropagateType(type); + endpoint.setPropagationManager(propagationManager); + endpoint.setPropagationTaskExecutor(taskExecutor); + endpoint.setUserDAO(userDAO); + endpoint.setGroupDAO(groupDAO); + endpoint.setAnyObjectDAO(anyObjectDAO); + endpoint.setGroupDataBinder(groupDataBinder); + + setProperties(endpoint, parameters); + return endpoint; + } + +} http://git-wip-us.apache.org/repos/asf/syncope/blob/6ae50200/ext/camel/provisioning-camel/src/main/java/org/apache/syncope/core/provisioning/camel/component/PropagateEndpoint.java ---------------------------------------------------------------------- diff --git a/ext/camel/provisioning-camel/src/main/java/org/apache/syncope/core/provisioning/camel/component/PropagateEndpoint.java b/ext/camel/provisioning-camel/src/main/java/org/apache/syncope/core/provisioning/camel/component/PropagateEndpoint.java new file mode 100644 index 0000000..7dff3a9 --- /dev/null +++ b/ext/camel/provisioning-camel/src/main/java/org/apache/syncope/core/provisioning/camel/component/PropagateEndpoint.java @@ -0,0 +1,138 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.syncope.core.provisioning.camel.component; + +import org.apache.camel.Component; +import org.apache.camel.Consumer; +import org.apache.camel.Processor; +import org.apache.camel.Producer; +import org.apache.camel.impl.DefaultEndpoint; +import org.apache.camel.spi.Metadata; +import org.apache.camel.spi.UriEndpoint; +import org.apache.camel.spi.UriParam; +import org.apache.camel.spi.UriPath; +import org.apache.syncope.core.persistence.api.dao.AnyObjectDAO; +import org.apache.syncope.core.persistence.api.dao.GroupDAO; +import org.apache.syncope.core.persistence.api.dao.UserDAO; +import org.apache.syncope.core.provisioning.api.data.GroupDataBinder; +import org.apache.syncope.core.provisioning.api.propagation.PropagationManager; +import org.apache.syncope.core.provisioning.api.propagation.PropagationTaskExecutor; +import org.apache.syncope.core.provisioning.camel.AnyType; +import org.apache.syncope.core.provisioning.camel.producer.AbstractProducer; +import org.apache.syncope.core.provisioning.camel.producer.CreateProducer; +import org.apache.syncope.core.provisioning.camel.producer.DeleteProducer; +import org.apache.syncope.core.provisioning.camel.producer.DeprovisionProducer; +import org.apache.syncope.core.provisioning.camel.producer.ProvisionProducer; +import org.apache.syncope.core.provisioning.camel.producer.UpdateProducer; + +@UriEndpoint(scheme = "propagate", title = "propagate", syntax = "propagate:propagateType", producerOnly = true) +public class PropagateEndpoint extends DefaultEndpoint { + + @UriPath @Metadata(required = "true") + private PropagateType propagateType; + + @UriParam + private AnyType anyType; + + private PropagationManager propagationManager; + + private PropagationTaskExecutor taskExecutor; + + private UserDAO userDAO; + + private GroupDAO groupDAO; + + private AnyObjectDAO anyObjectDAO; + + private GroupDataBinder groupDataBinder; + + public PropagateEndpoint(final String endpointUri, final Component component) { + super(endpointUri, component); + } + + @Override + public Producer createProducer() throws Exception { + AbstractProducer producer = null; + if (PropagateType.create == propagateType) { + producer = new CreateProducer(this, anyType); + } else if (PropagateType.update == propagateType) { + producer = new UpdateProducer(this, anyType); + } else if (PropagateType.delete == propagateType) { + producer = new DeleteProducer(this, anyType, userDAO, groupDataBinder); + } else if (PropagateType.provision == propagateType) { + producer = new ProvisionProducer(this, anyType); + } else if (PropagateType.deprovision == propagateType) { + producer = new DeprovisionProducer(this, anyType, userDAO, groupDAO, anyObjectDAO); + } + + if (producer != null) { + producer.setPropagationManager(propagationManager); + producer.setPropagationTaskExecutor(taskExecutor); + } + return producer; + } + + @Override + public Consumer createConsumer(final Processor processor) throws Exception { + throw new UnsupportedOperationException("Consumer not supported"); + } + + @Override + public boolean isSingleton() { + return false; + } + + public PropagateType getPropagateType() { + return propagateType; + } + + public void setPropagateType(final PropagateType propagateType) { + this.propagateType = propagateType; + } + + public void setPropagationManager(final PropagationManager propagationManager) { + this.propagationManager = propagationManager; + } + + public void setPropagationTaskExecutor(final PropagationTaskExecutor taskExecutor) { + this.taskExecutor = taskExecutor; + } + + public AnyType getAnyType() { + return anyType; + } + + public void setAnyType(final AnyType anyType) { + this.anyType = anyType; + } + + public void setUserDAO(final UserDAO userDAO) { + this.userDAO = userDAO; + } + + public void setGroupDAO(final GroupDAO groupDAO) { + this.groupDAO = groupDAO; + } + + public void setAnyObjectDAO(final AnyObjectDAO anyObjectDAO) { + this.anyObjectDAO = anyObjectDAO; + } + + public void setGroupDataBinder(final GroupDataBinder groupDataBinder) { + this.groupDataBinder = groupDataBinder; + } +} http://git-wip-us.apache.org/repos/asf/syncope/blob/6ae50200/ext/camel/provisioning-camel/src/main/java/org/apache/syncope/core/provisioning/camel/component/PropagateType.java ---------------------------------------------------------------------- diff --git a/ext/camel/provisioning-camel/src/main/java/org/apache/syncope/core/provisioning/camel/component/PropagateType.java b/ext/camel/provisioning-camel/src/main/java/org/apache/syncope/core/provisioning/camel/component/PropagateType.java new file mode 100644 index 0000000..ca0ae1a --- /dev/null +++ b/ext/camel/provisioning-camel/src/main/java/org/apache/syncope/core/provisioning/camel/component/PropagateType.java @@ -0,0 +1,23 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.syncope.core.provisioning.camel.component; + +public enum PropagateType { + + create, update, delete, provision, deprovision + +} http://git-wip-us.apache.org/repos/asf/syncope/blob/6ae50200/ext/camel/provisioning-camel/src/main/java/org/apache/syncope/core/provisioning/camel/processor/AnyObjectDeleteProcessor.java ---------------------------------------------------------------------- diff --git a/ext/camel/provisioning-camel/src/main/java/org/apache/syncope/core/provisioning/camel/processor/AnyObjectDeleteProcessor.java b/ext/camel/provisioning-camel/src/main/java/org/apache/syncope/core/provisioning/camel/processor/AnyObjectDeleteProcessor.java deleted file mode 100644 index e87a6ab..0000000 --- a/ext/camel/provisioning-camel/src/main/java/org/apache/syncope/core/provisioning/camel/processor/AnyObjectDeleteProcessor.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.syncope.core.provisioning.camel.processor; - -import java.util.List; -import java.util.Set; -import org.apache.camel.Exchange; -import org.apache.camel.Processor; -import org.apache.syncope.common.lib.types.AnyTypeKind; -import org.apache.syncope.core.persistence.api.entity.task.PropagationTask; -import org.apache.syncope.core.provisioning.api.propagation.PropagationManager; -import org.apache.syncope.core.provisioning.api.propagation.PropagationReporter; -import org.apache.syncope.core.provisioning.api.propagation.PropagationTaskExecutor; -import org.apache.syncope.core.workflow.api.AnyObjectWorkflowAdapter; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -@Component -public class AnyObjectDeleteProcessor implements Processor { - - @Autowired - protected AnyObjectWorkflowAdapter gwfAdapter; - - @Autowired - protected PropagationManager propagationManager; - - @Autowired - protected PropagationTaskExecutor taskExecutor; - - @Override - public void process(final Exchange exchange) throws Exception { - String key = exchange.getIn().getBody(String.class); - @SuppressWarnings("unchecked") - Set<String> excludedResources = exchange.getProperty("excludedResources", Set.class); - Boolean nullPriorityAsync = exchange.getProperty("nullPriorityAsync", Boolean.class); - - List<PropagationTask> tasks = propagationManager.getDeleteTasks( - AnyTypeKind.ANY_OBJECT, - key, - null, - excludedResources); - PropagationReporter propagationReporter = taskExecutor.execute(tasks, nullPriorityAsync); - - exchange.setProperty("statuses", propagationReporter.getStatuses()); - } - -} http://git-wip-us.apache.org/repos/asf/syncope/blob/6ae50200/ext/camel/provisioning-camel/src/main/java/org/apache/syncope/core/provisioning/camel/processor/AnyObjectDeprovisionProcessor.java ---------------------------------------------------------------------- diff --git a/ext/camel/provisioning-camel/src/main/java/org/apache/syncope/core/provisioning/camel/processor/AnyObjectDeprovisionProcessor.java b/ext/camel/provisioning-camel/src/main/java/org/apache/syncope/core/provisioning/camel/processor/AnyObjectDeprovisionProcessor.java deleted file mode 100644 index c16708d..0000000 --- a/ext/camel/provisioning-camel/src/main/java/org/apache/syncope/core/provisioning/camel/processor/AnyObjectDeprovisionProcessor.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.syncope.core.provisioning.camel.processor; - -import java.util.List; -import org.apache.camel.Exchange; -import org.apache.camel.Processor; -import org.apache.commons.collections4.CollectionUtils; -import org.apache.syncope.common.lib.types.AnyTypeKind; -import org.apache.syncope.core.provisioning.api.PropagationByResource; -import org.apache.syncope.common.lib.types.ResourceOperation; -import org.apache.syncope.core.persistence.api.dao.AnyObjectDAO; -import org.apache.syncope.core.persistence.api.entity.task.PropagationTask; -import org.apache.syncope.core.provisioning.api.propagation.PropagationManager; -import org.apache.syncope.core.provisioning.api.propagation.PropagationReporter; -import org.apache.syncope.core.provisioning.api.propagation.PropagationTaskExecutor; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -@Component -public class AnyObjectDeprovisionProcessor implements Processor { - - @Autowired - protected PropagationManager propagationManager; - - @Autowired - protected PropagationTaskExecutor taskExecutor; - - @Autowired - protected AnyObjectDAO anyObjectDAO; - - @SuppressWarnings("unchecked") - @Override - public void process(final Exchange exchange) { - String key = exchange.getIn().getBody(String.class); - List<String> resources = exchange.getProperty("resources", List.class); - Boolean nullPriorityAsync = exchange.getProperty("nullPriorityAsync", Boolean.class); - - PropagationByResource propByRes = new PropagationByResource(); - propByRes.addAll(ResourceOperation.DELETE, resources); - - List<PropagationTask> tasks = propagationManager.getDeleteTasks( - AnyTypeKind.ANY_OBJECT, - key, - propByRes, - CollectionUtils.removeAll(anyObjectDAO.findAllResourceNames(key), resources)); - PropagationReporter propagationReporter = taskExecutor.execute(tasks, nullPriorityAsync); - - exchange.getOut().setBody(propagationReporter.getStatuses()); - } - -} http://git-wip-us.apache.org/repos/asf/syncope/blob/6ae50200/ext/camel/provisioning-camel/src/main/java/org/apache/syncope/core/provisioning/camel/processor/AnyObjectProvisionProcessor.java ---------------------------------------------------------------------- diff --git a/ext/camel/provisioning-camel/src/main/java/org/apache/syncope/core/provisioning/camel/processor/AnyObjectProvisionProcessor.java b/ext/camel/provisioning-camel/src/main/java/org/apache/syncope/core/provisioning/camel/processor/AnyObjectProvisionProcessor.java deleted file mode 100644 index c548a27..0000000 --- a/ext/camel/provisioning-camel/src/main/java/org/apache/syncope/core/provisioning/camel/processor/AnyObjectProvisionProcessor.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.syncope.core.provisioning.camel.processor; - -import java.util.List; -import org.apache.camel.Exchange; -import org.apache.camel.Processor; -import org.apache.syncope.common.lib.types.AnyTypeKind; -import org.apache.syncope.core.provisioning.api.PropagationByResource; -import org.apache.syncope.common.lib.types.ResourceOperation; -import org.apache.syncope.core.persistence.api.entity.task.PropagationTask; -import org.apache.syncope.core.provisioning.api.propagation.PropagationManager; -import org.apache.syncope.core.provisioning.api.propagation.PropagationReporter; -import org.apache.syncope.core.provisioning.api.propagation.PropagationTaskExecutor; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -@Component -public class AnyObjectProvisionProcessor implements Processor { - - @Autowired - protected PropagationManager propagationManager; - - @Autowired - protected PropagationTaskExecutor taskExecutor; - - @SuppressWarnings("unchecked") - @Override - public void process(final Exchange exchange) { - String key = exchange.getIn().getBody(String.class); - List<String> resources = exchange.getProperty("resources", List.class); - Boolean nullPriorityAsync = exchange.getProperty("nullPriorityAsync", Boolean.class); - - PropagationByResource propByRes = new PropagationByResource(); - propByRes.addAll(ResourceOperation.UPDATE, resources); - - List<PropagationTask> tasks = propagationManager.getUpdateTasks( - AnyTypeKind.ANY_OBJECT, - key, - false, - null, - propByRes, - null, - null); - PropagationReporter propagationReporter = taskExecutor.execute(tasks, nullPriorityAsync); - - exchange.getOut().setBody(propagationReporter.getStatuses()); - } - -} http://git-wip-us.apache.org/repos/asf/syncope/blob/6ae50200/ext/camel/provisioning-camel/src/main/java/org/apache/syncope/core/provisioning/camel/processor/CreateProcessor.java ---------------------------------------------------------------------- diff --git a/ext/camel/provisioning-camel/src/main/java/org/apache/syncope/core/provisioning/camel/processor/CreateProcessor.java b/ext/camel/provisioning-camel/src/main/java/org/apache/syncope/core/provisioning/camel/processor/CreateProcessor.java deleted file mode 100644 index 494e319..0000000 --- a/ext/camel/provisioning-camel/src/main/java/org/apache/syncope/core/provisioning/camel/processor/CreateProcessor.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.syncope.core.provisioning.camel.processor; - -import java.util.List; -import java.util.Set; -import org.apache.camel.Exchange; -import org.apache.camel.Processor; -import org.apache.commons.lang3.tuple.ImmutablePair; -import org.apache.commons.lang3.tuple.Pair; -import org.apache.syncope.common.lib.to.AnyObjectTO; -import org.apache.syncope.common.lib.to.AnyTO; -import org.apache.syncope.common.lib.to.UserTO; -import org.apache.syncope.common.lib.types.AnyTypeKind; -import org.apache.syncope.core.persistence.api.entity.task.PropagationTask; -import org.apache.syncope.core.provisioning.api.WorkflowResult; -import org.apache.syncope.core.provisioning.api.propagation.PropagationManager; -import org.apache.syncope.core.provisioning.api.propagation.PropagationReporter; -import org.apache.syncope.core.provisioning.api.propagation.PropagationTaskExecutor; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -@Component -public class CreateProcessor implements Processor { - - @Autowired - protected PropagationManager propagationManager; - - @Autowired - protected PropagationTaskExecutor taskExecutor; - - @SuppressWarnings("unchecked") - @Override - public void process(final Exchange exchange) { - if ((exchange.getIn().getBody() instanceof WorkflowResult)) { - Object actual = exchange.getProperty("actual"); - Set<String> excludedResources = exchange.getProperty("excludedResources", Set.class); - Boolean nullPriorityAsync = exchange.getProperty("nullPriorityAsync", Boolean.class); - - if (actual instanceof UserTO) { - WorkflowResult<Pair<String, Boolean>> created = - (WorkflowResult<Pair<String, Boolean>>) exchange.getIn().getBody(); - - List<PropagationTask> tasks = propagationManager.getUserCreateTasks( - created.getResult().getKey(), - ((UserTO) actual).getPassword(), - created.getResult().getValue(), - created.getPropByRes(), - ((UserTO) actual).getVirAttrs(), - excludedResources); - PropagationReporter propagationReporter = taskExecutor.execute(tasks, nullPriorityAsync); - - exchange.getOut().setBody( - new ImmutablePair<>(created.getResult().getKey(), propagationReporter.getStatuses())); - } else if (actual instanceof AnyTO) { - WorkflowResult<String> created = (WorkflowResult<String>) exchange.getIn().getBody(); - - AnyTypeKind anyTypeKind = AnyTypeKind.GROUP; - if (actual instanceof AnyObjectTO) { - anyTypeKind = AnyTypeKind.ANY_OBJECT; - } - List<PropagationTask> tasks = propagationManager.getCreateTasks( - anyTypeKind, - created.getResult(), - created.getPropByRes(), - ((AnyTO) actual).getVirAttrs(), - excludedResources); - PropagationReporter propagationReporter = taskExecutor.execute(tasks, nullPriorityAsync); - - exchange.getOut().setBody(new ImmutablePair<>(created.getResult(), propagationReporter.getStatuses())); - } - } - } - -} http://git-wip-us.apache.org/repos/asf/syncope/blob/6ae50200/ext/camel/provisioning-camel/src/main/java/org/apache/syncope/core/provisioning/camel/processor/GroupDeleteProcessor.java ---------------------------------------------------------------------- diff --git a/ext/camel/provisioning-camel/src/main/java/org/apache/syncope/core/provisioning/camel/processor/GroupDeleteProcessor.java b/ext/camel/provisioning-camel/src/main/java/org/apache/syncope/core/provisioning/camel/processor/GroupDeleteProcessor.java deleted file mode 100644 index 32c9823..0000000 --- a/ext/camel/provisioning-camel/src/main/java/org/apache/syncope/core/provisioning/camel/processor/GroupDeleteProcessor.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.syncope.core.provisioning.camel.processor; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Set; -import org.apache.camel.Exchange; -import org.apache.camel.Processor; -import org.apache.syncope.common.lib.types.AnyTypeKind; -import org.apache.syncope.core.persistence.api.entity.task.PropagationTask; -import org.apache.syncope.core.provisioning.api.PropagationByResource; -import org.apache.syncope.core.provisioning.api.data.GroupDataBinder; -import org.apache.syncope.core.provisioning.api.propagation.PropagationManager; -import org.apache.syncope.core.provisioning.api.propagation.PropagationReporter; -import org.apache.syncope.core.provisioning.api.propagation.PropagationTaskExecutor; -import org.apache.syncope.core.workflow.api.GroupWorkflowAdapter; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -@Component -public class GroupDeleteProcessor implements Processor { - - @Autowired - protected GroupWorkflowAdapter gwfAdapter; - - @Autowired - protected PropagationManager propagationManager; - - @Autowired - protected PropagationTaskExecutor taskExecutor; - - @Autowired - protected GroupDataBinder groupDataBinder; - - @Override - public void process(final Exchange exchange) throws Exception { - String key = exchange.getIn().getBody(String.class); - @SuppressWarnings("unchecked") - Set<String> excludedResources = exchange.getProperty("excludedResources", Set.class); - Boolean nullPriorityAsync = exchange.getProperty("nullPriorityAsync", Boolean.class); - - List<PropagationTask> tasks = new ArrayList<>(); - - // Generate propagation tasks for deleting users from group resources, if they are on those resources only - // because of the reason being deleted (see SYNCOPE-357) - for (Map.Entry<String, PropagationByResource> entry - : groupDataBinder.findUsersWithTransitiveResources(key).entrySet()) { - - tasks.addAll(propagationManager.getDeleteTasks( - AnyTypeKind.USER, - entry.getKey(), - entry.getValue(), - excludedResources)); - } - for (Map.Entry<String, PropagationByResource> entry - : groupDataBinder.findAnyObjectsWithTransitiveResources(key).entrySet()) { - - tasks.addAll(propagationManager.getDeleteTasks( - AnyTypeKind.ANY_OBJECT, - entry.getKey(), - entry.getValue(), - excludedResources)); - } - - // Generate propagation tasks for deleting this group from resources - tasks.addAll(propagationManager.getDeleteTasks( - AnyTypeKind.GROUP, - key, - null, - null)); - - PropagationReporter propagationReporter = taskExecutor.execute(tasks, nullPriorityAsync); - - exchange.setProperty("statuses", propagationReporter.getStatuses()); - } - -} http://git-wip-us.apache.org/repos/asf/syncope/blob/6ae50200/ext/camel/provisioning-camel/src/main/java/org/apache/syncope/core/provisioning/camel/processor/GroupDeprovisionProcessor.java ---------------------------------------------------------------------- diff --git a/ext/camel/provisioning-camel/src/main/java/org/apache/syncope/core/provisioning/camel/processor/GroupDeprovisionProcessor.java b/ext/camel/provisioning-camel/src/main/java/org/apache/syncope/core/provisioning/camel/processor/GroupDeprovisionProcessor.java deleted file mode 100644 index fc886b7..0000000 --- a/ext/camel/provisioning-camel/src/main/java/org/apache/syncope/core/provisioning/camel/processor/GroupDeprovisionProcessor.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.syncope.core.provisioning.camel.processor; - -import java.util.List; -import org.apache.camel.Exchange; -import org.apache.camel.Processor; -import org.apache.commons.collections4.CollectionUtils; -import org.apache.syncope.common.lib.types.AnyTypeKind; -import org.apache.syncope.core.provisioning.api.PropagationByResource; -import org.apache.syncope.common.lib.types.ResourceOperation; -import org.apache.syncope.core.persistence.api.dao.GroupDAO; -import org.apache.syncope.core.persistence.api.entity.task.PropagationTask; -import org.apache.syncope.core.provisioning.api.propagation.PropagationManager; -import org.apache.syncope.core.provisioning.api.propagation.PropagationReporter; -import org.apache.syncope.core.provisioning.api.propagation.PropagationTaskExecutor; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -@Component -public class GroupDeprovisionProcessor implements Processor { - - @Autowired - protected PropagationManager propagationManager; - - @Autowired - protected PropagationTaskExecutor taskExecutor; - - @Autowired - protected GroupDAO groupDAO; - - @SuppressWarnings("unchecked") - @Override - public void process(final Exchange exchange) { - String key = exchange.getIn().getBody(String.class); - List<String> resources = exchange.getProperty("resources", List.class); - Boolean nullPriorityAsync = exchange.getProperty("nullPriorityAsync", Boolean.class); - - PropagationByResource propByRes = new PropagationByResource(); - propByRes.addAll(ResourceOperation.DELETE, resources); - - List<PropagationTask> tasks = propagationManager.getDeleteTasks( - AnyTypeKind.GROUP, - key, - propByRes, - CollectionUtils.removeAll(groupDAO.authFind(key).getResourceKeys(), resources)); - PropagationReporter propagationReporter = taskExecutor.execute(tasks, nullPriorityAsync); - - exchange.getOut().setBody(propagationReporter.getStatuses()); - } - -} http://git-wip-us.apache.org/repos/asf/syncope/blob/6ae50200/ext/camel/provisioning-camel/src/main/java/org/apache/syncope/core/provisioning/camel/processor/GroupProvisionProcessor.java ---------------------------------------------------------------------- diff --git a/ext/camel/provisioning-camel/src/main/java/org/apache/syncope/core/provisioning/camel/processor/GroupProvisionProcessor.java b/ext/camel/provisioning-camel/src/main/java/org/apache/syncope/core/provisioning/camel/processor/GroupProvisionProcessor.java deleted file mode 100644 index d2398dd..0000000 --- a/ext/camel/provisioning-camel/src/main/java/org/apache/syncope/core/provisioning/camel/processor/GroupProvisionProcessor.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.syncope.core.provisioning.camel.processor; - -import java.util.List; -import org.apache.camel.Exchange; -import org.apache.camel.Processor; -import org.apache.syncope.common.lib.types.AnyTypeKind; -import org.apache.syncope.core.provisioning.api.PropagationByResource; -import org.apache.syncope.common.lib.types.ResourceOperation; -import org.apache.syncope.core.persistence.api.entity.task.PropagationTask; -import org.apache.syncope.core.provisioning.api.propagation.PropagationManager; -import org.apache.syncope.core.provisioning.api.propagation.PropagationReporter; -import org.apache.syncope.core.provisioning.api.propagation.PropagationTaskExecutor; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -@Component -public class GroupProvisionProcessor implements Processor { - - @Autowired - protected PropagationManager propagationManager; - - @Autowired - protected PropagationTaskExecutor taskExecutor; - - @SuppressWarnings("unchecked") - @Override - public void process(final Exchange exchange) { - String key = exchange.getIn().getBody(String.class); - List<String> resources = exchange.getProperty("resources", List.class); - Boolean nullPriorityAsync = exchange.getProperty("nullPriorityAsync", Boolean.class); - - PropagationByResource propByRes = new PropagationByResource(); - propByRes.addAll(ResourceOperation.UPDATE, resources); - - List<PropagationTask> tasks = propagationManager.getUpdateTasks( - AnyTypeKind.GROUP, - key, - false, - null, - propByRes, - null, - null); - PropagationReporter propagationReporter = taskExecutor.execute(tasks, nullPriorityAsync); - - exchange.getOut().setBody(propagationReporter.getStatuses()); - } - -} http://git-wip-us.apache.org/repos/asf/syncope/blob/6ae50200/ext/camel/provisioning-camel/src/main/java/org/apache/syncope/core/provisioning/camel/processor/UpdateProcessor.java ---------------------------------------------------------------------- diff --git a/ext/camel/provisioning-camel/src/main/java/org/apache/syncope/core/provisioning/camel/processor/UpdateProcessor.java b/ext/camel/provisioning-camel/src/main/java/org/apache/syncope/core/provisioning/camel/processor/UpdateProcessor.java deleted file mode 100644 index aca3371..0000000 --- a/ext/camel/provisioning-camel/src/main/java/org/apache/syncope/core/provisioning/camel/processor/UpdateProcessor.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.syncope.core.provisioning.camel.processor; - -import java.util.List; -import java.util.Set; - -import org.apache.camel.Exchange; -import org.apache.camel.Processor; -import org.apache.commons.lang3.tuple.ImmutablePair; -import org.apache.commons.lang3.tuple.Pair; -import org.apache.syncope.common.lib.patch.AnyObjectPatch; -import org.apache.syncope.common.lib.patch.AnyPatch; -import org.apache.syncope.common.lib.patch.UserPatch; -import org.apache.syncope.common.lib.types.AnyTypeKind; -import org.apache.syncope.core.persistence.api.entity.task.PropagationTask; -import org.apache.syncope.core.provisioning.api.VirAttrHandler; -import org.apache.syncope.core.provisioning.api.WorkflowResult; -import org.apache.syncope.core.provisioning.api.propagation.PropagationManager; -import org.apache.syncope.core.provisioning.api.propagation.PropagationReporter; -import org.apache.syncope.core.provisioning.api.propagation.PropagationTaskExecutor; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -@Component -public class UpdateProcessor implements Processor { - - @Autowired - protected PropagationManager propagationManager; - - @Autowired - protected PropagationTaskExecutor taskExecutor; - - @Autowired - protected VirAttrHandler virtAttrHandler; - - @Override - @SuppressWarnings("unchecked") - public void process(final Exchange exchange) { - if ((exchange.getIn().getBody() instanceof WorkflowResult)) { - Object actual = exchange.getProperty("actual"); - Boolean nullPriorityAsync = exchange.getProperty("nullPriorityAsync", Boolean.class); - Set<String> excludedResources = exchange.getProperty("excludedResources", Set.class); - - if (actual instanceof UserPatch) { - WorkflowResult<Pair<UserPatch, Boolean>> updated = - (WorkflowResult<Pair<UserPatch, Boolean>>) exchange.getIn().getBody(); - - List<PropagationTask> tasks = propagationManager.getUserUpdateTasks(updated); - PropagationReporter propagationReporter = taskExecutor.execute(tasks, nullPriorityAsync); - - exchange.getOut().setBody(new ImmutablePair<>( - updated.getResult().getKey().getKey(), propagationReporter.getStatuses())); - } else if (actual instanceof AnyPatch) { - WorkflowResult<String> updated = (WorkflowResult<String>) exchange.getIn().getBody(); - - AnyTypeKind anyTypeKind = AnyTypeKind.GROUP; - if (actual instanceof AnyObjectPatch) { - anyTypeKind = AnyTypeKind.ANY_OBJECT; - } - - List<PropagationTask> tasks = propagationManager.getUpdateTasks( - anyTypeKind, - updated.getResult(), - false, - null, - updated.getPropByRes(), - ((AnyPatch) actual).getVirAttrs(), - excludedResources); - PropagationReporter propagationReporter = taskExecutor.execute(tasks, nullPriorityAsync); - - exchange.getOut().setBody(new ImmutablePair<>(updated.getResult(), propagationReporter.getStatuses())); - } - } - } -} http://git-wip-us.apache.org/repos/asf/syncope/blob/6ae50200/ext/camel/provisioning-camel/src/main/java/org/apache/syncope/core/provisioning/camel/processor/UserDeleteProcessor.java ---------------------------------------------------------------------- diff --git a/ext/camel/provisioning-camel/src/main/java/org/apache/syncope/core/provisioning/camel/processor/UserDeleteProcessor.java b/ext/camel/provisioning-camel/src/main/java/org/apache/syncope/core/provisioning/camel/processor/UserDeleteProcessor.java deleted file mode 100644 index 787c60f..0000000 --- a/ext/camel/provisioning-camel/src/main/java/org/apache/syncope/core/provisioning/camel/processor/UserDeleteProcessor.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.syncope.core.provisioning.camel.processor; - -import java.util.List; -import java.util.Set; -import org.apache.camel.Exchange; -import org.apache.camel.Processor; -import org.apache.syncope.common.lib.types.AnyTypeKind; -import org.apache.syncope.core.provisioning.api.PropagationByResource; -import org.apache.syncope.common.lib.types.ResourceOperation; -import org.apache.syncope.core.persistence.api.dao.UserDAO; -import org.apache.syncope.core.persistence.api.entity.task.PropagationTask; -import org.apache.syncope.core.provisioning.api.propagation.PropagationManager; -import org.apache.syncope.core.provisioning.api.propagation.PropagationReporter; -import org.apache.syncope.core.provisioning.api.propagation.PropagationTaskExecutor; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -@Component -public class UserDeleteProcessor implements Processor { - - @Autowired - protected UserDAO userDAO; - - @Autowired - protected PropagationManager propagationManager; - - @Autowired - protected PropagationTaskExecutor taskExecutor; - - @SuppressWarnings("unchecked") - @Override - public void process(final Exchange exchange) throws Exception { - String key = exchange.getIn().getBody(String.class); - Set<String> excludedResources = exchange.getProperty("excludedResources", Set.class); - Boolean nullPriorityAsync = exchange.getProperty("nullPriorityAsync", Boolean.class); - - PropagationByResource propByRes = new PropagationByResource(); - propByRes.set(ResourceOperation.DELETE, userDAO.findAllResourceNames(key)); - - // Note here that we can only notify about "delete", not any other - // task defined in workflow process definition: this because this - // information could only be available after uwfAdapter.delete(), which - // will also effectively remove user from db, thus making virtually - // impossible by NotificationManager to fetch required user information - List<PropagationTask> tasks = propagationManager.getDeleteTasks( - AnyTypeKind.USER, - key, - propByRes, - excludedResources); - - PropagationReporter propagationReporter = taskExecutor.execute(tasks, nullPriorityAsync); - - exchange.setProperty("statuses", propagationReporter.getStatuses()); - } - -} http://git-wip-us.apache.org/repos/asf/syncope/blob/6ae50200/ext/camel/provisioning-camel/src/main/java/org/apache/syncope/core/provisioning/camel/processor/UserDeprovisionProcessor.java ---------------------------------------------------------------------- diff --git a/ext/camel/provisioning-camel/src/main/java/org/apache/syncope/core/provisioning/camel/processor/UserDeprovisionProcessor.java b/ext/camel/provisioning-camel/src/main/java/org/apache/syncope/core/provisioning/camel/processor/UserDeprovisionProcessor.java deleted file mode 100644 index e23693f..0000000 --- a/ext/camel/provisioning-camel/src/main/java/org/apache/syncope/core/provisioning/camel/processor/UserDeprovisionProcessor.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.syncope.core.provisioning.camel.processor; - -import java.util.List; -import org.apache.camel.Exchange; -import org.apache.camel.Processor; -import org.apache.commons.collections4.CollectionUtils; -import org.apache.syncope.common.lib.types.AnyTypeKind; -import org.apache.syncope.core.provisioning.api.PropagationByResource; -import org.apache.syncope.common.lib.types.ResourceOperation; -import org.apache.syncope.core.persistence.api.dao.UserDAO; -import org.apache.syncope.core.persistence.api.entity.task.PropagationTask; -import org.apache.syncope.core.provisioning.api.propagation.PropagationManager; -import org.apache.syncope.core.provisioning.api.propagation.PropagationReporter; -import org.apache.syncope.core.provisioning.api.propagation.PropagationTaskExecutor; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -@Component -public class UserDeprovisionProcessor implements Processor { - - @Autowired - protected PropagationManager propagationManager; - - @Autowired - protected PropagationTaskExecutor taskExecutor; - - @Autowired - protected UserDAO userDAO; - - @Override - public void process(final Exchange exchange) { - String key = exchange.getIn().getBody(String.class); - @SuppressWarnings("unchecked") - List<String> resources = exchange.getProperty("resources", List.class); - Boolean nullPriorityAsync = exchange.getProperty("nullPriorityAsync", Boolean.class); - - PropagationByResource propByRes = new PropagationByResource(); - propByRes.set(ResourceOperation.DELETE, resources); - - List<PropagationTask> tasks = propagationManager.getDeleteTasks( - AnyTypeKind.USER, - key, - propByRes, - CollectionUtils.removeAll(userDAO.findAllResourceNames(key), resources)); - PropagationReporter propagationReporter = taskExecutor.execute(tasks, nullPriorityAsync); - - exchange.getOut().setBody(propagationReporter.getStatuses()); - } - -} http://git-wip-us.apache.org/repos/asf/syncope/blob/6ae50200/ext/camel/provisioning-camel/src/main/java/org/apache/syncope/core/provisioning/camel/processor/UserProvisionProcessor.java ---------------------------------------------------------------------- diff --git a/ext/camel/provisioning-camel/src/main/java/org/apache/syncope/core/provisioning/camel/processor/UserProvisionProcessor.java b/ext/camel/provisioning-camel/src/main/java/org/apache/syncope/core/provisioning/camel/processor/UserProvisionProcessor.java deleted file mode 100644 index 1f4c4a1..0000000 --- a/ext/camel/provisioning-camel/src/main/java/org/apache/syncope/core/provisioning/camel/processor/UserProvisionProcessor.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.syncope.core.provisioning.camel.processor; - -import java.util.List; -import org.apache.camel.Exchange; -import org.apache.camel.Processor; -import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.collections4.Transformer; -import org.apache.commons.lang3.tuple.ImmutablePair; -import org.apache.commons.lang3.tuple.Pair; -import org.apache.syncope.common.lib.patch.PasswordPatch; -import org.apache.syncope.common.lib.patch.StringPatchItem; -import org.apache.syncope.common.lib.patch.UserPatch; -import org.apache.syncope.common.lib.types.PatchOperation; -import org.apache.syncope.core.provisioning.api.PropagationByResource; -import org.apache.syncope.common.lib.types.ResourceOperation; -import org.apache.syncope.core.persistence.api.dao.UserDAO; -import org.apache.syncope.core.persistence.api.entity.task.PropagationTask; -import org.apache.syncope.core.provisioning.api.WorkflowResult; -import org.apache.syncope.core.provisioning.api.propagation.PropagationManager; -import org.apache.syncope.core.provisioning.api.propagation.PropagationReporter; -import org.apache.syncope.core.provisioning.api.propagation.PropagationTaskExecutor; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -@Component -public class UserProvisionProcessor implements Processor { - - @Autowired - protected PropagationManager propagationManager; - - @Autowired - protected PropagationTaskExecutor taskExecutor; - - @Autowired - protected UserDAO userDAO; - - @Override - public void process(final Exchange exchange) { - String key = exchange.getIn().getBody(String.class); - Boolean changePwd = exchange.getProperty("changePwd", Boolean.class); - String password = exchange.getProperty("password", String.class); - @SuppressWarnings("unchecked") - List<String> resources = exchange.getProperty("resources", List.class); - Boolean nullPriorityAsync = exchange.getProperty("nullPriorityAsync", Boolean.class); - - UserPatch userPatch = new UserPatch(); - userPatch.setKey(key); - userPatch.getResources().addAll(CollectionUtils.collect(resources, new Transformer<String, StringPatchItem>() { - - @Override - public StringPatchItem transform(final String resource) { - return new StringPatchItem.Builder().operation(PatchOperation.ADD_REPLACE).value(resource).build(); - } - })); - - if (changePwd) { - userPatch.setPassword( - new PasswordPatch.Builder().onSyncope(true).value(password).resources(resources).build()); - } - - PropagationByResource propByRes = new PropagationByResource(); - for (String resource : resources) { - propByRes.add(ResourceOperation.UPDATE, resource); - } - - WorkflowResult<Pair<UserPatch, Boolean>> wfResult = new WorkflowResult<Pair<UserPatch, Boolean>>( - ImmutablePair.of(userPatch, (Boolean) null), propByRes, "update"); - - List<PropagationTask> tasks = propagationManager.getUserUpdateTasks(wfResult, changePwd, null); - PropagationReporter propagationReporter = taskExecutor.execute(tasks, nullPriorityAsync); - - exchange.getOut().setBody(propagationReporter.getStatuses()); - } - -} http://git-wip-us.apache.org/repos/asf/syncope/blob/6ae50200/ext/camel/provisioning-camel/src/main/java/org/apache/syncope/core/provisioning/camel/producer/AbstractProducer.java ---------------------------------------------------------------------- diff --git a/ext/camel/provisioning-camel/src/main/java/org/apache/syncope/core/provisioning/camel/producer/AbstractProducer.java b/ext/camel/provisioning-camel/src/main/java/org/apache/syncope/core/provisioning/camel/producer/AbstractProducer.java new file mode 100644 index 0000000..de1007d --- /dev/null +++ b/ext/camel/provisioning-camel/src/main/java/org/apache/syncope/core/provisioning/camel/producer/AbstractProducer.java @@ -0,0 +1,57 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.syncope.core.provisioning.camel.producer; + +import org.apache.camel.Endpoint; +import org.apache.camel.impl.DefaultProducer; +import org.apache.syncope.core.provisioning.api.propagation.PropagationManager; +import org.apache.syncope.core.provisioning.api.propagation.PropagationTaskExecutor; +import org.apache.syncope.core.provisioning.camel.AnyType; + +public abstract class AbstractProducer extends DefaultProducer { + + private PropagationManager propagationManager; + + private PropagationTaskExecutor taskExecutor; + + private AnyType anyType; + + public AbstractProducer(final Endpoint endpoint, final AnyType anyType) { + super(endpoint); + this.anyType = anyType; + } + + public void setPropagationManager(final PropagationManager propagationManager) { + this.propagationManager = propagationManager; + } + + public PropagationManager getPropagationManager() { + return propagationManager; + } + + public void setPropagationTaskExecutor(final PropagationTaskExecutor taskExecutor) { + this.taskExecutor = taskExecutor; + } + + public PropagationTaskExecutor getPropagationTaskExecutor() { + return taskExecutor; + } + + public AnyType getAnyType() { + return anyType; + } +} http://git-wip-us.apache.org/repos/asf/syncope/blob/6ae50200/ext/camel/provisioning-camel/src/main/java/org/apache/syncope/core/provisioning/camel/producer/CreateProducer.java ---------------------------------------------------------------------- diff --git a/ext/camel/provisioning-camel/src/main/java/org/apache/syncope/core/provisioning/camel/producer/CreateProducer.java b/ext/camel/provisioning-camel/src/main/java/org/apache/syncope/core/provisioning/camel/producer/CreateProducer.java new file mode 100644 index 0000000..26ddc3c --- /dev/null +++ b/ext/camel/provisioning-camel/src/main/java/org/apache/syncope/core/provisioning/camel/producer/CreateProducer.java @@ -0,0 +1,86 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.syncope.core.provisioning.camel.producer; + +import java.util.List; +import java.util.Set; + +import org.apache.camel.Endpoint; +import org.apache.camel.Exchange; +import org.apache.commons.lang3.tuple.ImmutablePair; +import org.apache.commons.lang3.tuple.Pair; +import org.apache.syncope.common.lib.to.AnyObjectTO; +import org.apache.syncope.common.lib.to.AnyTO; +import org.apache.syncope.common.lib.to.UserTO; +import org.apache.syncope.common.lib.types.AnyTypeKind; +import org.apache.syncope.core.persistence.api.entity.task.PropagationTask; +import org.apache.syncope.core.provisioning.api.WorkflowResult; +import org.apache.syncope.core.provisioning.api.propagation.PropagationReporter; +import org.apache.syncope.core.provisioning.camel.AnyType; + +public class CreateProducer extends AbstractProducer { + + public CreateProducer(final Endpoint endpoint, final AnyType anyType) { + super(endpoint, anyType); + } + + @SuppressWarnings("unchecked") + @Override + public void process(final Exchange exchange) throws Exception { + if ((exchange.getIn().getBody() instanceof WorkflowResult)) { + Object actual = exchange.getProperty("actual"); + Set<String> excludedResources = exchange.getProperty("excludedResources", Set.class); + Boolean nullPriorityAsync = exchange.getProperty("nullPriorityAsync", Boolean.class); + + if (actual instanceof UserTO) { + WorkflowResult<Pair<String, Boolean>> created = + (WorkflowResult<Pair<String, Boolean>>) exchange.getIn().getBody(); + + List<PropagationTask> tasks = getPropagationManager().getUserCreateTasks( + created.getResult().getKey(), + ((UserTO) actual).getPassword(), + created.getResult().getValue(), + created.getPropByRes(), + ((UserTO) actual).getVirAttrs(), + excludedResources); + PropagationReporter propagationReporter = + getPropagationTaskExecutor().execute(tasks, nullPriorityAsync); + + exchange.getOut().setBody( + new ImmutablePair<>(created.getResult().getKey(), propagationReporter.getStatuses())); + } else if (actual instanceof AnyTO) { + WorkflowResult<String> created = (WorkflowResult<String>) exchange.getIn().getBody(); + + AnyTypeKind anyTypeKind = AnyTypeKind.GROUP; + if (actual instanceof AnyObjectTO) { + anyTypeKind = AnyTypeKind.ANY_OBJECT; + } + List<PropagationTask> tasks = getPropagationManager().getCreateTasks( + anyTypeKind, + created.getResult(), + created.getPropByRes(), + ((AnyTO) actual).getVirAttrs(), + excludedResources); + PropagationReporter propagationReporter = + getPropagationTaskExecutor().execute(tasks, nullPriorityAsync); + + exchange.getOut().setBody(new ImmutablePair<>(created.getResult(), propagationReporter.getStatuses())); + } + } + } + +} http://git-wip-us.apache.org/repos/asf/syncope/blob/6ae50200/ext/camel/provisioning-camel/src/main/java/org/apache/syncope/core/provisioning/camel/producer/DeleteProducer.java ---------------------------------------------------------------------- diff --git a/ext/camel/provisioning-camel/src/main/java/org/apache/syncope/core/provisioning/camel/producer/DeleteProducer.java b/ext/camel/provisioning-camel/src/main/java/org/apache/syncope/core/provisioning/camel/producer/DeleteProducer.java new file mode 100644 index 0000000..5a3f8e0 --- /dev/null +++ b/ext/camel/provisioning-camel/src/main/java/org/apache/syncope/core/provisioning/camel/producer/DeleteProducer.java @@ -0,0 +1,118 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.syncope.core.provisioning.camel.producer; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.apache.camel.Endpoint; +import org.apache.camel.Exchange; +import org.apache.syncope.common.lib.types.AnyTypeKind; +import org.apache.syncope.common.lib.types.ResourceOperation; +import org.apache.syncope.core.persistence.api.dao.UserDAO; +import org.apache.syncope.core.persistence.api.entity.task.PropagationTask; +import org.apache.syncope.core.provisioning.api.PropagationByResource; +import org.apache.syncope.core.provisioning.api.data.GroupDataBinder; +import org.apache.syncope.core.provisioning.api.propagation.PropagationReporter; +import org.apache.syncope.core.provisioning.camel.AnyType; + +public class DeleteProducer extends AbstractProducer { + + private UserDAO userDAO; + private GroupDataBinder groupDataBinder; + + public DeleteProducer(final Endpoint endpoint, final AnyType anyType, final UserDAO userDao, + final GroupDataBinder groupDataBinder) { + super(endpoint, anyType); + this.userDAO = userDao; + this.groupDataBinder = groupDataBinder; + } + + @SuppressWarnings("unchecked") + @Override + public void process(final Exchange exchange) throws Exception { + String key = exchange.getIn().getBody(String.class); + Set<String> excludedResources = exchange.getProperty("excludedResources", Set.class); + Boolean nullPriorityAsync = exchange.getProperty("nullPriorityAsync", Boolean.class); + + if (getAnyType() == AnyType.user) { + PropagationByResource propByRes = new PropagationByResource(); + propByRes.set(ResourceOperation.DELETE, userDAO.findAllResourceNames(key)); + + // Note here that we can only notify about "delete", not any other + // task defined in workflow process definition: this because this + // information could only be available after uwfAdapter.delete(), which + // will also effectively remove user from db, thus making virtually + // impossible by NotificationManager to fetch required user information + List<PropagationTask> tasks = getPropagationManager().getDeleteTasks( + AnyTypeKind.USER, + key, + propByRes, + excludedResources); + + PropagationReporter propagationReporter = getPropagationTaskExecutor().execute(tasks, nullPriorityAsync); + + exchange.setProperty("statuses", propagationReporter.getStatuses()); + } else if (getAnyType() == AnyType.group) { + List<PropagationTask> tasks = new ArrayList<>(); + + // Generate propagation tasks for deleting users from group resources, if they are on those resources only + // because of the reason being deleted (see SYNCOPE-357) + for (Map.Entry<String, PropagationByResource> entry + : groupDataBinder.findUsersWithTransitiveResources(key).entrySet()) { + + tasks.addAll(getPropagationManager().getDeleteTasks( + AnyTypeKind.USER, + entry.getKey(), + entry.getValue(), + excludedResources)); + } + for (Map.Entry<String, PropagationByResource> entry + : groupDataBinder.findAnyObjectsWithTransitiveResources(key).entrySet()) { + + tasks.addAll(getPropagationManager().getDeleteTasks( + AnyTypeKind.ANY_OBJECT, + entry.getKey(), + entry.getValue(), + excludedResources)); + } + + // Generate propagation tasks for deleting this group from resources + tasks.addAll(getPropagationManager().getDeleteTasks( + AnyTypeKind.GROUP, + key, + null, + null)); + + PropagationReporter propagationReporter = getPropagationTaskExecutor().execute(tasks, nullPriorityAsync); + + exchange.setProperty("statuses", propagationReporter.getStatuses()); + } else if (getAnyType() == AnyType.any) { + List<PropagationTask> tasks = getPropagationManager().getDeleteTasks( + AnyTypeKind.ANY_OBJECT, + key, + null, + excludedResources); + PropagationReporter propagationReporter = getPropagationTaskExecutor().execute(tasks, nullPriorityAsync); + + exchange.setProperty("statuses", propagationReporter.getStatuses()); + } + } + +} http://git-wip-us.apache.org/repos/asf/syncope/blob/6ae50200/ext/camel/provisioning-camel/src/main/java/org/apache/syncope/core/provisioning/camel/producer/DeprovisionProducer.java ---------------------------------------------------------------------- diff --git a/ext/camel/provisioning-camel/src/main/java/org/apache/syncope/core/provisioning/camel/producer/DeprovisionProducer.java b/ext/camel/provisioning-camel/src/main/java/org/apache/syncope/core/provisioning/camel/producer/DeprovisionProducer.java new file mode 100644 index 0000000..fb54aa9 --- /dev/null +++ b/ext/camel/provisioning-camel/src/main/java/org/apache/syncope/core/provisioning/camel/producer/DeprovisionProducer.java @@ -0,0 +1,94 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.syncope.core.provisioning.camel.producer; + +import java.util.List; + +import org.apache.camel.Endpoint; +import org.apache.camel.Exchange; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.syncope.common.lib.types.AnyTypeKind; +import org.apache.syncope.common.lib.types.ResourceOperation; +import org.apache.syncope.core.persistence.api.dao.AnyObjectDAO; +import org.apache.syncope.core.persistence.api.dao.GroupDAO; +import org.apache.syncope.core.persistence.api.dao.UserDAO; +import org.apache.syncope.core.persistence.api.entity.task.PropagationTask; +import org.apache.syncope.core.provisioning.api.PropagationByResource; +import org.apache.syncope.core.provisioning.api.propagation.PropagationReporter; +import org.apache.syncope.core.provisioning.camel.AnyType; + +public class DeprovisionProducer extends AbstractProducer { + + private UserDAO userDAO; + private GroupDAO groupDAO; + private AnyObjectDAO anyObjectDAO; + + public DeprovisionProducer(final Endpoint endpoint, final AnyType anyType, final UserDAO userDAO, + final GroupDAO groupDAO, final AnyObjectDAO anyObjectDAO) { + super(endpoint, anyType); + this.userDAO = userDAO; + this.groupDAO = groupDAO; + this.anyObjectDAO = anyObjectDAO; + } + + @SuppressWarnings("unchecked") + @Override + public void process(final Exchange exchange) throws Exception { + String key = exchange.getIn().getBody(String.class); + List<String> resources = exchange.getProperty("resources", List.class); + Boolean nullPriorityAsync = exchange.getProperty("nullPriorityAsync", Boolean.class); + + if (getAnyType() == AnyType.user) { + PropagationByResource propByRes = new PropagationByResource(); + propByRes.set(ResourceOperation.DELETE, resources); + + List<PropagationTask> tasks = getPropagationManager().getDeleteTasks( + AnyTypeKind.USER, + key, + propByRes, + CollectionUtils.removeAll(userDAO.findAllResourceNames(key), resources)); + PropagationReporter propagationReporter = getPropagationTaskExecutor().execute(tasks, nullPriorityAsync); + + exchange.getOut().setBody(propagationReporter.getStatuses()); + } else if (getAnyType() == AnyType.group) { + PropagationByResource propByRes = new PropagationByResource(); + propByRes.addAll(ResourceOperation.DELETE, resources); + + List<PropagationTask> tasks = getPropagationManager().getDeleteTasks( + AnyTypeKind.GROUP, + key, + propByRes, + CollectionUtils.removeAll(groupDAO.authFind(key).getResourceKeys(), resources)); + PropagationReporter propagationReporter = getPropagationTaskExecutor().execute(tasks, nullPriorityAsync); + + exchange.getOut().setBody(propagationReporter.getStatuses()); + } else if (getAnyType() == AnyType.any) { + PropagationByResource propByRes = new PropagationByResource(); + propByRes.addAll(ResourceOperation.DELETE, resources); + + List<PropagationTask> tasks = getPropagationManager().getDeleteTasks( + AnyTypeKind.ANY_OBJECT, + key, + propByRes, + CollectionUtils.removeAll(anyObjectDAO.findAllResourceNames(key), resources)); + PropagationReporter propagationReporter = getPropagationTaskExecutor().execute(tasks, nullPriorityAsync); + + exchange.getOut().setBody(propagationReporter.getStatuses()); + } + } + +} http://git-wip-us.apache.org/repos/asf/syncope/blob/6ae50200/ext/camel/provisioning-camel/src/main/java/org/apache/syncope/core/provisioning/camel/producer/ProvisionProducer.java ---------------------------------------------------------------------- diff --git a/ext/camel/provisioning-camel/src/main/java/org/apache/syncope/core/provisioning/camel/producer/ProvisionProducer.java b/ext/camel/provisioning-camel/src/main/java/org/apache/syncope/core/provisioning/camel/producer/ProvisionProducer.java new file mode 100644 index 0000000..e50366c --- /dev/null +++ b/ext/camel/provisioning-camel/src/main/java/org/apache/syncope/core/provisioning/camel/producer/ProvisionProducer.java @@ -0,0 +1,107 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.syncope.core.provisioning.camel.producer; + +import java.util.List; + +import org.apache.camel.Endpoint; +import org.apache.camel.Exchange; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.collections4.Transformer; +import org.apache.commons.lang3.tuple.ImmutablePair; +import org.apache.commons.lang3.tuple.Pair; +import org.apache.syncope.common.lib.patch.PasswordPatch; +import org.apache.syncope.common.lib.patch.StringPatchItem; +import org.apache.syncope.common.lib.patch.UserPatch; +import org.apache.syncope.common.lib.types.AnyTypeKind; +import org.apache.syncope.common.lib.types.PatchOperation; +import org.apache.syncope.common.lib.types.ResourceOperation; +import org.apache.syncope.core.persistence.api.entity.task.PropagationTask; +import org.apache.syncope.core.provisioning.api.PropagationByResource; +import org.apache.syncope.core.provisioning.api.WorkflowResult; +import org.apache.syncope.core.provisioning.api.propagation.PropagationReporter; +import org.apache.syncope.core.provisioning.camel.AnyType; + +public class ProvisionProducer extends AbstractProducer { + + public ProvisionProducer(final Endpoint endpoint, final AnyType anyType) { + super(endpoint, anyType); + } + + @SuppressWarnings("unchecked") + @Override + public void process(final Exchange exchange) throws Exception { + String key = exchange.getIn().getBody(String.class); + List<String> resources = exchange.getProperty("resources", List.class); + Boolean nullPriorityAsync = exchange.getProperty("nullPriorityAsync", Boolean.class); + + if (getAnyType() == AnyType.user) { + Boolean changePwd = exchange.getProperty("changePwd", Boolean.class); + String password = exchange.getProperty("password", String.class); + + UserPatch userPatch = new UserPatch(); + userPatch.setKey(key); + userPatch.getResources().addAll(CollectionUtils.collect(resources, + new Transformer<String, StringPatchItem>() { + + @Override + public StringPatchItem transform(final String resource) { + return new StringPatchItem.Builder().operation(PatchOperation.ADD_REPLACE).value(resource).build(); + } + })); + + if (changePwd) { + userPatch.setPassword( + new PasswordPatch.Builder().onSyncope(true).value(password).resources(resources).build()); + } + + PropagationByResource propByRes = new PropagationByResource(); + for (String resource : resources) { + propByRes.add(ResourceOperation.UPDATE, resource); + } + + WorkflowResult<Pair<UserPatch, Boolean>> wfResult = new WorkflowResult<Pair<UserPatch, Boolean>>( + ImmutablePair.of(userPatch, (Boolean) null), propByRes, "update"); + + List<PropagationTask> tasks = getPropagationManager().getUserUpdateTasks(wfResult, changePwd, null); + PropagationReporter propagationReporter = getPropagationTaskExecutor().execute(tasks, nullPriorityAsync); + + exchange.getOut().setBody(propagationReporter.getStatuses()); + } else { + PropagationByResource propByRes = new PropagationByResource(); + propByRes.addAll(ResourceOperation.UPDATE, resources); + + AnyTypeKind anyType = AnyTypeKind.GROUP; + if (getAnyType() == AnyType.any) { + anyType = AnyTypeKind.ANY_OBJECT; + } + + List<PropagationTask> tasks = getPropagationManager().getUpdateTasks( + anyType, + key, + false, + null, + propByRes, + null, + null); + PropagationReporter propagationReporter = getPropagationTaskExecutor().execute(tasks, nullPriorityAsync); + + exchange.getOut().setBody(propagationReporter.getStatuses()); + } + } + +} http://git-wip-us.apache.org/repos/asf/syncope/blob/6ae50200/ext/camel/provisioning-camel/src/main/java/org/apache/syncope/core/provisioning/camel/producer/UpdateProducer.java ---------------------------------------------------------------------- diff --git a/ext/camel/provisioning-camel/src/main/java/org/apache/syncope/core/provisioning/camel/producer/UpdateProducer.java b/ext/camel/provisioning-camel/src/main/java/org/apache/syncope/core/provisioning/camel/producer/UpdateProducer.java new file mode 100644 index 0000000..6146c60 --- /dev/null +++ b/ext/camel/provisioning-camel/src/main/java/org/apache/syncope/core/provisioning/camel/producer/UpdateProducer.java @@ -0,0 +1,83 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.syncope.core.provisioning.camel.producer; + +import java.util.List; +import java.util.Set; + +import org.apache.camel.Endpoint; +import org.apache.camel.Exchange; +import org.apache.commons.lang3.tuple.ImmutablePair; +import org.apache.commons.lang3.tuple.Pair; +import org.apache.syncope.common.lib.patch.AnyObjectPatch; +import org.apache.syncope.common.lib.patch.AnyPatch; +import org.apache.syncope.common.lib.patch.UserPatch; +import org.apache.syncope.common.lib.types.AnyTypeKind; +import org.apache.syncope.core.persistence.api.entity.task.PropagationTask; +import org.apache.syncope.core.provisioning.api.WorkflowResult; +import org.apache.syncope.core.provisioning.api.propagation.PropagationReporter; +import org.apache.syncope.core.provisioning.camel.AnyType; + +public class UpdateProducer extends AbstractProducer { + + public UpdateProducer(final Endpoint endpoint, final AnyType anyType) { + super(endpoint, anyType); + } + + @SuppressWarnings("unchecked") + @Override + public void process(final Exchange exchange) throws Exception { + if ((exchange.getIn().getBody() instanceof WorkflowResult)) { + Object actual = exchange.getProperty("actual"); + Boolean nullPriorityAsync = exchange.getProperty("nullPriorityAsync", Boolean.class); + Set<String> excludedResources = exchange.getProperty("excludedResources", Set.class); + + if (actual instanceof UserPatch) { + WorkflowResult<Pair<UserPatch, Boolean>> updated = + (WorkflowResult<Pair<UserPatch, Boolean>>) exchange.getIn().getBody(); + + List<PropagationTask> tasks = getPropagationManager().getUserUpdateTasks(updated); + PropagationReporter propagationReporter = + getPropagationTaskExecutor().execute(tasks, nullPriorityAsync); + + exchange.getOut().setBody(new ImmutablePair<>( + updated.getResult().getKey().getKey(), propagationReporter.getStatuses())); + } else if (actual instanceof AnyPatch) { + WorkflowResult<String> updated = (WorkflowResult<String>) exchange.getIn().getBody(); + + AnyTypeKind anyTypeKind = AnyTypeKind.GROUP; + if (actual instanceof AnyObjectPatch) { + anyTypeKind = AnyTypeKind.ANY_OBJECT; + } + + List<PropagationTask> tasks = getPropagationManager().getUpdateTasks( + anyTypeKind, + updated.getResult(), + false, + null, + updated.getPropByRes(), + ((AnyPatch) actual).getVirAttrs(), + excludedResources); + PropagationReporter propagationReporter = + getPropagationTaskExecutor().execute(tasks, nullPriorityAsync); + + exchange.getOut().setBody(new ImmutablePair<>(updated.getResult(), propagationReporter.getStatuses())); + } + } + } + +}