Repository: syncope
Updated Branches:
  refs/heads/1_2_X 1ed1bee11 -> 80d7e53cc


[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/80d7e53c
Tree: http://git-wip-us.apache.org/repos/asf/syncope/tree/80d7e53c
Diff: http://git-wip-us.apache.org/repos/asf/syncope/diff/80d7e53c

Branch: refs/heads/1_2_X
Commit: 80d7e53cc9905765fe641a92bb4e8d83cd852c68
Parents: 1ed1bee
Author: Francesco Chicchiriccò <ilgro...@apache.org>
Authored: Thu Apr 5 11:17:59 2018 +0200
Committer: Francesco Chicchiriccò <ilgro...@apache.org>
Committed: Thu Apr 5 11:17:59 2018 +0200

----------------------------------------------------------------------
 .../syncope/core/rest/data/SearchCondVisitor.java     | 14 ++++++++++++++
 .../apache/syncope/core/rest/UserSelfTestITCase.java  |  8 ++++++++
 2 files changed, 22 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/syncope/blob/80d7e53c/core/src/main/java/org/apache/syncope/core/rest/data/SearchCondVisitor.java
----------------------------------------------------------------------
diff --git 
a/core/src/main/java/org/apache/syncope/core/rest/data/SearchCondVisitor.java 
b/core/src/main/java/org/apache/syncope/core/rest/data/SearchCondVisitor.java
index 9d67c3e..7663d51 100644
--- 
a/core/src/main/java/org/apache/syncope/core/rest/data/SearchCondVisitor.java
+++ 
b/core/src/main/java/org/apache/syncope/core/rest/data/SearchCondVisitor.java
@@ -177,6 +177,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) {
+
+            SubjectCond tokenCond = new SubjectCond();
+            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/80d7e53c/core/src/test/java/org/apache/syncope/core/rest/UserSelfTestITCase.java
----------------------------------------------------------------------
diff --git 
a/core/src/test/java/org/apache/syncope/core/rest/UserSelfTestITCase.java 
b/core/src/test/java/org/apache/syncope/core/rest/UserSelfTestITCase.java
index 9b6ff13..c0c3d75 100644
--- a/core/src/test/java/org/apache/syncope/core/rest/UserSelfTestITCase.java
+++ b/core/src/test/java/org/apache/syncope/core/rest/UserSelfTestITCase.java
@@ -39,6 +39,7 @@ import org.apache.syncope.common.mod.AttributeMod;
 import org.apache.syncope.common.mod.MembershipMod;
 import org.apache.syncope.common.mod.StatusMod;
 import org.apache.syncope.common.mod.UserMod;
+import org.apache.syncope.common.reqres.PagedResult;
 import org.apache.syncope.common.services.UserSelfService;
 import org.apache.syncope.common.services.UserService;
 import org.apache.syncope.common.to.MembershipTO;
@@ -272,6 +273,9 @@ public class UserSelfTestITCase extends AbstractTest {
         UserTO read = authClient.getService(UserSelfService.class).read();
         assertNotNull(read);
 
+        // SYNCOPE-1293:get users with token not null before requesting 
password reset
+        PagedResult<UserTO> before = userService.search("token!=$null");
+
         // 3. request password reset (as anonymous) providing the expected 
security answer
         SyncopeClient anonClient = clientFactory.createAnonymous();
         try {
@@ -282,6 +286,10 @@ public class UserSelfTestITCase extends AbstractTest {
         }
         
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("token!=$null");
+        assertEquals(before.getTotalCount() + 1, after.getTotalCount());
+
         // 4. get token (normally sent via e-mail, now reading as admin)
         String token = userService.read(read.getId()).getToken();
         assertNotNull(token);

Reply via email to