Search in sources :

Example 1 with ScimOperator

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);
}
Also used : ScimOperator(org.gluu.oxtrust.service.antlr.scimFilter.enums.ScimOperator) ScimFilterParser(org.gluu.oxtrust.service.antlr.scimFilter.antlr4.ScimFilterParser) CompValueType(org.gluu.oxtrust.service.antlr.scimFilter.enums.CompValueType) SimpleExpression(org.gluu.oxtrust.service.antlr.scimFilter.util.SimpleExpression)

Example 2 with ScimOperator

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);
            }
        }
    }
}
Also used : Type(org.gluu.oxtrust.model.scim2.AttributeDefinition.Type) CompValueType(org.gluu.oxtrust.service.antlr.scimFilter.enums.CompValueType) ExtensionField(org.gluu.oxtrust.model.scim2.extensions.ExtensionField) Attribute(org.gluu.oxtrust.model.scim2.annotations.Attribute) ScimOperator(org.gluu.oxtrust.service.antlr.scimFilter.enums.ScimOperator) ScimFilterParser(org.gluu.oxtrust.service.antlr.scimFilter.antlr4.ScimFilterParser) CompValueType(org.gluu.oxtrust.service.antlr.scimFilter.enums.CompValueType)

Aggregations

ScimFilterParser (org.gluu.oxtrust.service.antlr.scimFilter.antlr4.ScimFilterParser)2 CompValueType (org.gluu.oxtrust.service.antlr.scimFilter.enums.CompValueType)2 ScimOperator (org.gluu.oxtrust.service.antlr.scimFilter.enums.ScimOperator)2 Type (org.gluu.oxtrust.model.scim2.AttributeDefinition.Type)1 Attribute (org.gluu.oxtrust.model.scim2.annotations.Attribute)1 ExtensionField (org.gluu.oxtrust.model.scim2.extensions.ExtensionField)1 SimpleExpression (org.gluu.oxtrust.service.antlr.scimFilter.util.SimpleExpression)1