Skip to content

Commit 1453817

Browse files
[SYNCOPE-1922] raise error while searching by encrypted plain schema, removed suggestion of such schemas on search in console (#1219)
1 parent 11cf138 commit 1453817

File tree

5 files changed

+84
-1
lines changed

5 files changed

+84
-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-common/src/main/java/org/apache/syncope/core/persistence/common/dao/AbstractAnySearchDAO.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,11 @@ protected Pair<PlainSchema, PlainAttrValue> check(final AttrCond cond) {
242242
orElseThrow(() -> new IllegalArgumentException("Invalid schema " + cond.getSchema()));
243243

244244
PlainAttrValue attrValue = new PlainAttrValue();
245+
246+
if (AttrSchemaType.Encrypted == schema.getType()) {
247+
throw new IllegalArgumentException("Cannot search by encrypted schema " + cond.getSchema());
248+
}
249+
245250
try {
246251
if (cond.getType() != AttrCond.Type.LIKE
247252
&& cond.getType() != AttrCond.Type.ILIKE

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

Lines changed: 19 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;
@@ -1027,6 +1028,24 @@ public void issueSYNCOPE1906() {
10271028
assertEquals("bellini", users.get(0).getUsername());
10281029
}
10291030

1031+
@Test
1032+
public void issueSYNCOPE1922() {
1033+
User bellini = userDAO.findByUsername("bellini").orElseThrow();
1034+
1035+
PlainSchema obscureSchema = plainSchemaDAO.findById("obscure").orElseThrow();
1036+
1037+
userDAO.save(addPlainAttr(bellini, obscureSchema, "myobscurevalue"));
1038+
1039+
entityManager.flush();
1040+
1041+
AttrCond obscureCond = new AttrCond(AttrCond.Type.EQ);
1042+
obscureCond.setSchema("obscure");
1043+
obscureCond.setExpression("myobscurevalue");
1044+
1045+
assertThrows(IllegalArgumentException.class,
1046+
() -> searchDAO.search(SearchCond.of(obscureCond), AnyTypeKind.USER));
1047+
}
1048+
10301049
private User addPlainAttr(final User user, final PlainSchema plainSchema, final String value) {
10311050
user.getPlainAttr(plainSchema.getKey())
10321051
.ifPresentOrElse(ctype -> ctype.getValues().get(0).setStringValue(value), () -> {

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

Lines changed: 38 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;
@@ -36,10 +37,12 @@
3637
import org.apache.syncope.common.lib.SyncopeConstants;
3738
import org.apache.syncope.common.lib.types.AnyTypeKind;
3839
import org.apache.syncope.common.lib.types.IdRepoEntitlement;
40+
import org.apache.syncope.core.persistence.api.attrvalue.PlainAttrValidationManager;
3941
import org.apache.syncope.core.persistence.api.dao.AnyObjectDAO;
4042
import org.apache.syncope.core.persistence.api.dao.AnySearchDAO;
4143
import org.apache.syncope.core.persistence.api.dao.AnyTypeDAO;
4244
import org.apache.syncope.core.persistence.api.dao.GroupDAO;
45+
import org.apache.syncope.core.persistence.api.dao.PlainSchemaDAO;
4346
import org.apache.syncope.core.persistence.api.dao.RealmDAO;
4447
import org.apache.syncope.core.persistence.api.dao.RealmSearchDAO;
4548
import org.apache.syncope.core.persistence.api.dao.RoleDAO;
@@ -56,6 +59,7 @@
5659
import org.apache.syncope.core.persistence.api.dao.search.SearchCond;
5760
import org.apache.syncope.core.persistence.api.entity.AnyType;
5861
import org.apache.syncope.core.persistence.api.entity.PlainAttr;
62+
import org.apache.syncope.core.persistence.api.entity.PlainSchema;
5963
import org.apache.syncope.core.persistence.api.entity.anyobject.AMembership;
6064
import org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject;
6165
import org.apache.syncope.core.persistence.api.entity.group.Group;
@@ -105,6 +109,12 @@ public class AnySearchTest extends AbstractTest {
105109
@Autowired
106110
private RoleDAO roleDAO;
107111

112+
@Autowired
113+
private PlainSchemaDAO plainSchemaDAO;
114+
115+
@Autowired
116+
private PlainAttrValidationManager validator;
117+
108118
@BeforeEach
109119
public void adjustLoginDateForLocalSystem() throws ParseException {
110120
User rossini = userDAO.findByUsername("rossini").orElseThrow();
@@ -974,4 +984,32 @@ public void issueSYNCOPE1419() {
974984
assertNotNull(users);
975985
assertEquals(4, users.size());
976986
}
987+
988+
@Test
989+
public void issueSYNCOPE1922() {
990+
User bellini = userDAO.findByUsername("bellini").orElseThrow();
991+
992+
PlainSchema obscureSchema = plainSchemaDAO.findById("obscure").orElseThrow();
993+
994+
userDAO.save(addPlainAttr(bellini, obscureSchema, "myobscurevalue"));
995+
996+
AttrCond obscureCond = new AttrCond(AttrCond.Type.EQ);
997+
obscureCond.setSchema("obscure");
998+
obscureCond.setExpression("myobscurevalue");
999+
1000+
assertThrows(IllegalArgumentException.class,
1001+
() -> searchDAO.search(SearchCond.of(obscureCond), AnyTypeKind.USER));
1002+
}
1003+
1004+
protected User addPlainAttr(final User user, final PlainSchema plainSchema, final String value) {
1005+
user.getPlainAttr(plainSchema.getKey())
1006+
.ifPresentOrElse(ctype -> ctype.getValues().get(0).setStringValue(value), () -> {
1007+
PlainAttr attr = new PlainAttr();
1008+
attr.setPlainSchema(plainSchema);
1009+
attr.add(validator, value);
1010+
1011+
user.add(attr);
1012+
});
1013+
return user;
1014+
}
9771015
}

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
@@ -1163,4 +1163,23 @@ void issueSYNCOPE1826() {
11631163
deleteUser("user test 182");
11641164
}
11651165
}
1166+
1167+
@Test
1168+
public void issueSYNCOPE1922() {
1169+
// 1. set encrypted value
1170+
updateUser(new UserUR.Builder(USER_SERVICE.read("bellini").getKey()).plainAttr(
1171+
attrAddReplacePatch("obscure", "myobscurevalue")).build());
1172+
// 2. search by encrypted value
1173+
try {
1174+
USER_SERVICE.search(new AnyQuery.Builder().fiql(SyncopeClient.getUserSearchConditionBuilder()
1175+
.and(List.of(SyncopeClient.getUserSearchConditionBuilder().is("obscure").equalTo("myobscurevalue"),
1176+
SyncopeClient.getUserSearchConditionBuilder().is("surname").equalTo("bellini")))
1177+
.query()).page(1).size(1).build());
1178+
fail("Search should have been blocked, since on encrypted schema");
1179+
} catch (SyncopeClientException sce) {
1180+
assertEquals(ClientExceptionType.InvalidSearchParameters, sce.getType());
1181+
assertTrue(
1182+
sce.getMessage().contains("IllegalArgumentException: Cannot search by encrypted schema obscure"));
1183+
}
1184+
}
11661185
}

0 commit comments

Comments
 (0)