You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by sk...@apache.org on 2018/05/29 08:56:58 UTC

[1/2] syncope git commit: [SYNCOPE-1283] Added PullActions to handle the id provided by Azure in response, also during Pull Tasks

Repository: syncope
Updated Branches:
  refs/heads/master e15156735 -> 6d38f3c50


[SYNCOPE-1283] Added PullActions to handle the id provided by Azure 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/252eb543
Tree: http://git-wip-us.apache.org/repos/asf/syncope/tree/252eb543
Diff: http://git-wip-us.apache.org/repos/asf/syncope/diff/252eb543

Branch: refs/heads/master
Commit: 252eb543eaed80c3952f3e97c1745109486ab4b4
Parents: e151567
Author: skylark17 <ma...@tirasa.net>
Authored: Tue May 29 09:21:27 2018 +0200
Committer: skylark17 <ma...@tirasa.net>
Committed: Tue May 29 10:12:28 2018 +0200

----------------------------------------------------------------------
 .../java/pushpull/AzurePullActions.java         | 221 +++++++++++++++++++
 1 file changed, 221 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/syncope/blob/252eb543/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/pushpull/AzurePullActions.java
----------------------------------------------------------------------
diff --git a/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/pushpull/AzurePullActions.java b/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/pushpull/AzurePullActions.java
new file mode 100644
index 0000000..3b3d786
--- /dev/null
+++ b/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/pushpull/AzurePullActions.java
@@ -0,0 +1,221 @@
+/*
+ * 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.GroupPatch;
+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.GroupTO;
+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.GroupDAO;
+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.group.GPlainAttr;
+import org.apache.syncope.core.persistence.api.entity.group.Group;
+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.apache.syncope.core.provisioning.api.pushpull.PullActions;
+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/ConnIdAzureBundle">Azure connector</a>.
+ *
+ * It manages:
+ * <ol>
+ * <li>the id provided by Azure in response to create, which will need to be used for all subsequent operations</li>
+ * <li>the e-mail address</li>
+ * </ol>
+ */
+public class AzurePullActions implements PullActions {
+
+    private static final Logger LOG = LoggerFactory.getLogger(AzurePullActions.class);
+
+    @Autowired
+    private PlainSchemaDAO plainSchemaDAO;
+
+    @Autowired
+    private UserDAO userDAO;
+
+    @Autowired
+    private GroupDAO groupDAO;
+
+    @Autowired
+    private EntityFactory entityFactory;
+
+    @Autowired
+    private AnyUtilsFactory anyUtilsFactory;
+
+    private final Map<EntityTO, String> azureRefs = new HashMap<>();
+
+    protected String getEmailAttrName() {
+        return "mailNickname";
+    }
+
+    protected String getAzureUserIdSchema() {
+        return "AzureUserId";
+    }
+
+    protected String getAzureGroupIdSchema() {
+        return "AzureGroupId";
+    }
+
+    @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());
+            }
+        } else if (entity instanceof GroupTO) {
+            GroupTO groupTO = (GroupTO) entity;
+            if (groupTO.getName() == null) {
+                groupTO.setName(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());
+            }
+        } else if (entity instanceof GroupPatch) {
+            GroupPatch groupPatch = (GroupPatch) entity;
+            if (groupPatch.getName() == null) {
+                groupPatch.setName(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) && !(entity instanceof GroupTO)) {
+            return;
+        }
+
+        azureRefs.put(entity, delta.getUid().getUidValue());
+    }
+
+    @Transactional
+    @Override
+    public void afterAll(final ProvisioningProfile<?, ?> profile) throws JobExecutionException {
+        for (Map.Entry<EntityTO, String> entry : azureRefs.entrySet()) {
+            if (entry.getKey() instanceof UserTO) {
+                User user = userDAO.find(entry.getKey().getKey());
+                if (user == null) {
+                    LOG.error("Could not find user {}, skipping", entry.getKey().getKey());
+                } else {
+                    AnyUtils anyUtils = anyUtilsFactory.getInstance(user);
+
+                    // 1. stores the __UID__ received by Azure
+                    PlainSchema azureId = plainSchemaDAO.find(getAzureUserIdSchema());
+                    if (azureId == null) {
+                        LOG.error("Could not find schema {}, skipping", getAzureUserIdSchema());
+                    } else {
+                        UPlainAttr attr = user.getPlainAttr(getAzureUserIdSchema()).orElse(null);
+                        if (attr == null) {
+                            attr = entityFactory.newEntity(UPlainAttr.class);
+                            attr.setSchema(azureId);
+                            attr.setOwner(user);
+                            user.add(attr);
+
+                            try {
+                                attr.add(entry.getValue(), anyUtils);
+                                userDAO.save(user);
+                            } catch (InvalidPlainAttrValueException e) {
+                                LOG.error("Invalid value for attribute {}: {}", azureId.getKey(), entry.getValue(), e);
+                            }
+                        } else {
+                            LOG.debug("User {} has already a {} assigned: {}", user, getAzureUserIdSchema(),
+                                    attr.getValuesAsStrings());
+                        }
+                    }
+                }
+            } else if (entry.getKey() instanceof GroupTO) {
+                Group group = groupDAO.find(entry.getKey().getKey());
+                if (group == null) {
+                    LOG.error("Could not find group {}, skipping", entry.getKey().getKey());
+                } else {
+                    AnyUtils anyUtils = anyUtilsFactory.getInstance(group);
+
+                    // 1. stores the __UID__ received by Azure
+                    PlainSchema azureId = plainSchemaDAO.find(getAzureGroupIdSchema());
+                    if (azureId == null) {
+                        LOG.error("Could not find schema {}, skipping", getAzureGroupIdSchema());
+                    } else {
+                        GPlainAttr attr = group.getPlainAttr(getAzureGroupIdSchema()).orElse(null);
+                        if (attr == null) {
+                            attr = entityFactory.newEntity(GPlainAttr.class);
+                            attr.setSchema(azureId);
+                            attr.setOwner(group);
+                            group.add(attr);
+
+                            try {
+                                attr.add(entry.getValue(), anyUtils);
+                                groupDAO.save(group);
+                            } catch (InvalidPlainAttrValueException e) {
+                                LOG.error("Invalid value for attribute {}: {}", azureId.getKey(), entry.getValue(), e);
+                            }
+                        } else {
+                            LOG.debug("Group {} has already a {} assigned: {}", group, getAzureGroupIdSchema(),
+                                    attr.getValuesAsStrings());
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+}


[2/2] syncope git commit: [SYNCOPE-1315] Fix symbol not found

Posted by sk...@apache.org.
[SYNCOPE-1315] Fix symbol not found


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

Branch: refs/heads/master
Commit: 6d38f3c50119f2fb7c2da6a7717e38250e5dd178
Parents: 252eb54
Author: skylark17 <ma...@tirasa.net>
Authored: Tue May 29 10:51:50 2018 +0200
Committer: skylark17 <ma...@tirasa.net>
Committed: Tue May 29 10:51:50 2018 +0200

----------------------------------------------------------------------
 .../java/org/apache/syncope/fit/console/AbstractConsoleITCase.java  | 1 +
 1 file changed, 1 insertion(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/syncope/blob/6d38f3c5/fit/core-reference/src/test/java/org/apache/syncope/fit/console/AbstractConsoleITCase.java
----------------------------------------------------------------------
diff --git a/fit/core-reference/src/test/java/org/apache/syncope/fit/console/AbstractConsoleITCase.java b/fit/core-reference/src/test/java/org/apache/syncope/fit/console/AbstractConsoleITCase.java
index 506b4a2..f9ab81b 100644
--- a/fit/core-reference/src/test/java/org/apache/syncope/fit/console/AbstractConsoleITCase.java
+++ b/fit/core-reference/src/test/java/org/apache/syncope/fit/console/AbstractConsoleITCase.java
@@ -31,6 +31,7 @@ import org.apache.wicket.markup.html.list.ListItem;
 import org.apache.wicket.util.tester.FormTester;
 import org.apache.wicket.util.tester.WicketTester;
 import org.apache.wicket.util.visit.IVisit;
+import org.apache.wicket.util.visit.IVisitor;
 import org.junit.jupiter.api.BeforeAll;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;