diff --git a/core/persistence-common/src/main/java/org/apache/syncope/core/persistence/common/dao/AbstractAnyMatchDAO.java b/core/persistence-common/src/main/java/org/apache/syncope/core/persistence/common/dao/AbstractAnyMatchDAO.java index 7b19f5e6c4..aaa235f371 100644 --- a/core/persistence-common/src/main/java/org/apache/syncope/core/persistence/common/dao/AbstractAnyMatchDAO.java +++ b/core/persistence-common/src/main/java/org/apache/syncope/core/persistence/common/dao/AbstractAnyMatchDAO.java @@ -23,6 +23,8 @@ import jakarta.validation.constraints.Min; import java.beans.PropertyDescriptor; import java.lang.annotation.Annotation; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.time.OffsetDateTime; import java.util.ArrayList; import java.util.List; @@ -31,6 +33,7 @@ import java.util.regex.Pattern; import java.util.stream.Collectors; import org.apache.commons.lang3.BooleanUtils; +import org.apache.commons.lang3.ClassUtils; import org.apache.syncope.common.lib.SyncopeConstants; import org.apache.syncope.common.lib.types.AnyTypeKind; import org.apache.syncope.common.lib.types.AttrSchemaType; @@ -59,6 +62,7 @@ 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.PlainSchema; +import org.apache.syncope.core.persistence.api.entity.Realm; import org.apache.syncope.core.persistence.api.entity.Relatable; import org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject; import org.apache.syncope.core.persistence.api.entity.group.Group; @@ -439,6 +443,32 @@ protected boolean matches(final Any any, final AnyCond cond, final boolean not) // Deal with any fields representing relationships to other entities relationshipFieldMatches(pd, cond, schema); + if (!(anyAttrValue instanceof String)) { + + try { + Method relMethod = null; + if (!SyncopeConstants.UUID_PATTERN.matcher(cond.getExpression()).matches()) { + Class type = pd.getPropertyType(); + + if (Realm.class.isAssignableFrom(type)) { + relMethod = ClassUtils.getPublicMethod(pd.getPropertyType(), "getFullPath"); + } else if (User.class.isAssignableFrom(type)) { + relMethod = ClassUtils.getPublicMethod(pd.getPropertyType(), "getUsername"); + } else if (Group.class.isAssignableFrom(type)) { + relMethod = ClassUtils.getPublicMethod(pd.getPropertyType(), "getName"); + } + } else { + relMethod = ClassUtils.getPublicMethod(pd.getPropertyType(), "getKey"); + } + + if (relMethod != null && String.class.isAssignableFrom(relMethod.getReturnType())) { + anyAttrValue = relMethod.invoke(anyAttrValue); + } + } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { + LOG.error("Could not find getter method for relationshipField of type [{}]", + pd.getPropertyType().getSimpleName(), e); + } + } PlainAttrValue attrValue = new PlainAttrValue(); if (cond.getType() != AttrCond.Type.LIKE