You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by il...@apache.org on 2017/12/15 07:42:32 UTC
[2/2] syncope git commit: [SYNCOPE-1249] Better management of User,
Group and AnyObject field mapping - including mustChangePassword
[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/4193ab37
Tree: http://git-wip-us.apache.org/repos/asf/syncope/tree/4193ab37
Diff: http://git-wip-us.apache.org/repos/asf/syncope/diff/4193ab37
Branch: refs/heads/2_0_X
Commit: 4193ab370b05d266d36ea37656d923cd7b040951
Parents: 96a7848
Author: Francesco Chicchiriccò <il...@apache.org>
Authored: Fri Dec 15 08:41:53 2017 +0100
Committer: Francesco Chicchiriccò <il...@apache.org>
Committed: Fri Dec 15 08:42:21 2017 +0100
----------------------------------------------------------------------
.../provisioning/java/MappingManagerImpl.java | 61 ++++++++++++--------
1 file changed, 36 insertions(+), 25 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/syncope/blob/4193ab37/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 d640187..6d47aeb 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,6 +20,7 @@ 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.Set;
@@ -27,6 +28,7 @@ import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.ListUtils;
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;
@@ -66,7 +68,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);
}
}