Repository: syncope
Updated Branches:
  refs/heads/2_0_X 38327a0a2 -> 79354db35
  refs/heads/master 95ee2ffe8 -> a8ae113d9


[SYNCOPE-1293] Explicitly allow token Vs  comparison


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

Branch: refs/heads/2_0_X
Commit: 79354db353792907c175dffe94205b17569313cc
Parents: 38327a0
Author: Francesco Chicchiriccò <ilgro...@apache.org>
Authored: Thu Apr 5 10:17:07 2018 +0200
Committer: Francesco Chicchiriccò <ilgro...@apache.org>
Committed: Thu Apr 5 10:17:07 2018 +0200

----------------------------------------------------------------------
 .../panels/search/AbstractSearchPanel.java        |  2 +-
 .../common/lib/search/SearchableFields.java       | 11 +++--------
 .../persistence/api/search/SearchCondVisitor.java | 18 +++++++++++++++++-
 .../apache/syncope/fit/core/UserSelfITCase.java   |  9 +++++++++
 4 files changed, 30 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/syncope/blob/79354db3/client/console/src/main/java/org/apache/syncope/client/console/panels/search/AbstractSearchPanel.java
----------------------------------------------------------------------
diff --git 
a/client/console/src/main/java/org/apache/syncope/client/console/panels/search/AbstractSearchPanel.java
 
b/client/console/src/main/java/org/apache/syncope/client/console/panels/search/AbstractSearchPanel.java
index 5c02669..be1d2b1 100644
--- 
a/client/console/src/main/java/org/apache/syncope/client/console/panels/search/AbstractSearchPanel.java
+++ 
b/client/console/src/main/java/org/apache/syncope/client/console/panels/search/AbstractSearchPanel.java
@@ -175,7 +175,7 @@ public abstract class AbstractSearchPanel extends Panel {
 
             @Override
             protected List<String> load() {
-                return SearchableFields.get(typeKind);
+                return SearchableFields.get(typeKind.getTOClass());
             }
         };
 

http://git-wip-us.apache.org/repos/asf/syncope/blob/79354db3/common/lib/src/main/java/org/apache/syncope/common/lib/search/SearchableFields.java
----------------------------------------------------------------------
diff --git 
a/common/lib/src/main/java/org/apache/syncope/common/lib/search/SearchableFields.java
 
b/common/lib/src/main/java/org/apache/syncope/common/lib/search/SearchableFields.java
index 77a7d13..c5102a4 100644
--- 
a/common/lib/src/main/java/org/apache/syncope/common/lib/search/SearchableFields.java
+++ 
b/common/lib/src/main/java/org/apache/syncope/common/lib/search/SearchableFields.java
@@ -31,7 +31,6 @@ import org.apache.syncope.common.lib.to.AnyObjectTO;
 import org.apache.syncope.common.lib.to.AnyTO;
 import org.apache.syncope.common.lib.to.GroupTO;
 import org.apache.syncope.common.lib.to.UserTO;
