Skip to content

Commit 5f26f1f

Browse files
committed
[SYNCOPE-1963] Check if null before pattern match
1 parent 8fb31f6 commit 5f26f1f

3 files changed

Lines changed: 21 additions & 13 deletions

File tree

core/persistence-common/src/main/java/org/apache/syncope/core/persistence/common/dao/AbstractSearchDAO.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.util.Comparator;
2828
import java.util.HashSet;
2929
import java.util.List;
30+
import java.util.Optional;
3031
import java.util.Set;
3132
import java.util.function.Supplier;
3233
import java.util.regex.Pattern;
@@ -279,18 +280,20 @@ protected CheckResult<AnyCond> check(final AnyCond cond, final Field field, fina
279280
computed.setSchema(computed.getSchema() + "_id");
280281
schema.setType(AttrSchemaType.String);
281282

282-
if (!SyncopeConstants.UUID_PATTERN.matcher(computed.getExpression()).matches()) {
283-
switch (StringUtils.substringBefore(computed.getSchema(), "_id")) {
284-
case "uManager" ->
285-
userDAO.findKey(computed.getExpression()).ifPresent(computed::setExpression);
283+
Optional.ofNullable(computed.getExpression()).
284+
filter(expression -> !SyncopeConstants.UUID_PATTERN.matcher(expression).matches()).
285+
ifPresent(expression -> {
286+
switch (StringUtils.substringBefore(computed.getSchema(), "_id")) {
287+
case "uManager" ->
288+
userDAO.findKey(expression).ifPresent(computed::setExpression);
286289

287-
case "gManager" ->
288-
groupDAO.findKey(computed.getExpression()).ifPresent(computed::setExpression);
290+
case "gManager" ->
291+
groupDAO.findKey(expression).ifPresent(computed::setExpression);
289292

290-
default -> {
291-
}
292-
}
293-
}
293+
default -> {
294+
}
295+
}
296+
});
294297
}
295298

296299
PlainAttrValue attrValue = new PlainAttrValue();

core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/notification/DefaultNotificationManager.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -358,15 +358,13 @@ public List<NotificationTask> createTasks(
358358
},
359359
() -> {
360360
switch (before) {
361-
case null -> {
362-
}
363361
case UserTO userTO ->
364362
jexlVars.put("user", userTO);
365363
case GroupTO groupTO ->
366364
jexlVars.put("group", groupTO);
367365
case AnyObjectTO anyObjectTO ->
368366
jexlVars.put("anyObject", anyObjectTO);
369-
default -> {
367+
case null, default -> {
370368
}
371369
}
372370
});

fit/core-reference/src/test/java/org/apache/syncope/fit/core/SearchITCase.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
*/
1919
package org.apache.syncope.fit.core;
2020

21+
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
2122
import static org.junit.jupiter.api.Assertions.assertEquals;
2223
import static org.junit.jupiter.api.Assertions.assertFalse;
2324
import static org.junit.jupiter.api.Assertions.assertNotEquals;
@@ -1043,4 +1044,10 @@ void issueSYNCOPE1922() {
10431044
sce.getMessage().contains("IllegalArgumentException: Cannot search by encrypted schema obscure"));
10441045
}
10451046
}
1047+
1048+
@Test
1049+
void issueSYNCOPE1963() {
1050+
assertDoesNotThrow(() -> ANY_OBJECT_SERVICE.search(new AnyQuery.Builder().fiql(
1051+
SyncopeClient.getAnyObjectSearchConditionBuilder(PRINTER).isNotNull("gManager").query()).build()));
1052+
}
10461053
}

0 commit comments

Comments
 (0)