This is an automated email from the ASF dual-hosted git repository.
ilgrosso pushed a commit to branch 3_0_X
in repository https://gitbox.apache.org/repos/asf/syncope.git
The following commit(s) were added to refs/heads/3_0_X by this push:
new 1d47f6a4fc Upgrading OpenSearch
1d47f6a4fc is described below
commit 1d47f6a4fc6760ab529ffecff472a5563a7ecde1
Author: Francesco Chicchiriccò <[email protected]>
AuthorDate: Thu Oct 17 08:44:38 2024 +0200
Upgrading OpenSearch
---
.../core/persistence/jpa/outer/AnySearchTest.java | 39 ++++++
.../elasticsearch/client/ElasticsearchUtils.java | 14 +-
.../ext/opensearch/client/OpenSearchUtils.java | 14 +-
.../org/apache/syncope/fit/core/SearchITCase.java | 143 +++++++++++++--------
pom.xml | 2 +-
5 files changed, 139 insertions(+), 73 deletions(-)
diff --git
a/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/outer/AnySearchTest.java
b/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/outer/AnySearchTest.java
index 3be78d4059..6e60f39f8e 100644
---
a/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/outer/AnySearchTest.java
+++
b/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/outer/AnySearchTest.java
@@ -33,6 +33,7 @@ import org.apache.syncope.common.lib.types.AnyTypeKind;
import org.apache.syncope.common.lib.types.ClientExceptionType;
import org.apache.syncope.common.lib.types.IdRepoEntitlement;
import
org.apache.syncope.core.persistence.api.attrvalue.validation.PlainAttrValidationManager;
+import org.apache.syncope.core.persistence.api.dao.AnyObjectDAO;
import org.apache.syncope.core.persistence.api.dao.AnySearchDAO;
import org.apache.syncope.core.persistence.api.dao.GroupDAO;
import org.apache.syncope.core.persistence.api.dao.PlainSchemaDAO;
@@ -45,6 +46,9 @@ import
org.apache.syncope.core.persistence.api.dao.search.OrderByClause;
import org.apache.syncope.core.persistence.api.dao.search.RoleCond;
import org.apache.syncope.core.persistence.api.dao.search.SearchCond;
import org.apache.syncope.core.persistence.api.entity.Role;
+import org.apache.syncope.core.persistence.api.entity.anyobject.AMembership;
+import org.apache.syncope.core.persistence.api.entity.anyobject.APlainAttr;
+import org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject;
import org.apache.syncope.core.persistence.api.entity.group.GPlainAttr;
import org.apache.syncope.core.persistence.api.entity.group.Group;
import org.apache.syncope.core.persistence.api.entity.user.DynRoleMembership;
@@ -66,6 +70,9 @@ public class AnySearchTest extends AbstractTest {
@Autowired
private GroupDAO groupDAO;
+ @Autowired
+ private AnyObjectDAO anyObjectDAO;
+
@Autowired
private AnySearchDAO searchDAO;
@@ -152,6 +159,38 @@ public class AnySearchTest extends AbstractTest {
assertEquals(rossini.getKey(), users.get(0).getKey());
}
+ @Test
+ public void searchByMembershipAttribute() {
+ AttrCond attrCond = new AttrCond(AttrCond.Type.EQ);
+ attrCond.setSchema("ctype");
+ attrCond.setExpression("otherchildctype");
+ SearchCond cond = SearchCond.getLeaf(attrCond);
+
+ List<AnyObject> results = searchDAO.search(cond,
AnyTypeKind.ANY_OBJECT);
+ assertTrue(results.isEmpty());
+
+ // add any object membership and its plain attribute
+ AnyObject anyObject =
anyObjectDAO.find("8559d14d-58c2-46eb-a2d4-a7d35161e8f8");
+ AMembership memb = entityFactory.newEntity(AMembership.class);
+ memb.setLeftEnd(anyObject);
+ memb.setRightEnd(groupDAO.findByName("otherchild"));
+ anyObject.add(memb);
+ anyObject = anyObjectDAO.save(anyObject);
+
+ APlainAttr attr = entityFactory.newEntity(APlainAttr.class);
+ attr.setSchema(plainSchemaDAO.find("ctype"));
+ attr.add(validator, "otherchildctype",
anyUtilsFactory.getInstance(AnyTypeKind.ANY_OBJECT));
+ attr.setOwner(anyObject);
+ attr.setMembership(anyObject.getMemberships().get(0));
+ anyObject.add(attr);
+ anyObjectDAO.save(anyObject);
+
+ results = searchDAO.search(cond, AnyTypeKind.ANY_OBJECT);
+ assertEquals(1, results.size());
+
+ assertTrue(results.stream().anyMatch(a ->
"8559d14d-58c2-46eb-a2d4-a7d35161e8f8".equals(a.getKey())));
+ }
+
@Test
public void issueSYNCOPE95() {
groupDAO.findAll(1, 100).forEach(group ->
groupDAO.delete(group.getKey()));
diff --git
a/ext/elasticsearch/client-elasticsearch/src/main/java/org/apache/syncope/ext/elasticsearch/client/ElasticsearchUtils.java
b/ext/elasticsearch/client-elasticsearch/src/main/java/org/apache/syncope/ext/elasticsearch/client/ElasticsearchUtils.java
index 257a0fed44..2093c51451 100644
---
a/ext/elasticsearch/client-elasticsearch/src/main/java/org/apache/syncope/ext/elasticsearch/client/ElasticsearchUtils.java
+++
b/ext/elasticsearch/client-elasticsearch/src/main/java/org/apache/syncope/ext/elasticsearch/client/ElasticsearchUtils.java
@@ -36,14 +36,11 @@ import org.apache.syncope.core.persistence.api.dao.GroupDAO;
import org.apache.syncope.core.persistence.api.dao.UserDAO;
import org.apache.syncope.core.persistence.api.entity.Any;
import org.apache.syncope.core.persistence.api.entity.AnyTypeClass;
-import org.apache.syncope.core.persistence.api.entity.GroupablePlainAttr;
import org.apache.syncope.core.persistence.api.entity.GroupableRelatable;
-import org.apache.syncope.core.persistence.api.entity.Membership;
import org.apache.syncope.core.persistence.api.entity.PlainAttr;
import org.apache.syncope.core.persistence.api.entity.PlainAttrValue;
import org.apache.syncope.core.persistence.api.entity.Privilege;
import org.apache.syncope.core.persistence.api.entity.Realm;
-import org.apache.syncope.core.persistence.api.entity.Relationship;
import org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject;
import org.apache.syncope.core.persistence.api.entity.group.Group;
import org.apache.syncope.core.persistence.api.entity.user.User;
@@ -209,11 +206,10 @@ public class ElasticsearchUtils {
// add also flattened membership attributes
if (any instanceof GroupableRelatable) {
- GroupableRelatable<? extends Any, ? extends Membership, ? extends
GroupablePlainAttr, ? extends Any, ?
- extends Relationship> entity =
GroupableRelatable.class.cast(any);
- entity.getMemberships().forEach(m ->
entity.getPlainAttrs(m).forEach(mAttr -> {
- List<Object> values =
mAttr.getValues().stream().map(PlainAttrValue::getValue)
- .collect(Collectors.toList());
+ GroupableRelatable<?, ?, ?, ?, ?> groupable =
GroupableRelatable.class.cast(any);
+ groupable.getMemberships().forEach(m ->
groupable.getPlainAttrs(m).forEach(mAttr -> {
+ List<Object> values = mAttr.getValues().stream().
+
map(PlainAttrValue::getValue).collect(Collectors.toList());
Optional.ofNullable(mAttr.getUniqueValue()).ifPresent(v ->
values.add(v.getValue()));
@@ -227,7 +223,7 @@ public class ElasticsearchUtils {
}
}));
}
-
+
return builder;
}
diff --git
a/ext/opensearch/client-opensearch/src/main/java/org/apache/syncope/ext/opensearch/client/OpenSearchUtils.java
b/ext/opensearch/client-opensearch/src/main/java/org/apache/syncope/ext/opensearch/client/OpenSearchUtils.java
index 8f79317a84..8650fe09a4 100644
---
a/ext/opensearch/client-opensearch/src/main/java/org/apache/syncope/ext/opensearch/client/OpenSearchUtils.java
+++
b/ext/opensearch/client-opensearch/src/main/java/org/apache/syncope/ext/opensearch/client/OpenSearchUtils.java
@@ -36,14 +36,11 @@ import org.apache.syncope.core.persistence.api.dao.GroupDAO;
import org.apache.syncope.core.persistence.api.dao.UserDAO;
import org.apache.syncope.core.persistence.api.entity.Any;
import org.apache.syncope.core.persistence.api.entity.AnyTypeClass;
-import org.apache.syncope.core.persistence.api.entity.GroupablePlainAttr;
import org.apache.syncope.core.persistence.api.entity.GroupableRelatable;
-import org.apache.syncope.core.persistence.api.entity.Membership;
import org.apache.syncope.core.persistence.api.entity.PlainAttr;
import org.apache.syncope.core.persistence.api.entity.PlainAttrValue;
import org.apache.syncope.core.persistence.api.entity.Privilege;
import org.apache.syncope.core.persistence.api.entity.Realm;
-import org.apache.syncope.core.persistence.api.entity.Relationship;
import org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject;
import org.apache.syncope.core.persistence.api.entity.group.Group;
import org.apache.syncope.core.persistence.api.entity.user.User;
@@ -209,11 +206,10 @@ public class OpenSearchUtils {
// add also flattened membership attributes
if (any instanceof GroupableRelatable) {
- GroupableRelatable<? extends Any, ? extends Membership, ? extends
GroupablePlainAttr, ? extends Any, ?
- extends Relationship> entity =
GroupableRelatable.class.cast(any);
- entity.getMemberships().forEach(m ->
entity.getPlainAttrs(m).forEach(mAttr -> {
- List<Object> values =
mAttr.getValues().stream().map(PlainAttrValue::getValue)
- .collect(Collectors.toList());
+ GroupableRelatable<?, ?, ?, ?, ?> groupable =
GroupableRelatable.class.cast(any);
+ groupable.getMemberships().forEach(m ->
groupable.getPlainAttrs(m).forEach(mAttr -> {
+ List<Object> values = mAttr.getValues().stream().
+
map(PlainAttrValue::getValue).collect(Collectors.toList());
Optional.ofNullable(mAttr.getUniqueValue()).ifPresent(v ->
values.add(v.getValue()));
@@ -227,7 +223,7 @@ public class OpenSearchUtils {
}
}));
}
-
+
return builder;
}
diff --git
a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/SearchITCase.java
b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/SearchITCase.java
index 9f6364af0c..93919052c5 100644
---
a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/SearchITCase.java
+++
b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/SearchITCase.java
@@ -18,7 +18,6 @@
*/
package org.apache.syncope.fit.core;
-import static org.awaitility.Awaitility.await;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
@@ -625,6 +624,95 @@ public class SearchITCase extends AbstractITCase {
assertTrue(users > 0);
}
+ @Test
+ public void userByMembershipAttribute() {
+ // create type extension for the 'employee' group, if not present
+ GroupTO employee = GROUP_SERVICE.read("employee");
+ if (employee.getTypeExtension(AnyTypeKind.USER.name()).isEmpty()) {
+ TypeExtensionTO typeExtensionTO = new TypeExtensionTO();
+ typeExtensionTO.setAnyType(AnyTypeKind.USER.name());
+ typeExtensionTO.getAuxClasses().add("other");
+ updateGroup(new
GroupUR.Builder(employee.getKey()).typeExtension(typeExtensionTO).build());
+ }
+
+ if (IS_EXT_SEARCH_ENABLED) {
+ try {
+ Thread.sleep(2000);
+ } catch (InterruptedException ex) {
+ // ignore
+ }
+ }
+
+ PagedResult<UserTO> matching = USER_SERVICE.search(
+ new
AnyQuery.Builder().fiql(SyncopeClient.getUserSearchConditionBuilder().
+
is("ctype").equalTo("additionalctype").query()).build());
+ assertEquals(0, matching.getTotalCount());
+ matching = USER_SERVICE.search(
+ new
AnyQuery.Builder().fiql(SyncopeClient.getUserSearchConditionBuilder().
+ is("ctype").equalTo("myownctype").query()).build());
+ assertEquals(0, matching.getTotalCount());
+
+ // add user membership and its plain attribute
+ updateUser(new UserUR.Builder(USER_SERVICE.read("puccini").getKey())
+ .plainAttr(attrAddReplacePatch("ctype", "myownctype"))
+ .membership(new
MembershipUR.Builder(GROUP_SERVICE.read("additional").getKey()).
+ plainAttrs(attr("ctype", "additionalctype")).build())
+ .membership(new MembershipUR.Builder(employee.getKey())
+ .plainAttrs(attr("ctype",
"additionalemployeectype")).build())
+ .build());
+
+ if (IS_EXT_SEARCH_ENABLED) {
+ try {
+ Thread.sleep(2000);
+ } catch (InterruptedException ex) {
+ // ignore
+ }
+ }
+
+ matching = USER_SERVICE.search(
+ new
AnyQuery.Builder().fiql(SyncopeClient.getUserSearchConditionBuilder().
+
is("ctype").equalTo("additionalctype").query()).build());
+ assertEquals(1, matching.getTotalCount());
+ assertTrue(matching.getResult().stream().anyMatch(u ->
"puccini".equals(u.getUsername())));
+
+ // check also that search on user plain attribute (not in membership)
works
+ matching = USER_SERVICE.search(
+ new
AnyQuery.Builder().fiql(SyncopeClient.getUserSearchConditionBuilder().
+ is("ctype").equalTo("myownctype").query()).build());
+ assertEquals(1, matching.getTotalCount());
+ assertTrue(matching.getResult().stream().anyMatch(u ->
"puccini".equals(u.getUsername())));
+ }
+
+ @Test
+ public void anyObjectByMembershipAttribute() {
+ PagedResult<AnyObjectTO> matching = ANY_OBJECT_SERVICE.search(
+ new
AnyQuery.Builder().fiql(SyncopeClient.getAnyObjectSearchConditionBuilder(PRINTER)
+
.is("ctype").equalTo("otherchildctype").query()).build());
+ assertEquals(0, matching.getTotalCount());
+
+ // add any object membership and its plain attribute
+ updateAnyObject(new
AnyObjectUR.Builder("8559d14d-58c2-46eb-a2d4-a7d35161e8f8").
+ membership(new
MembershipUR.Builder(GROUP_SERVICE.read("otherchild").getKey()).
+ plainAttrs(attr("ctype", "otherchildctype")).
+ build()).build());
+
+ if (IS_EXT_SEARCH_ENABLED) {
+ try {
+ Thread.sleep(2000);
+ } catch (InterruptedException ex) {
+ // ignore
+ }
+ }
+
+ matching = ANY_OBJECT_SERVICE.search(
+ new
AnyQuery.Builder().fiql(SyncopeClient.getAnyObjectSearchConditionBuilder(PRINTER)
+
.is("ctype").equalTo("otherchildctype").query()).build());
+ assertEquals(1, matching.getTotalCount());
+
+ assertTrue(matching.getResult().stream().
+ anyMatch(a ->
"8559d14d-58c2-46eb-a2d4-a7d35161e8f8".equals(a.getKey())));
+ }
+
@Test
public void issueSYNCOPE768() {
int usersWithNullable = USER_SERVICE.search(new
AnyQuery.Builder().realm(SyncopeConstants.ROOT_REALM).
@@ -1054,57 +1142,4 @@ public class SearchITCase extends AbstractITCase {
deleteUser("user test 182");
}
}
-
- @Test
- void userByMembershipAttribute() {
- // search user by membership attribute
- UserTO puccini = USER_SERVICE.read("puccini");
- GroupTO additional = GROUP_SERVICE.read("additional");
- GroupTO employee = GROUP_SERVICE.read("employee");
- TypeExtensionTO typeExtensionTO = new TypeExtensionTO();
- typeExtensionTO.setAnyType(AnyTypeKind.USER.name());
- typeExtensionTO.getAuxClasses().add("other");
- updateGroup(new
GroupUR.Builder(employee.getKey()).typeExtension(typeExtensionTO).build());
- // add a membership and its plain attribute
- updateUser(new UserUR.Builder(puccini.getKey())
- .plainAttr(attrAddReplacePatch("ctype", "myownctype"))
- .memberships(
- new
MembershipUR.Builder(additional.getKey()).plainAttrs(attr("ctype",
"additionalctype"))
- .build(), new MembershipUR.Builder(employee.getKey())
- .plainAttrs(attr("ctype",
"additionalemployeectype"))
- .build()).build());
- await().until(() -> USER_SERVICE.search(new
AnyQuery.Builder().page(1).size(10)
-
.fiql(SyncopeClient.getUserSearchConditionBuilder().is("ctype").equalTo("additionalctype").query())
- .build()).getTotalCount() == 1);
- assertTrue(USER_SERVICE.search(new AnyQuery.Builder().page(1).size(10)
-
.fiql(SyncopeClient.getUserSearchConditionBuilder().is("ctype").equalTo("additionalctype").query())
- .build()).getResult().stream().anyMatch(u ->
"puccini".equals(u.getUsername())));
- assertTrue(USER_SERVICE.search(new AnyQuery.Builder().page(1).size(10)
-
.fiql(SyncopeClient.getUserSearchConditionBuilder().is("ctype").equalTo("additionalemployeectype")
- .query()).build()).getResult().stream().anyMatch(u ->
"puccini".equals(u.getUsername())));
- // check also that search on user plain attribute (not in membership)
works
- assertTrue(USER_SERVICE.search(new AnyQuery.Builder().page(1).size(10)
-
.fiql(SyncopeClient.getUserSearchConditionBuilder().is("ctype").equalTo("myownctype").query())
- .build()).getResult().stream().anyMatch(u ->
"puccini".equals(u.getUsername())));
- }
-
- @Test
- void anyObjectByMembershipAttribute() {
- // search user by membership attribute
- AnyObjectTO canonMf =
ANY_OBJECT_SERVICE.read("8559d14d-58c2-46eb-a2d4-a7d35161e8f8");
- GroupTO otherchild = GROUP_SERVICE.read("otherchild");
- // add a membership and its plain attribute
- updateAnyObject(new AnyObjectUR.Builder(canonMf.getKey()).memberships(
- new
MembershipUR.Builder(otherchild.getKey()).plainAttrs(attr("ctype",
"otherchildctype"))
- .build()).build());
- await().until(() -> ANY_OBJECT_SERVICE.search(new
AnyQuery.Builder().page(1).size(10)
-
.fiql(SyncopeClient.getAnyObjectSearchConditionBuilder(PRINTER).is("ctype").equalTo("otherchildctype")
- .query()).build()).getTotalCount() == 1);
- assertTrue(ANY_OBJECT_SERVICE.search(new
AnyQuery.Builder().page(1).size(10)
-
.fiql(SyncopeClient.getAnyObjectSearchConditionBuilder(PRINTER).is("ctype").equalTo(
- "otherchildctype")
- .query()).build()).getResult().stream()
- .anyMatch(u ->
"8559d14d-58c2-46eb-a2d4-a7d35161e8f8".equals(u.getKey())));
- }
-
}
diff --git a/pom.xml b/pom.xml
index 1e4df61a30..c0e2c09a58 100644
--- a/pom.xml
+++ b/pom.xml
@@ -432,7 +432,7 @@ under the License.
<elasticsearch.version>8.15.2</elasticsearch.version>
<opensearch.version>2.17.1</opensearch.version>
- <opensearch-java.version>2.14.0</opensearch-java.version>
+ <opensearch-java.version>2.15.0</opensearch-java.version>
<log4j2.version>2.22.0</log4j2.version>
<disruptor.version>3.4.4</disruptor.version>