use of org.gluu.oxtrust.service.antlr.scimFilter.enums.ScimOperator in project oxTrust by GluuFederation.
the class MatchFilterVisitor method visitAttrexp.
@Override
public Boolean visitAttrexp(ScimFilterParser.AttrexpContext ctx) {
log.trace("visitAttrexp. childs: {}, text: {}", ctx.getChildCount(), ctx.getText());
String path = ctx.attrpath().getText();
ScimFilterParser.CompvalueContext compValueCtx = ctx.compvalue();
boolean isPrRule = compValueCtx == null && ctx.getChild(1).getText().equals("pr");
ScimOperator operator;
CompValueType valueType;
String value;
if (isPrRule) {
operator = ScimOperator.NOT_EQUAL;
valueType = CompValueType.NULL;
value = null;
} else {
operator = ScimOperator.getByValue(ctx.compareop().getText());
valueType = FilterUtil.getCompValueType(compValueCtx);
value = compValueCtx.getText();
if (// drop double quotes
CompValueType.STRING.equals(valueType))
value = value.substring(1, value.length() - 1);
}
SimpleExpression expr = new SimpleExpression(path, operator, valueType, value);
expr.setParentAttribute(parentAttribute);
expr.setResourceClass(resourceClass);
return expr.evaluate(item);
}
use of org.gluu.oxtrust.service.antlr.scimFilter.enums.ScimOperator in project oxTrust by GluuFederation.
the class LdapFilterListener method enterAttrexp.
@Override
public void enterAttrexp(ScimFilterParser.AttrexpContext ctx) {
if (StringUtils.isEmpty(error)) {
log.trace("enterAttrexp.");
String path = ctx.attrpath().getText();
ScimFilterParser.CompvalueContext compValueCtx = ctx.compvalue();
boolean isPrRule = compValueCtx == null && ctx.getChild(1).getText().equals("pr");
Type attrType = null;
Attribute attrAnnot = IntrospectUtil.getFieldAnnotation(path, resourceClass, Attribute.class);
String ldapAttribute = null;
boolean isNested = false;
if (attrAnnot == null) {
ExtensionField field = extService.getFieldOfExtendedAttribute(resourceClass, path);
if (field == null)
error = String.format("Attribute path '%s' is not recognized in %s", path, resourceClass.getSimpleName());
else {
attrType = field.getAttributeDefinitionType();
ldapAttribute = path.substring(path.lastIndexOf(":") + 1);
}
} else {
attrType = attrAnnot.type();
Pair<String, Boolean> pair = FilterUtil.getLdapAttributeOfResourceAttribute(path, resourceClass);
ldapAttribute = pair.getFirst();
isNested = pair.getSecond();
}
if (error != null)
// Intentionally left empty
;
else if (attrType == null)
error = String.format("Could not determine type of attribute path '%s' in %s", path, resourceClass.getSimpleName());
else if (ldapAttribute == null)
error = String.format("Could not determine LDAP attribute for path '%s' in %s", path, resourceClass.getSimpleName());
else {
String subattr = isNested ? path.substring(path.lastIndexOf(".") + 1) : null;
String subFilth;
CompValueType type;
ScimOperator operator;
if (isPrRule) {
type = CompValueType.NULL;
operator = ScimOperator.NOT_EQUAL;
} else {
type = FilterUtil.getCompValueType(compValueCtx);
operator = ScimOperator.getByValue(ctx.compareop().getText());
}
error = FilterUtil.checkFilterConsistency(path, attrType, type, operator);
if (error == null) {
subFilth = getSubFilter(subattr, ldapAttribute, isPrRule ? null : compValueCtx.getText(), attrType, type, operator);
if (subFilth == null) {
if (error == null)
error = String.format("Operator '%s' is not supported for attribute %s", operator.getValue(), path);
} else
filter.append(subFilth);
}
}
}
}
Aggregations