-import org.apache.syncope.common.lib.types.AnyTypeKind;
 
 public final class SearchableFields {
 
@@ -42,19 +41,15 @@ public final class SearchableFields {
     private static final Set<String> ANY_FIELDS = new HashSet<>();
 
     static {
-        ANY_FIELDS.addAll(SearchableFields.get(UserTO.class));
-        ANY_FIELDS.addAll(SearchableFields.get(GroupTO.class));
-        ANY_FIELDS.addAll(SearchableFields.get(AnyObjectTO.class));
+        ANY_FIELDS.addAll(get(UserTO.class));
+        ANY_FIELDS.addAll(get(GroupTO.class));
+        ANY_FIELDS.addAll(get(AnyObjectTO.class));
     }
 
     public static boolean contains(final String schema) {
         return ANY_FIELDS.contains(schema);
     }
 
-    public static List<String> get(final AnyTypeKind anyTypeKind) {
-        return get(anyTypeKind.getTOClass());
-    }
-
     public static List<String> get(final Class<? extends AnyTO> anyRef) {
         final List<String> fieldNames = new ArrayList<>();
 

http://git-wip-us.apache.org/repos/asf/syncope/blob/79354db3/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/search/SearchCondVisitor.java
----------------------------------------------------------------------
diff --git 
a/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/search/SearchCondVisitor.java
 
b/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/search/SearchCondVisitor.java
index e9e5951..29ee195 100644
--- 
a/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/search/SearchCondVisitor.java
+++ 
b/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/search/SearchCondVisitor.java
@@ -185,7 +185,9 @@ public class SearchCondVisitor extends 
AbstractSearchConditionVisitor<SearchBean
                             && leaf.getAttributeCond().getType() == 
AttributeCond.Type.ISNULL) {
 
                         
leaf.getAttributeCond().setType(AttributeCond.Type.ISNOTNULL);
-                    } else if (leaf.getAnyCond() != null && 
leaf.getAnyCond().getType() == AnyCond.Type.ISNULL) {
+                    } else if (leaf.getAnyCond() != null
+                            && leaf.getAnyCond().getType() == 
AttributeCond.Type.ISNULL) {
+
                         
leaf.getAnyCond().setType(AttributeCond.Type.ISNOTNULL);
                     } else {
                         leaf = SearchCond.getNotLeafCond(leaf);
@@ -217,6 +219,20 @@ public class SearchCondVisitor extends 
AbstractSearchConditionVisitor<SearchBean
                 throw new IllegalArgumentException(String.format("Condition 
type %s is not supported", ct.name()));
         }
 
+        // SYNCOPE-1293: explicitly re-process to allow 'token==$null' or 
'token!=$null'
+        if (leaf.getAttributeCond() != null
+                && "token".equals(leaf.getAttributeCond().getSchema())
+                && (leaf.getAttributeCond().getType() == 
AttributeCond.Type.ISNULL
+                || leaf.getAttributeCond().getType() == 
AttributeCond.Type.ISNOTNULL)
+                && leaf.getAttributeCond().getExpression() == null) {
+
+            AnyCond tokenCond = new AnyCond();
+            tokenCond.setSchema(leaf.getAttributeCond().getSchema());
+            tokenCond.setType(leaf.getAttributeCond().getType());
+            tokenCond.setExpression(null);
+            leaf = SearchCond.getLeafCond(tokenCond);
+        }
+
         return leaf;
     }
 

http://git-wip-us.apache.org/repos/asf/syncope/blob/79354db3/fit/core-reference/src/test/java/org/apache/syncope/fit/core/UserSelfITCase.java
----------------------------------------------------------------------
diff --git 
a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/UserSelfITCase.java
 
b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/UserSelfITCase.java
index f4b6dd4..36e21cb 100644
--- 
a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/UserSelfITCase.java
+++ 
b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/UserSelfITCase.java
@@ -44,12 +44,14 @@ import org.apache.syncope.common.lib.patch.StringPatchItem;
 import org.apache.syncope.common.lib.patch.StringReplacePatchItem;
 import org.apache.syncope.common.lib.patch.UserPatch;
 import org.apache.syncope.common.lib.to.MembershipTO;
+import org.apache.syncope.common.lib.to.PagedResult;
 import org.apache.syncope.common.lib.to.ProvisioningResult;
 import org.apache.syncope.common.lib.to.UserTO;
 import org.apache.syncope.common.lib.to.WorkflowFormTO;
 import org.apache.syncope.common.lib.types.AnyTypeKind;
 import org.apache.syncope.common.lib.types.ClientExceptionType;
 import org.apache.syncope.common.lib.types.PatchOperation;
+import org.apache.syncope.common.rest.api.beans.AnyQuery;
 import org.apache.syncope.common.rest.api.service.ResourceService;
 import org.apache.syncope.common.rest.api.service.UserSelfService;
 import org.apache.syncope.common.rest.api.service.UserService;
@@ -279,6 +281,9 @@ public class UserSelfITCase extends AbstractITCase {
         UserTO read = authClient.self().getValue();
         assertNotNull(read);
 
+        // SYNCOPE-1293:get users with token not null before requesting 
password reset
+        PagedResult<UserTO> before = userService.search(new 
AnyQuery.Builder().fiql("token!=$null").build());
+
         // 3. request password reset (as anonymous) providing the expected 
security answer
         SyncopeClient anonClient = clientFactory.create();
         try {
@@ -289,6 +294,10 @@ public class UserSelfITCase extends AbstractITCase {
         }
         
anonClient.getService(UserSelfService.class).requestPasswordReset(user.getUsername(),
 "Rossi");
 
+        // SYNCOPE-1293:get users with token not null before requesting 
password reset
+        PagedResult<UserTO> after = userService.search(new 
AnyQuery.Builder().fiql("token!=$null").build());
+        assertEquals(before.getTotalCount() + 1, after.getTotalCount());
+
         // 4. get token (normally sent via e-mail, now reading as admin)
         String token = userService.read(read.getKey()).getToken();
         assertNotNull(token);

Reply via email to