Search in sources :

Example 1 with OperationNode

use of org.wso2.charon3.core.utils.codeutils.OperationNode in project carbon-identity-framework by wso2.

the class FilterTreeBuilder method factor.

/**
 * We build the parser using the recursive descent parser technique.
 */
private void factor() throws IdentityException {
    symbol = nextSymbol();
    if (symbol.equals(String.valueOf(IdentityCoreConstants.Filter.NOT))) {
        OperationNode not = new OperationNode(IdentityCoreConstants.Filter.NOT);
        factor();
        not.setRightNode(root);
        root = not;
    } else if (symbol.equals(String.valueOf("("))) {
        expression();
        // We don't care about ')'.
        symbol = nextSymbol();
    } else {
        if (!(symbol.equals(String.valueOf(")")))) {
            ExpressionNode expressionNode = new ExpressionNode();
            validateAndBuildFilterExpression(symbol, expressionNode);
            root = expressionNode;
            symbol = nextSymbol();
        } else {
            throw new IdentityException("Invalid argument: Identity Provider filter name value is empty or " + "invalid symbol: " + symbol);
        }
    }
}
Also used : IdentityException(org.wso2.carbon.identity.base.IdentityException)

Example 2 with OperationNode

use of org.wso2.charon3.core.utils.codeutils.OperationNode in project identity-inbound-provisioning-scim2 by wso2-extensions.

the class SCIMRoleManagerTest method generateNodeBasedOnNodeType.

private Node generateNodeBasedOnNodeType(String nodeType, String attributes, String operation) {
    Node rootNode = null;
    if (nodeType != null && nodeType.equals("Expression")) {
        rootNode = new ExpressionNode();
        ((ExpressionNode) rootNode).setOperation(operation);
        ((ExpressionNode) rootNode).setAttributeValue("attributeValue");
        ((ExpressionNode) rootNode).setValue(attributes);
    } else if (nodeType != null && nodeType.equals("Operation")) {
        rootNode = new OperationNode("operation");
    }
    return rootNode;
}
Also used : OperationNode(org.wso2.charon3.core.utils.codeutils.OperationNode) ExpressionNode(org.wso2.charon3.core.utils.codeutils.ExpressionNode) OperationNode(org.wso2.charon3.core.utils.codeutils.OperationNode) ExpressionNode(org.wso2.charon3.core.utils.codeutils.ExpressionNode) Node(org.wso2.charon3.core.utils.codeutils.Node)

Example 3 with OperationNode

use of org.wso2.charon3.core.utils.codeutils.OperationNode in project identity-inbound-provisioning-scim2 by wso2-extensions.

the class SCIMUserManager method getCondition.

/**
 * Generate condition tree for given filters.
 *
 * @param node       Filter condition tree.
 * @param attributes User attributes.
 * @return Validated filter condition tree.
 * @throws CharonException
 */
