Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.apache.syncope.common.lib.to.PlainSchemaTO;
import org.apache.syncope.common.lib.to.SchemaTO;
import org.apache.syncope.common.lib.types.AnyTypeKind;
import org.apache.syncope.common.lib.types.AttrSchemaType;
import org.apache.syncope.common.lib.types.SchemaType;
import org.apache.wicket.PageReference;
import org.apache.wicket.extensions.markup.html.repeater.util.SortParam;
Expand Down Expand Up @@ -123,7 +124,8 @@ protected List<String> load() {
protected Map<String, PlainSchemaTO> load() {
return schemaRestClient.<PlainSchemaTO>getSchemas(
SchemaType.PLAIN, null, anyTypeRestClient.read(anyType).getClasses().toArray(String[]::new)).
stream().collect(Collectors.toMap(SchemaTO::getKey, Function.identity()));
stream().filter(schema -> AttrSchemaType.Encrypted != schema.getType()).
collect(Collectors.toMap(SchemaTO::getKey, Function.identity()));
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,11 @@ protected Pair<PlainSchema, PlainAttrValue> check(final AttrCond cond) {
orElseThrow(() -> new IllegalArgumentException("Invalid schema " + cond.getSchema()));

PlainAttrValue attrValue = new PlainAttrValue();

if (AttrSchemaType.Encrypted == schema.getType()) {
throw new IllegalArgumentException("Cannot search by encrypted schema " + cond.getSchema());
}

try {
if (cond.getType() != AttrCond.Type.LIKE
&& cond.getType() != AttrCond.Type.ILIKE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.text.ParseException;
Expand Down Expand Up @@ -1027,6 +1028,26 @@ public void issueSYNCOPE1906() {
assertEquals("bellini", users.get(0).getUsername());
}

@Test
public void issueSYNCOPE1922() {
User bellini = userDAO.findByUsername("bellini").orElseThrow();
assertNotNull(bellini);

PlainSchema obscureSchema = plainSchemaDAO.findById("obscure").orElseThrow();
assertNotNull(obscureSchema);

userDAO.save(addPlainAttr(bellini, obscureSchema, "myobscurevalue"));

entityManager.flush();

AttrCond obscureCond = new AttrCond(AttrCond.Type.EQ);
obscureCond.setSchema("obscure");
obscureCond.setExpression("myobscurevalue");

assertThrows(IllegalArgumentException.class,
() -> searchDAO.search(SearchCond.of(obscureCond), AnyTypeKind.USER));
}

private User addPlainAttr(final User user, final PlainSchema plainSchema, final String value) {
user.getPlainAttr(plainSchema.getKey())
.ifPresentOrElse(ctype -> ctype.getValues().get(0).setStringValue(value), () -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1163,4 +1163,23 @@ void issueSYNCOPE1826() {
deleteUser("user test 182");
}
}

@Test
public void issueSYNCOPE1922() {
// 1. set encrypted value
updateUser(new UserUR.Builder(USER_SERVICE.read("bellini").getKey()).plainAttr(
attrAddReplacePatch("obscure", "myobscurevalue")).build());
// 2. search by encrypted value
try {
USER_SERVICE.search(new AnyQuery.Builder().fiql(SyncopeClient.getUserSearchConditionBuilder()
.and(List.of(SyncopeClient.getUserSearchConditionBuilder().is("obscure").equalTo("myobscurevalue"),
SyncopeClient.getUserSearchConditionBuilder().is("surname").equalTo("bellini")))
.query()).page(1).size(1).build());
fail("Search should have been blocked, since on encrypted schema");
} catch (SyncopeClientException sce) {
assertEquals(ClientExceptionType.InvalidSearchParameters, sce.getType());
assertTrue(
sce.getMessage().contains("IllegalArgumentException: Cannot search by encrypted schema obscure"));
}
}
}