syncope-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ilgro...@apache.org
Subject [1/2] syncope git commit: [SYNCOPE-1249] Better management of User, Group and AnyObject field mapping - including mustChangePassword
Date Fri, 15 Dec 2017 07:42:31 GMT
Repository: syncope
Updated Branches:
  refs/heads/2_0_X 96a784848 -> 4193ab370
  refs/heads/master 76c114016 -> 471c0fa67


[SYNCOPE-1249] Better management of User, Group and AnyObject field mapping - including mustChangePassword


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

Branch: refs/heads/master
Commit: 471c0fa67b68c37e8fe974b408079bc4e3c7c250
Parents: 76c1140
Author: Francesco Chicchiriccò <ilgrosso@apache.org>
Authored: Fri Dec 15 08:41:53 2017 +0100
Committer: Francesco Chicchiriccò <ilgrosso@apache.org>
Committed: Fri Dec 15 08:42:12 2017 +0100

----------------------------------------------------------------------
 .../provisioning/java/MappingManagerImpl.java   | 61 ++++++++++++--------
 1 file changed, 36 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/syncope/blob/471c0fa6/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/MappingManagerImpl.java
----------------------------------------------------------------------
diff --git a/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/MappingManagerImpl.java
b/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/MappingManagerImpl.java
index c11dd4c..f09cd06 100644
--- a/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/MappingManagerImpl.java
+++ b/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/MappingManagerImpl.java
@@ -20,12 +20,14 @@ package org.apache.syncope.core.provisioning.java;
 
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.Date;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Optional;
 import java.util.Set;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.reflect.FieldUtils;
+import org.apache.commons.lang3.time.DateFormatUtils;
 import org.apache.commons.lang3.tuple.Pair;
 import org.apache.syncope.common.lib.to.AnyObjectTO;
 import org.apache.syncope.common.lib.to.AnyTO;
@@ -65,7 +67,6 @@ import org.apache.syncope.core.persistence.api.entity.resource.MappingItem;
 import org.apache.syncope.core.persistence.api.entity.resource.OrgUnit;
 import org.apache.syncope.core.persistence.api.entity.resource.OrgUnitItem;
 import org.apache.syncope.core.persistence.api.entity.resource.Provision;
-import org.apache.syncope.core.persistence.api.entity.user.UPlainAttrValue;
 import org.apache.syncope.core.persistence.api.entity.user.User;
 import org.apache.syncope.core.provisioning.api.DerAttrHandler;
 import org.apache.syncope.core.provisioning.api.IntAttrName;
@@ -442,28 +443,13 @@ public class MappingManagerImpl implements MappingManager {
                     values.add(attrValue);
                     break;
 
-                case "password":
-                    // ignore
-                    break;
-
-                case "username":
-                    if (reference instanceof User) {
-                        attrValue = entityFactory.newEntity(UPlainAttrValue.class);
-                        attrValue.setStringValue(((User) reference).getUsername());
-                        values.add(attrValue);
-                    }
+                case "realm":
+                    attrValue.setStringValue(reference.getRealm().getFullPath());
+                    values.add(attrValue);
                     break;
 
-                case "name":
-                    if (reference instanceof Group) {
-                        attrValue = entityFactory.newEntity(UPlainAttrValue.class);
-                        attrValue.setStringValue(((Group) reference).getName());
-                        values.add(attrValue);
-                    } else if (reference instanceof AnyObject) {
-                        attrValue = entityFactory.newEntity(UPlainAttrValue.class);
-                        attrValue.setStringValue(((AnyObject) reference).getName());
-                        values.add(attrValue);
-                    }
+                case "password":
+                    // ignore
                     break;
 
                 case "userOwner":
@@ -486,19 +472,44 @@ public class MappingManagerImpl implements MappingManager {
                         }
 
                         if (StringUtils.isNotBlank(groupOwnerValue)) {
-                            attrValue = entityFactory.newEntity(UPlainAttrValue.class);
                             attrValue.setStringValue(groupOwnerValue);
                             values.add(attrValue);
                         }
                     }
                     break;
 
+                case "suspended":
+                    if (reference instanceof User) {
+                        attrValue.setBooleanValue(((User) reference).isSuspended());
+                        values.add(attrValue);
+                    }
+                    break;
+
+                case "mustChangePassword":
+                    if (reference instanceof User) {
+                        attrValue.setBooleanValue(((User) reference).isMustChangePassword());
+                        values.add(attrValue);
+                    }
+                    break;
+
                 default:
                     try {
-                        attrValue.setStringValue(FieldUtils.readField(
-                                reference, intAttrName.getField(), true).toString());
+                        Object fieldValue = FieldUtils.readField(reference, intAttrName.getField(),
true);
+                        if (fieldValue instanceof Date) {
+                            // needed because ConnId does not natively supports the Date
type
+                            attrValue.setStringValue(DateFormatUtils.ISO_8601_EXTENDED_DATETIME_TIME_ZONE_FORMAT.
+                                    format((Date) fieldValue));
+                        } else if (Boolean.TYPE.isInstance(fieldValue)) {
+                            attrValue.setBooleanValue((Boolean) fieldValue);
+                        } else if (Double.TYPE.isInstance(fieldValue) || Float.TYPE.isInstance(fieldValue))
{
+                            attrValue.setDoubleValue((Double) fieldValue);
+                        } else if (Long.TYPE.isInstance(fieldValue) || Integer.TYPE.isInstance(fieldValue))
{
+                            attrValue.setLongValue((Long) fieldValue);
+                        } else {
+                            attrValue.setStringValue(fieldValue.toString());
+                        }
                         values.add(attrValue);
-                    } catch (IllegalAccessException e) {
+                    } catch (Exception e) {
                         LOG.error("Could not read value of '{}' from {}", intAttrName.getField(),
reference, e);
                     }
             }


Mime
View raw message