private Condition getCondition(Node node, Map<String, String> attributes) throws CharonException {
    if (node instanceof ExpressionNode) {
        String operation = ((ExpressionNode) node).getOperation();
        String attributeName = ((ExpressionNode) node).getAttributeValue();
        String attributeValue = ((ExpressionNode) node).getValue();
        try {
            /* If primary login identifier feature is enabled, the username uri should be replaced with
                appropriate scim attribute of the primary login identifier claim. */
            if (SCIMConstants.UserSchemaConstants.USER_NAME_URI.equals(attributeName) && isLoginIdentifiersEnabled() && StringUtils.isNotBlank(getPrimaryLoginIdentifierClaim())) {
                attributeName = getScimUriForPrimaryLoginIdentifier(node);
            }
        } catch (org.wso2.carbon.user.core.UserStoreException e) {
            throw new CharonException("Error in retrieving scim to local mappings.", e);
        }
        String conditionOperation;
        String conditionAttributeName;
        if (SCIMCommonConstants.EQ.equals(operation)) {
            conditionOperation = ExpressionOperation.EQ.toString();
        } else if (SCIMCommonConstants.SW.equals(operation)) {
            conditionOperation = ExpressionOperation.SW.toString();
        } else if (SCIMCommonConstants.EW.equals(operation)) {
            conditionOperation = ExpressionOperation.EW.toString();
        } else if (SCIMCommonConstants.CO.equals(operation)) {
            conditionOperation = ExpressionOperation.CO.toString();
        } else if (SCIMCommonConstants.GE.equals(operation)) {
            conditionOperation = ExpressionOperation.GE.toString();
        } else if (SCIMCommonConstants.LE.equals(operation)) {
            conditionOperation = ExpressionOperation.LE.toString();
        } else {
            conditionOperation = operation;
        }
        if (SCIMConstants.UserSchemaConstants.GROUP_URI.equals(attributeName)) {
            conditionAttributeName = ExpressionAttribute.ROLE.toString();
        } else if (SCIMConstants.UserSchemaConstants.USER_NAME_URI.equals(attributeName)) {
            conditionAttributeName = ExpressionAttribute.USERNAME.toString();
        } else if (attributes != null && attributes.get(attributeName) != null) {
            conditionAttributeName = attributes.get(attributeName);
        } else {
            throw new CharonException("Unsupported attribute: " + attributeName);
        }
        return new ExpressionCondition(conditionOperation, conditionAttributeName, attributeValue);
    } else if (node instanceof OperationNode) {
        Condition leftCondition = getCondition(node.getLeftNode(), attributes);
        Condition rightCondition = getCondition(node.getRightNode(), attributes);
        String operation = ((OperationNode) node).getOperation();
        if (OperationalOperation.AND.toString().equalsIgnoreCase(operation)) {
            return new OperationalCondition(OperationalOperation.AND.toString(), leftCondition, rightCondition);
        } else {
            throw new CharonException("Unsupported Operation: " + operation);
        }
    } else {
        throw new CharonException("Unsupported Operation");
    }
}
Also used : ExpressionCondition(org.wso2.carbon.user.core.model.ExpressionCondition) OperationalCondition(org.wso2.carbon.user.core.model.OperationalCondition) ExpressionCondition(org.wso2.carbon.user.core.model.ExpressionCondition) Condition(org.wso2.carbon.user.core.model.Condition) OperationNode(org.wso2.charon3.core.utils.codeutils.OperationNode) OperationalCondition(org.wso2.carbon.user.core.model.OperationalCondition) ExpressionNode(org.wso2.charon3.core.utils.codeutils.ExpressionNode) CharonException(org.wso2.charon3.core.exceptions.CharonException)

Example 4 with OperationNode

use of org.wso2.charon3.core.utils.codeutils.OperationNode in project identity-api-server by wso2.

the class ServerAuthenticatorManagementService method validateFilter.

