Skip to content

Commit 0a59884

Browse files
alberto-bogiilgrosso
authored andcommitted
[SYNCOPE-2000] Add AnyAbout filtering by Realm, uManager, and gManager (#1566)
1 parent 69f8a8b commit 0a59884

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

‎core/persistence-common/src/main/java/org/apache/syncope/core/persistence/common/dao/AbstractAnyMatchDAO.java‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import jakarta.validation.constraints.Min;
2424
import java.beans.PropertyDescriptor;
2525
import java.lang.annotation.Annotation;
26+
import java.lang.reflect.InvocationTargetException;
27+
import java.lang.reflect.Method;
2628
import java.time.OffsetDateTime;
2729
import java.util.ArrayList;
2830
import java.util.List;
@@ -31,6 +33,7 @@
3133
import java.util.regex.Pattern;
3234
import java.util.stream.Collectors;
3335
import org.apache.commons.lang3.BooleanUtils;
36+
import org.apache.commons.lang3.ClassUtils;
3437
import org.apache.syncope.common.lib.SyncopeConstants;
3538
import org.apache.syncope.common.lib.types.AnyTypeKind;
3639
import org.apache.syncope.common.lib.types.AttrSchemaType;
@@ -59,6 +62,7 @@
5962
import org.apache.syncope.core.persistence.api.entity.PlainAttr;
6063
import org.apache.syncope.core.persistence.api.entity.PlainAttrValue;
6164
import org.apache.syncope.core.persistence.api.entity.PlainSchema;
65+
import org.apache.syncope.core.persistence.api.entity.Realm;
6266
import org.apache.syncope.core.persistence.api.entity.Relatable;
6367
import org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject;
6468
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)
439443

440444
// Deal with any fields representing relationships to other entities
441445
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+
}
442472

443473
PlainAttrValue attrValue = new PlainAttrValue();
444474
if (cond.getType() != AttrCond.Type.LIKE

0 commit comments

Comments
 (0)