You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by an...@apache.org on 2017/06/29 08:54:03 UTC
syncope git commit: Fixes [SYNCOPE-1110],
[SYNCOPE-1123]. This closes #47
Repository: syncope
Updated Branches:
refs/heads/master 7187c35ab -> c50ee3176
Fixes [SYNCOPE-1110], [SYNCOPE-1123]. This closes #47
Project: http://git-wip-us.apache.org/repos/asf/syncope/repo
Commit: http://git-wip-us.apache.org/repos/asf/syncope/commit/c50ee317
Tree: http://git-wip-us.apache.org/repos/asf/syncope/tree/c50ee317
Diff: http://git-wip-us.apache.org/repos/asf/syncope/diff/c50ee317
Branch: refs/heads/master
Commit: c50ee317670571c7e56e1066536ba99313327166
Parents: 7187c35
Author: Matteo Alessandroni <ma...@tirasa.net>
Authored: Fri Jun 23 14:27:17 2017 +0200
Committer: Andrea Patricelli <an...@apache.org>
Committed: Thu Jun 29 10:53:27 2017 +0200
----------------------------------------------------------------------
.../enduser/model/CustomAttributesInfo.java | 2 +-
.../enduser/resources/BaseUserSelfResource.java | 38 --------------
.../enduser/resources/SchemaResource.java | 6 +--
.../enduser/resources/UserSelfReadResource.java | 22 ++++++++
.../resources/UserSelfUpdateResource.java | 54 +++++++++++++++-----
.../enduser/util/UserRequestValidator.java | 2 +-
6 files changed, 68 insertions(+), 56 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/syncope/blob/c50ee317/client/enduser/src/main/java/org/apache/syncope/client/enduser/model/CustomAttributesInfo.java
----------------------------------------------------------------------
diff --git a/client/enduser/src/main/java/org/apache/syncope/client/enduser/model/CustomAttributesInfo.java b/client/enduser/src/main/java/org/apache/syncope/client/enduser/model/CustomAttributesInfo.java
index a62a6bb..63eaa0b 100644
--- a/client/enduser/src/main/java/org/apache/syncope/client/enduser/model/CustomAttributesInfo.java
+++ b/client/enduser/src/main/java/org/apache/syncope/client/enduser/model/CustomAttributesInfo.java
@@ -33,7 +33,7 @@ public class CustomAttributesInfo implements Serializable {
public CustomAttributesInfo() {
}
- public Boolean getShow() {
+ public Boolean isShow() {
return show;
}
http://git-wip-us.apache.org/repos/asf/syncope/blob/c50ee317/client/enduser/src/main/java/org/apache/syncope/client/enduser/resources/BaseUserSelfResource.java
----------------------------------------------------------------------
diff --git a/client/enduser/src/main/java/org/apache/syncope/client/enduser/resources/BaseUserSelfResource.java b/client/enduser/src/main/java/org/apache/syncope/client/enduser/resources/BaseUserSelfResource.java
index 670d603..3a092c3 100644
--- a/client/enduser/src/main/java/org/apache/syncope/client/enduser/resources/BaseUserSelfResource.java
+++ b/client/enduser/src/main/java/org/apache/syncope/client/enduser/resources/BaseUserSelfResource.java
@@ -21,14 +21,10 @@ package org.apache.syncope.client.enduser.resources;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.text.ParseException;
-import java.util.HashSet;
-import org.apache.commons.collections4.Predicate;
import java.util.Set;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.Transformer;
import org.apache.commons.lang3.time.FastDateFormat;
-import org.apache.syncope.client.enduser.model.CustomAttributesInfo;
-import org.apache.syncope.common.lib.patch.AttrPatch;
import org.apache.syncope.common.lib.to.AttrTO;
import org.apache.syncope.common.lib.to.PlainSchemaTO;
@@ -91,38 +87,4 @@ public abstract class BaseUserSelfResource extends BaseResource {
});
}
- protected void customizeAttrTOs(final Set<AttrTO> attrs, final CustomAttributesInfo customAttributesInfo) {
- if (customAttributesInfo != null
- && customAttributesInfo.getShow()
- && !customAttributesInfo.getAttributes().isEmpty()) {
- Set<AttrTO> attrsToAdd = new HashSet<>();
- for (AttrTO attr : attrs) {
- if (customAttributesInfo.getAttributes().containsKey(attr.getSchema())) {
- attrsToAdd.add(attr);
- }
- }
- attrs.clear();
- attrs.addAll(attrsToAdd);
- } else if (customAttributesInfo != null && !customAttributesInfo.getShow()) {
- attrs.clear();
- }
- }
-
- protected void customizeAttrPatches(final Set<AttrPatch> attrs, final CustomAttributesInfo customAttributesInfo) {
- if (customAttributesInfo != null
- && customAttributesInfo.getShow()
- && !customAttributesInfo.getAttributes().isEmpty()) {
- CollectionUtils.filter(attrs, new Predicate<AttrPatch>() {
-
- @Override
- public boolean evaluate(final AttrPatch patchPlainAttr) {
- // if membership attribute clean schema name coming from custom form
- return customAttributesInfo.getAttributes().containsKey(patchPlainAttr.getAttrTO().getSchema());
- }
- });
- } else if (customAttributesInfo != null && !customAttributesInfo.getShow()) {
- attrs.clear();
- }
- }
-
}
http://git-wip-us.apache.org/repos/asf/syncope/blob/c50ee317/client/enduser/src/main/java/org/apache/syncope/client/enduser/resources/SchemaResource.java
----------------------------------------------------------------------
diff --git a/client/enduser/src/main/java/org/apache/syncope/client/enduser/resources/SchemaResource.java b/client/enduser/src/main/java/org/apache/syncope/client/enduser/resources/SchemaResource.java
index b088201..332011f 100644
--- a/client/enduser/src/main/java/org/apache/syncope/client/enduser/resources/SchemaResource.java
+++ b/client/enduser/src/main/java/org/apache/syncope/client/enduser/resources/SchemaResource.java
@@ -111,7 +111,7 @@ public class SchemaResource extends BaseResource {
: customForm == null || customForm.isEmpty() || customForm.get(SchemaType.PLAIN.name()) == null
? schemaService.list(
new SchemaQuery.Builder().type(SchemaType.PLAIN).anyTypeClasses(classes).build())
- : customForm.get(SchemaType.PLAIN.name()).getShow()
+ : customForm.get(SchemaType.PLAIN.name()).isShow()
? customizeSchemas(schemaService.list(new SchemaQuery.Builder().type(SchemaType.PLAIN).
anyTypeClasses(classes).build()), groupParam, customForm.get(SchemaType.PLAIN.name()).
getAttributes())
@@ -121,7 +121,7 @@ public class SchemaResource extends BaseResource {
: customForm == null || customForm.isEmpty() || customForm.get(SchemaType.DERIVED.name()) == null
? schemaService.list(
new SchemaQuery.Builder().type(SchemaType.DERIVED).anyTypeClasses(classes).build())
- : customForm.get(SchemaType.DERIVED.name()).getShow()
+ : customForm.get(SchemaType.DERIVED.name()).isShow()
? customizeSchemas(schemaService.list(new SchemaQuery.Builder().type(SchemaType.DERIVED).
anyTypeClasses(classes).build()), groupParam, customForm.get(SchemaType.DERIVED.name()).
getAttributes())
@@ -131,7 +131,7 @@ public class SchemaResource extends BaseResource {
: customForm == null || customForm.isEmpty() || customForm.get(SchemaType.VIRTUAL.name()) == null
? schemaService.list(
new SchemaQuery.Builder().type(SchemaType.VIRTUAL).anyTypeClasses(classes).build())
- : customForm.get(SchemaType.VIRTUAL.name()).getShow()
+ : customForm.get(SchemaType.VIRTUAL.name()).isShow()
? customizeSchemas(schemaService.list(new SchemaQuery.Builder().type(SchemaType.VIRTUAL).
anyTypeClasses(classes).build()), groupParam, customForm.get(SchemaType.VIRTUAL.name()).
getAttributes())
http://git-wip-us.apache.org/repos/asf/syncope/blob/c50ee317/client/enduser/src/main/java/org/apache/syncope/client/enduser/resources/UserSelfReadResource.java
----------------------------------------------------------------------
diff --git a/client/enduser/src/main/java/org/apache/syncope/client/enduser/resources/UserSelfReadResource.java b/client/enduser/src/main/java/org/apache/syncope/client/enduser/resources/UserSelfReadResource.java
index 924800c..7d95cdc 100644
--- a/client/enduser/src/main/java/org/apache/syncope/client/enduser/resources/UserSelfReadResource.java
+++ b/client/enduser/src/main/java/org/apache/syncope/client/enduser/resources/UserSelfReadResource.java
@@ -21,9 +21,12 @@ package org.apache.syncope.client.enduser.resources;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Map;
+import java.util.Set;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
+import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.collections4.Predicate;
import org.apache.commons.lang3.SerializationUtils;
import org.apache.syncope.client.enduser.SyncopeEnduserApplication;
import org.apache.syncope.client.enduser.SyncopeEnduserConstants;
@@ -95,6 +98,7 @@ public class UserSelfReadResource extends BaseUserSelfResource {
for (PlainSchemaTO plainSchema : SyncopeEnduserSession.get().getDatePlainSchemas()) {
dateToMillis(userTO.getPlainAttrs(), plainSchema);
}
+
final String selfTOJson = MAPPER.writeValueAsString(userTO);
response.setContentType(MediaType.APPLICATION_JSON);
response.setTextEncoding(StandardCharsets.UTF_8.name());
@@ -129,4 +133,22 @@ public class UserSelfReadResource extends BaseUserSelfResource {
}
}
+ private void customizeAttrTOs(final Set<AttrTO> attrs, final CustomAttributesInfo customAttributesInfo) {
+ if (customAttributesInfo != null
+ && customAttributesInfo.isShow()
+ && !customAttributesInfo.getAttributes().isEmpty()) {
+
+ CollectionUtils.filter(attrs, new Predicate<AttrTO>() {
+
+ @Override
+ public boolean evaluate(final AttrTO attr) {
+ return customAttributesInfo.getAttributes().containsKey(attr.getSchema());
+ }
+ });
+
+ } else if (customAttributesInfo != null && !customAttributesInfo.isShow()) {
+ attrs.clear();
+ }
+ }
+
}
http://git-wip-us.apache.org/repos/asf/syncope/blob/c50ee317/client/enduser/src/main/java/org/apache/syncope/client/enduser/resources/UserSelfUpdateResource.java
----------------------------------------------------------------------
diff --git a/client/enduser/src/main/java/org/apache/syncope/client/enduser/resources/UserSelfUpdateResource.java b/client/enduser/src/main/java/org/apache/syncope/client/enduser/resources/UserSelfUpdateResource.java
index c72c62c..56c6152 100644
--- a/client/enduser/src/main/java/org/apache/syncope/client/enduser/resources/UserSelfUpdateResource.java
+++ b/client/enduser/src/main/java/org/apache/syncope/client/enduser/resources/UserSelfUpdateResource.java
@@ -34,12 +34,12 @@ import org.apache.syncope.client.enduser.annotations.Resource;
import org.apache.syncope.client.enduser.model.CustomAttributesInfo;
import org.apache.syncope.client.enduser.util.UserRequestValidator;
import org.apache.syncope.common.lib.AnyOperations;
+import org.apache.syncope.common.lib.EntityTOUtils;
import org.apache.syncope.common.lib.patch.UserPatch;
import org.apache.syncope.common.lib.to.AttrTO;
import org.apache.syncope.common.lib.to.MembershipTO;
import org.apache.syncope.common.lib.to.PlainSchemaTO;
import org.apache.syncope.common.lib.to.UserTO;
-import org.apache.syncope.common.lib.types.SchemaType;
import org.apache.syncope.common.rest.api.service.UserSelfService;
import org.apache.wicket.request.resource.AbstractResource;
import org.apache.wicket.request.resource.IResource;
@@ -158,10 +158,14 @@ public class UserSelfUpdateResource extends BaseUserSelfResource {
}
userTO.getVirAttrs().removeAll(membAttrs);
- UserPatch userPatch = AnyOperations.diff(userTO, SyncopeEnduserSession.get().getSelfTO(), false);
-
- applyFormCustomization(userPatch, customForm);
-
+ // get old user object from session
+ UserTO selfTO = SyncopeEnduserSession.get().getSelfTO();
+ // align "userTO" and "selfTO" objects
+ if (customForm != null && !customForm.isEmpty()) {
+ completeUserObject(userTO, selfTO);
+ }
+ // create diff patch
+ UserPatch userPatch = AnyOperations.diff(userTO, selfTO, false);
// update user by patch
Response res = SyncopeEnduserSession.get().
getService(userTO.getETagValue(), UserSelfService.class).update(userPatch);
@@ -189,15 +193,39 @@ public class UserSelfUpdateResource extends BaseUserSelfResource {
return response;
}
- private void applyFormCustomization(final UserPatch userPatch, final Map<String, CustomAttributesInfo> customForm) {
- final CustomAttributesInfo customPlainAttrsInfo = customForm.get(SchemaType.PLAIN.name());
- final CustomAttributesInfo customVirtualAttrsInfo = customForm.get(SchemaType.VIRTUAL.name());
- // clean patch to avoid unwanted deletions of hidden schemas (custom form)
- if (customPlainAttrsInfo != null) {
- customizeAttrPatches(userPatch.getPlainAttrs(), customPlainAttrsInfo);
+ private void completeUserObject(final UserTO userTO, final UserTO selfTO) {
+ // memberships plain and virtual attrs
+ for (final MembershipTO updatedTOMemb : userTO.getMemberships()) {
+ MembershipTO oldTOMatchedMemb =
+ IterableUtils.find(selfTO.getMemberships(), new Predicate<MembershipTO>() {
+
+ @Override
+ public boolean evaluate(final MembershipTO oldTOMemb) {
+ return updatedTOMemb.getGroupKey().equals(oldTOMemb.getGroupKey());
+ }
+ });
+ if (oldTOMatchedMemb != null) {
+ if (!updatedTOMemb.getPlainAttrs().isEmpty()) {
+ completeAttrs(updatedTOMemb.getPlainAttrs(), oldTOMatchedMemb.getPlainAttrs());
+ }
+ if (!updatedTOMemb.getVirAttrs().isEmpty()) {
+ completeAttrs(updatedTOMemb.getVirAttrs(), oldTOMatchedMemb.getVirAttrs());
+ }
+ }
}
- if (customVirtualAttrsInfo != null) {
- customizeAttrTOs(userPatch.getVirAttrs(), customPlainAttrsInfo);
+ // plain attrs
+ completeAttrs(userTO.getPlainAttrs(), selfTO.getPlainAttrs());
+ // virtual attrs
+ completeAttrs(userTO.getVirAttrs(), selfTO.getVirAttrs());
+ }
+
+ private void completeAttrs(final Set<AttrTO> userTOAttrs, final Set<AttrTO> selfTOAttrs) {
+ Map<String, AttrTO> userTOAttrsMap =
+ EntityTOUtils.buildAttrMap(userTOAttrs);
+ for (AttrTO selfTOAttr : selfTOAttrs) {
+ if (!userTOAttrsMap.containsKey(selfTOAttr.getSchema())) {
+ userTOAttrs.add(selfTOAttr);
+ }
}
}
http://git-wip-us.apache.org/repos/asf/syncope/blob/c50ee317/client/enduser/src/main/java/org/apache/syncope/client/enduser/util/UserRequestValidator.java
----------------------------------------------------------------------
diff --git a/client/enduser/src/main/java/org/apache/syncope/client/enduser/util/UserRequestValidator.java b/client/enduser/src/main/java/org/apache/syncope/client/enduser/util/UserRequestValidator.java
index b5253af..1d02e4e 100644
--- a/client/enduser/src/main/java/org/apache/syncope/client/enduser/util/UserRequestValidator.java
+++ b/client/enduser/src/main/java/org/apache/syncope/client/enduser/util/UserRequestValidator.java
@@ -56,7 +56,7 @@ public final class UserRequestValidator {
final CustomAttributesInfo customAttrInfo, final boolean checkDefaultValues) {
return customAttrInfo == null
- || (customAttrInfo.getAttributes().isEmpty() && customAttrInfo.getShow())
+ || (customAttrInfo.getAttributes().isEmpty() && customAttrInfo.isShow())
|| IterableUtils.matchesAll(attrMap.entrySet(), new Predicate<Map.Entry<String, AttrTO>>() {
@Override