Skip to content

Commit 6378ea9

Browse files
[SYNCOPE-1922] raise error while searching by encrypted plain schema, removed suggestion of such schemas on search in console (#1218)
1 parent 9826b55 commit 6378ea9

File tree

4 files changed

+47
-1
lines changed

4 files changed

+47
-1
lines changed

client/idrepo/console/src/main/java/org/apache/syncope/client/console/panels/search/AnyObjectSearchPanel.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.apache.syncope.common.lib.to.PlainSchemaTO;
3434
import org.apache.syncope.common.lib.to.SchemaTO;
3535
import org.apache.syncope.common.lib.types.AnyTypeKind;
36+
import org.apache.syncope.common.lib.types.AttrSchemaType;
3637
import org.apache.syncope.common.lib.types.SchemaType;
3738
import org.apache.wicket.PageReference;
3839
import org.apache.wicket.extensions.markup.html.repeater.util.SortParam;
@@ -123,7 +124,8 @@ protected List<String> load() {
123124
protected Map<String, PlainSchemaTO> load() {
124125
return schemaRestClient.<PlainSchemaTO>getSchemas(
125126
SchemaType.PLAIN, null, anyTypeRestClient.read(anyType).getClasses().toArray(String[]::new)).
126-
stream().collect(Collectors.toMap(SchemaTO::getKey, Function.identity()));
127+
stream().filter(schema -> AttrSchemaType.Encrypted != schema.getType()).
128+
collect(Collectors.toMap(SchemaTO::getKey, Function.identity()));
127129
}
128130
};
129131
}

core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/AbstractAnySearchDAO.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,10 @@ protected Pair<PlainSchema, PlainAttrValue> check(final AttrCond cond, final Any
202202
PlainSchema schema = Optional.ofNullable(plainSchemaDAO.find(cond.getSchema())).
203203
orElseThrow(() -> new IllegalArgumentException("Invalid schema " + cond.getSchema()));
204204

205+
if (AttrSchemaType.Encrypted == schema.getType()) {
206+
throw new IllegalArgumentException("Cannot search by encrypted schema " + cond.getSchema());
207+
}
208+
205209
PlainAttrValue attrValue = schema.isUniqueConstraint()
206210
? anyUtils.newPlainAttrUniqueValue()
207211
: anyUtils.newPlainAttrValue();

core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/AnySearchTest.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import static org.junit.jupiter.api.Assertions.assertEquals;
2222
import static org.junit.jupiter.api.Assertions.assertFalse;
2323
import static org.junit.jupiter.api.Assertions.assertNotNull;
24+
import static org.junit.jupiter.api.Assertions.assertThrows;
2425
import static org.junit.jupiter.api.Assertions.assertTrue;
2526

2627
import java.text.ParseException;
@@ -1067,6 +1068,26 @@ public void issueSYNCOPE1906() {
10671068
assertEquals("bellini", users.get(0).getUsername());
10681069
}
10691070

1071+
@Test
1072+
public void issueSYNCOPE1922() {
1073+
User bellini = userDAO.findByUsername("bellini");
1074+
assertNotNull(bellini);
1075+
1076+
PlainSchema obscureSchema = plainSchemaDAO.find("obscure");
1077+
assertNotNull(obscureSchema);
1078+
1079+
userDAO.save(addPlainAttr(bellini, obscureSchema, "myobscurevalue"));
1080+
1081+
entityManager().flush();
1082+
1083+
AttrCond obscureCond = new AttrCond(AttrCond.Type.EQ);
1084+
obscureCond.setSchema("obscure");
1085+
obscureCond.setExpression("myobscurevalue");
1086+
1087+
assertThrows(IllegalArgumentException.class,
1088+
() -> searchDAO.search(SearchCond.getLeaf(obscureCond), AnyTypeKind.USER));
1089+
}
1090+
10701091
private User addPlainAttr(final User user, final PlainSchema plainSchema, final String value) {
10711092
user.getPlainAttr(plainSchema.getKey())
10721093
.ifPresentOrElse(ctype -> ctype.getValues().get(0).setStringValue(value), () -> {

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,4 +1142,23 @@ void issueSYNCOPE1826() {
11421142
deleteUser("user test 182");
11431143
}
11441144
}
1145+
1146+
@Test
1147+
public void issueSYNCOPE1922() {
1148+
// 1. set encrypted value
1149+
updateUser(new UserUR.Builder(USER_SERVICE.read("bellini").getKey()).plainAttr(
1150+
attrAddReplacePatch("obscure", "myobscurevalue")).build());
1151+
// 2. search by encrypted value
1152+
try {
1153+
USER_SERVICE.search(new AnyQuery.Builder().fiql(SyncopeClient.getUserSearchConditionBuilder()
1154+
.and(List.of(SyncopeClient.getUserSearchConditionBuilder().is("obscure").equalTo("myobscurevalue"),
1155+
SyncopeClient.getUserSearchConditionBuilder().is("surname").equalTo("bellini")))
1156+
.query()).page(1).size(1).build());
1157+
fail("Search should have been blocked, since on encrypted schema");
1158+
} catch (SyncopeClientException sce) {
1159+
assertEquals(ClientExceptionType.InvalidSearchParameters, sce.getType());
1160+
assertTrue(
1161+
sce.getMessage().contains("IllegalArgumentException: Cannot search by encrypted schema obscure"));
1162+
}
1163+
}
11451164
}

0 commit comments

Comments
 (0)