private void validateFilter(Node rootNode) {
    if (!(rootNode instanceof OperationNode)) {
        String attributeValue = ((ExpressionNode) rootNode).getAttributeValue();
        String operation = ((ExpressionNode) rootNode).getOperation();
        if (StringUtils.equalsIgnoreCase(attributeValue, Constants.FilterAttributes.NAME)) {
            if (StringUtils.equalsIgnoreCase(operation, Constants.FilterOperations.SW) || StringUtils.equalsIgnoreCase(operation, Constants.FilterOperations.EQ)) {
                return;
            } else {
                throw handleException(Response.Status.NOT_IMPLEMENTED, Constants.ErrorMessage.ERROR_CODE_UNSUPPORTED_FILTER_OPERATION_FOR_NAME, operation);
            }
        } else if (StringUtils.equalsIgnoreCase(attributeValue, Constants.FilterAttributes.TAG)) {
            if (StringUtils.equalsIgnoreCase(operation, Constants.FilterOperations.EQ)) {
                return;
            } else {
                throw handleException(Response.Status.NOT_IMPLEMENTED, Constants.ErrorMessage.ERROR_CODE_UNSUPPORTED_FILTER_OPERATION_FOR_TAG, operation);
            }
        } else {
            throw buildClientError(Constants.ErrorMessage.ERROR_CODE_UNSUPPORTED_FILTER_ATTRIBUTE, attributeValue);
        }
    }
    Node rootNodeLeftNode = rootNode.getLeftNode();
    Node rootNodeRightNode = rootNode.getRightNode();
    boolean nameFiltering = false;
    boolean tagAvailableInLeftNode = false;
    boolean tagAvailableInRightNode = false;
    if (rootNodeLeftNode instanceof ExpressionNode) {
        String attributeValue = ((ExpressionNode) rootNodeLeftNode).getAttributeValue();
        nameFiltering = attributeValue.equals(Constants.FilterAttributes.NAME);
        tagAvailableInLeftNode = attributeValue.equals(Constants.FilterAttributes.TAG);
        if (!(nameFiltering || tagAvailableInLeftNode)) {
            throw buildClientError(Constants.ErrorMessage.ERROR_CODE_UNSUPPORTED_FILTER_ATTRIBUTE, attributeValue);
        }
        String operation = ((ExpressionNode) rootNodeLeftNode).getOperation();
        if (nameFiltering && (!(StringUtils.equalsIgnoreCase(operation, Constants.FilterOperations.SW) || StringUtils.equalsIgnoreCase(operation, Constants.FilterOperations.EQ)))) {
            throw handleException(Response.Status.NOT_IMPLEMENTED, Constants.ErrorMessage.ERROR_CODE_UNSUPPORTED_FILTER_OPERATION_FOR_NAME, operation);
        }
        if (tagAvailableInLeftNode && !StringUtils.equalsIgnoreCase(operation, Constants.FilterOperations.EQ)) {
            throw handleException(Response.Status.NOT_IMPLEMENTED, Constants.ErrorMessage.ERROR_CODE_UNSUPPORTED_FILTER_OPERATION_FOR_TAG, operation);
        }
    } else {
        validateChildNode(rootNodeLeftNode);
    }
    if (rootNodeRightNode instanceof ExpressionNode) {
        String attributeValue = ((ExpressionNode) rootNodeRightNode).getAttributeValue();
        tagAvailableInRightNode = attributeValue.equals(Constants.FilterAttributes.TAG);
        boolean nameAvailableInRightNode = attributeValue.equals(Constants.FilterAttributes.NAME);
        if (!(tagAvailableInRightNode || nameAvailableInRightNode)) {
            throw buildClientError(Constants.ErrorMessage.ERROR_CODE_UNSUPPORTED_FILTER_ATTRIBUTE, attributeValue);
        }
        if (nameFiltering && nameAvailableInRightNode) {
            throw handleException(Response.Status.NOT_IMPLEMENTED, Constants.ErrorMessage.ERROR_CODE_UNSUPPORTED_FILTER_FOR_MULTIPLE_NAMES, null);
        }
        String operation = ((ExpressionNode) rootNodeRightNode).getOperation();
        if (!nameFiltering) {
            nameFiltering = nameAvailableInRightNode;
            if (nameFiltering && (!(StringUtils.equalsIgnoreCase(operation, Constants.FilterOperations.SW) || StringUtils.equalsIgnoreCase(operation, Constants.FilterOperations.EQ)))) {
                throw handleException(Response.Status.NOT_IMPLEMENTED, Constants.ErrorMessage.ERROR_CODE_UNSUPPORTED_FILTER_OPERATION_FOR_NAME, operation);
            }
        }
        if (tagAvailableInRightNode && !StringUtils.equalsIgnoreCase(operation, Constants.FilterOperations.EQ)) {
            throw handleException(Response.Status.NOT_IMPLEMENTED, Constants.ErrorMessage.ERROR_CODE_UNSUPPORTED_FILTER_OPERATION_FOR_TAG, operation);
        }
    } else {
        validateChildNode(rootNodeRightNode);
    }
    String operation = ((OperationNode) rootNode).getOperation();
    if (nameFiltering && !StringUtils.equalsIgnoreCase(operation, Constants.ComplexQueryOperations.AND)) {
        throw handleException(Response.Status.NOT_IMPLEMENTED, Constants.ErrorMessage.ERROR_CODE_UNSUPPORTED_COMPLEX_QUERY_OPERATION_FOR_NAME, operation);
    }
    if (tagAvailableInLeftNode && tagAvailableInRightNode && !StringUtils.equalsIgnoreCase(operation, Constants.ComplexQueryOperations.OR)) {
        throw handleException(Response.Status.NOT_IMPLEMENTED, Constants.ErrorMessage.ERROR_CODE_UNSUPPORTED_COMPLEX_QUERY_OPERATION_FOR_TAG, operation);
    }
}
Also used : OperationNode(org.wso2.carbon.identity.core.model.OperationNode) ExpressionNode(org.wso2.carbon.identity.core.model.ExpressionNode) OperationNode(org.wso2.carbon.identity.core.model.OperationNode) ExpressionNode(org.wso2.carbon.identity.core.model.ExpressionNode) Node(org.wso2.carbon.identity.core.model.Node)

Aggregations

ExpressionNode (org.wso2.charon3.core.utils.codeutils.ExpressionNode)2 OperationNode (org.wso2.charon3.core.utils.codeutils.OperationNode)2 IdentityException (org.wso2.carbon.identity.base.IdentityException)1 ExpressionNode (org.wso2.carbon.identity.core.model.ExpressionNode)1 Node (org.wso2.carbon.identity.core.model.Node)1 OperationNode (org.wso2.carbon.identity.core.model.OperationNode)1 Condition (org.wso2.carbon.user.core.model.Condition)1 ExpressionCondition (org.wso2.carbon.user.core.model.ExpressionCondition)1 OperationalCondition (org.wso2.carbon.user.core.model.OperationalCondition)1 CharonException (org.wso2.charon3.core.exceptions.CharonException)1 Node (org.wso2.charon3.core.utils.codeutils.Node)1