syncope-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From skylar...@apache.org
Subject syncope git commit: [SYNCOPE-1310] Added PullActions to handle the id provided by SCIM in response, also during Pull Tasks
Date Tue, 29 May 2018 08:58:06 GMT
Repository: syncope
Updated Branches:
  refs/heads/2_0_X b903017fc -> d02ddfa8d


[SYNCOPE-1310] Added PullActions to handle the id provided by SCIM in response, also during
Pull Tasks


Project: http://git-wip-us.apache.org/repos/asf/syncope/repo
Commit: http://git-wip-us.apache.org/repos/asf/syncope/commit/d02ddfa8
Tree: http://git-wip-us.apache.org/repos/asf/syncope/tree/d02ddfa8
Diff: http://git-wip-us.apache.org/repos/asf/syncope/diff/d02ddfa8

Branch: refs/heads/2_0_X
Commit: d02ddfa8d94b22d926684184525734f8abe8e584
Parents: b903017
Author: skylark17 <matteo.alessandroni@tirasa.net>
Authored: Tue May 29 10:09:32 2018 +0200
Committer: skylark17 <matteo.alessandroni@tirasa.net>
Committed: Tue May 29 10:09:32 2018 +0200

----------------------------------------------------------------------
 .../java/pushpull/SCIMv11PullActions.java       | 160 +++++++++++++++++++
 1 file changed, 160 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/syncope/blob/d02ddfa8/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/pushpull/SCIMv11PullActions.java
----------------------------------------------------------------------
diff --git a/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/pushpull/SCIMv11PullActions.java
b/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/pushpull/SCIMv11PullActions.java
new file mode 100644
index 0000000..053c6df
--- /dev/null
+++ b/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/pushpull/SCIMv11PullActions.java
@@ -0,0 +1,160 @@
+/*
+ * 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.java.pushpull;
+
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.syncope.common.lib.patch.AnyPatch;
+import org.apache.syncope.common.lib.patch.StringReplacePatchItem;
+import org.apache.syncope.common.lib.patch.UserPatch;
+import org.apache.syncope.common.lib.to.EntityTO;
+import org.apache.syncope.common.lib.to.UserTO;
+import org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidPlainAttrValueException;
+import org.apache.syncope.core.persistence.api.dao.PlainSchemaDAO;
+import org.apache.syncope.core.persistence.api.dao.UserDAO;
+import org.apache.syncope.core.persistence.api.entity.AnyUtils;
+import org.apache.syncope.core.persistence.api.entity.AnyUtilsFactory;
+import org.apache.syncope.core.persistence.api.entity.EntityFactory;
+import org.apache.syncope.core.persistence.api.entity.PlainSchema;
+import org.apache.syncope.core.persistence.api.entity.user.UPlainAttr;
+import org.apache.syncope.core.persistence.api.entity.user.User;
+import org.apache.syncope.core.provisioning.api.pushpull.ProvisioningProfile;
+import org.apache.syncope.core.provisioning.api.pushpull.ProvisioningReport;
+import org.identityconnectors.framework.common.objects.SyncDelta;
+import org.quartz.JobExecutionException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.annotation.Transactional;
+
+/**
+ * This class is required during setup of an External Resource based on the ConnId
+ * <a href="https://github.com/Tirasa/ConnIdSCIMv11Bundle">SCIM connector</a>.
+ *
+ * It manages:
+ * <ol>
+ * <li>the id provided by SCIM in response to create, which will need to be used for
all subsequent operations</li>
+ * </ol>
+ */
+public class SCIMv11PullActions extends DefaultPullActions {
+
+    private static final Logger LOG = LoggerFactory.getLogger(SCIMv11PullActions.class);
+
+    @Autowired
+    private PlainSchemaDAO plainSchemaDAO;
+
+    @Autowired
+    private UserDAO userDAO;
+
+    @Autowired
+    private EntityFactory entityFactory;
+
+    @Autowired
+    private AnyUtilsFactory anyUtilsFactory;
+
+    private final Map<String, String> scimRefs = new HashMap<>();
+
+    protected String getSCIMIdSchema() {
+        return "SCIMUserId";
+    }
+
+    @Override
+    public void beforeProvision(
+            final ProvisioningProfile<?, ?> profile,
+            final SyncDelta delta,
+            final EntityTO entity) throws JobExecutionException {
+
+        if (entity instanceof UserTO) {
+            UserTO userTO = (UserTO) entity;
+            if (userTO.getUsername() == null) {
+                userTO.setUsername(delta.getObject().getName().getNameValue());
+            }
+        }
+    }
+
+    @Override
+    public <P extends AnyPatch> void beforeUpdate(
+            final ProvisioningProfile<?, ?> profile,
+            final SyncDelta delta,
+            final EntityTO entity,
+            final P anyPatch) throws JobExecutionException {
+
+        if (anyPatch instanceof UserPatch) {
+            UserPatch userPatch = (UserPatch) anyPatch;
+            if (userPatch.getUsername() == null) {
+                userPatch.setUsername(new StringReplacePatchItem.Builder().
+                        value(delta.getObject().getName().getNameValue()).build());
+            }
+        }
+    }
+
+    @Transactional
+    @Override
+    public void after(
+            final ProvisioningProfile<?, ?> profile,
+            final SyncDelta delta,
+            final EntityTO entity,
+            final ProvisioningReport result) throws JobExecutionException {
+
+        if (!(entity instanceof UserTO)) {
+            return;
+        }
+
+        scimRefs.put(entity.getKey(), delta.getUid().getUidValue());
+    }
+
+    @Transactional
+    @Override
+    public void afterAll(final ProvisioningProfile<?, ?> profile) throws JobExecutionException
{
+        for (Map.Entry<String, String> entry : scimRefs.entrySet()) {
+            User user = userDAO.find(entry.getKey());
+            if (user == null) {
+                LOG.error("Could not find user {}, skipping", entry.getKey());
+            } else {
+                AnyUtils anyUtils = anyUtilsFactory.getInstance(user);
+
+                // 1. stores the __UID__ received by SCIM
+                PlainSchema scimId = plainSchemaDAO.find(getSCIMIdSchema());
+                if (scimId == null) {
+                    LOG.error("Could not find schema {}, skipping", getSCIMIdSchema());
+                } else {
+                    UPlainAttr attr = user.getPlainAttr(getSCIMIdSchema());
+                    if (attr == null) {
+                        attr = entityFactory.newEntity(UPlainAttr.class);
+                        attr.setSchema(scimId);
+                        attr.setOwner(user);
+                        user.add(attr);
+
+                        try {
+                            attr.add(entry.getValue(), anyUtils);
+                            userDAO.save(user);
+                        } catch (InvalidPlainAttrValueException e) {
+                            LOG.error("Invalid value for attribute {}: {}",
+                                    scimId.getKey(), entry.getValue(), e);
+                        }
+                    } else {
+                        LOG.debug("User {} has already a {} assigned: {}", user, getSCIMIdSchema(),
+                                attr.getValuesAsStrings());
+                    }
+                }
+            }
+        }
+    }
+
+}


Mime
View raw message