|
23 | 23 | import jakarta.validation.constraints.Min; |
24 | 24 | import java.beans.PropertyDescriptor; |
25 | 25 | import java.lang.annotation.Annotation; |
| 26 | +import java.lang.reflect.InvocationTargetException; |
| 27 | +import java.lang.reflect.Method; |
26 | 28 | import java.time.OffsetDateTime; |
27 | 29 | import java.util.ArrayList; |
28 | 30 | import java.util.List; |
|
31 | 33 | import java.util.regex.Pattern; |
32 | 34 | import java.util.stream.Collectors; |
33 | 35 | import org.apache.commons.lang3.BooleanUtils; |
| 36 | +import org.apache.commons.lang3.ClassUtils; |
34 | 37 | import org.apache.syncope.common.lib.SyncopeConstants; |
35 | 38 | import org.apache.syncope.common.lib.types.AnyTypeKind; |
36 | 39 | import org.apache.syncope.common.lib.types.AttrSchemaType; |
|
59 | 62 | import org.apache.syncope.core.persistence.api.entity.PlainAttr; |
60 | 63 | import org.apache.syncope.core.persistence.api.entity.PlainAttrValue; |
61 | 64 | import org.apache.syncope.core.persistence.api.entity.PlainSchema; |
| 65 | +import org.apache.syncope.core.persistence.api.entity.Realm; |
62 | 66 | import org.apache.syncope.core.persistence.api.entity.Relatable; |
63 | 67 | import org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject; |
64 | 68 | 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) |
439 | 443 |
|
440 | 444 | // Deal with any fields representing relationships to other entities |
441 | 445 | relationshipFieldMatches(pd, cond, schema); |
| 446 | + if (!(anyAttrValue instanceof String)) { |
| 447 | + |
| 448 | + try { |
| 449 | + Method relMethod = null; |
| 450 | + if (!SyncopeConstants.UUID_PATTERN.matcher(cond.getExpression()).matches()) { |
| 451 | + Class<?> type = pd.getPropertyType(); |
| 452 | + |
| 453 | + if (Realm.class.isAssignableFrom(type)) { |
| 454 | + relMethod = ClassUtils.getPublicMethod(pd.getPropertyType(), "getFullPath"); |
| 455 | + } else if (User.class.isAssignableFrom(type)) { |
| 456 | + relMethod = ClassUtils.getPublicMethod(pd.getPropertyType(), "getUsername"); |
| 457 | + } else if (Group.class.isAssignableFrom(type)) { |
| 458 | + relMethod = ClassUtils.getPublicMethod(pd.getPropertyType(), "getName"); |
| 459 | + } |
| 460 | + } else { |
| 461 | + relMethod = ClassUtils.getPublicMethod(pd.getPropertyType(), "getKey"); |
| 462 | + } |
| 463 | + |
| 464 | + if (relMethod != null && String.class.isAssignableFrom(relMethod.getReturnType())) { |
| 465 | + anyAttrValue = relMethod.invoke(anyAttrValue); |
| 466 | + } |
| 467 | + } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { |
| 468 | + LOG.error("Could not find getter method for relationshipField of type [{}]", |
| 469 | + pd.getPropertyType().getSimpleName(), e); |
| 470 | + } |
| 471 | + } |
442 | 472 |
|
443 | 473 | PlainAttrValue attrValue = new PlainAttrValue(); |
444 | 474 | if (cond.getType() != AttrCond.Type.LIKE |
|
0 commit comments