@Test public final void testRegexp() { final String testVal = "testVal,testVal2"; final String testId = "function:testId"; final IdentifierImpl testFnId = new IdentifierImpl(testId); final Identifier identifier = XACML.ID_DATATYPE_STRING; final StdAttributeValue<String> attValue = new StdAttributeValue<String>(identifier, testVal); final FunctionArgument fArg = new FunctionArgumentAttributeValue(attValue); final List<FunctionArgument> listFa = new ArrayList<FunctionArgument>(); listFa.add(fArg); listFa.add(fArg); final FunctionDefinitionCustomRegexpMatch<String> regexpMatch = new FunctionDefinitionCustomRegexpMatch<String>(testFnId, DataTypes.DT_STRING); final ExpressionResult result = regexpMatch.evaluate(null, listFa); assertEquals(true, result.getValue().getValue()); assertEquals(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, regexpMatch.evaluate(null, null).getStatus().getStatusCode()); final Identifier identifier2 = XACML.ID_DATATYPE_BOOLEAN; final StdAttributeValue<String> attValue2 = new StdAttributeValue<String>(identifier2, testVal); final FunctionArgument fArg2 = new FunctionArgumentAttributeValue(attValue2); final List<FunctionArgument> listFa2 = new ArrayList<FunctionArgument>(); listFa2.add(fArg2); listFa2.add(fArg2); assertEquals(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, regexpMatch.evaluate(null, listFa2).getStatus().getStatusCode()); final List<FunctionArgument> listFa3 = new ArrayList<FunctionArgument>(); listFa3.add(fArg); listFa3.add(fArg2); assertEquals(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, regexpMatch.evaluate(null, listFa3).getStatus().getStatusCode()); final String testVal4 = "testVal3"; final StdAttributeValue<String> attValue4 = new StdAttributeValue<String>(identifier, testVal4); final FunctionArgument fArg4 = new FunctionArgumentAttributeValue(attValue4); final List<FunctionArgument> listFa4 = new ArrayList<FunctionArgument>(); listFa4.add(fArg); listFa4.add(fArg4); assertEquals(false, regexpMatch.evaluate(null, listFa4).getValue().getValue()); final String testVal5 = "testVal2"; final StdAttributeValue<String> attValue5 = new StdAttributeValue<String>(identifier, testVal5); final FunctionArgument fArg5 = new FunctionArgumentAttributeValue(attValue5); final List<FunctionArgument> listFa5 = new ArrayList<FunctionArgument>(); listFa5.add(fArg); listFa5.add(fArg5); assertEquals(true, regexpMatch.evaluate(null, listFa5).getValue().getValue()); }
@Override public ExpressionResult evaluate(final EvaluationContext evaluationContext, final List<FunctionArgument> arguments) { if (arguments == null || arguments.size() != 2) { return ExpressionResult .newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, this.getShortFunctionId() + " Expected 2 arguments, got " + ((arguments == null) ? "null" : arguments.size()))); } final FunctionArgument regexpArgument = arguments.get(0); final ConvertedArgument<String> convertedArgument = new ConvertedArgument<>(regexpArgument, DataTypes.DT_STRING, false); if (!convertedArgument.isOk()) { return ExpressionResult.newError(getFunctionStatus(convertedArgument.getStatus())); } String regexpValue = convertedArgument.getValue(); final FunctionArgument elementArgument = arguments.get(1); final ConvertedArgument<I> convertedElement = new ConvertedArgument<>(elementArgument, this.getDataTypeArgs(), false); if (!convertedElement.isOk()) { return ExpressionResult.newError(getFunctionStatus(convertedElement.getStatus())); } final I elementValueObject = convertedElement.getValue(); String elementValueString; try { elementValueString = this.getDataTypeArgs().toStringValue(elementValueObject); } catch (final DataTypeException e) { logger.error(e.getMessage() + e); String message = e.getMessage(); if (e.getCause() != null) { message = e.getCause().getMessage(); } return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, this.getShortFunctionId() + " " + message)); } elementValueString = elementValueString + regexpValue; regexpValue = elementValueString.substring(0, (elementValueString.length() - regexpValue.length())); elementValueString = elementValueString.substring(regexpValue.length(), (elementValueString.length())); if (elementValueString.contains(",")) { final String[] elements = elementValueString.split(","); for (int i = 0; i < elements.length; i++) { if (elements[i].trim().matches(regexpValue)) { return ER_TRUE; } } } if (elementValueString.matches(regexpValue)) { return ER_TRUE; } else { return ER_FALSE; } }
FunctionDefinitionCustomRegexpMatch extends FunctionDefinitionBase<Boolean, I> { @Override public ExpressionResult evaluate(final EvaluationContext evaluationContext, final List<FunctionArgument> arguments) { if (arguments == null || arguments.size() != 2) { return ExpressionResult .newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, this.getShortFunctionId() + " Expected 2 arguments, got " + ((arguments == null) ? "null" : arguments.size()))); } final FunctionArgument regexpArgument = arguments.get(0); final ConvertedArgument<String> convertedArgument = new ConvertedArgument<>(regexpArgument, DataTypes.DT_STRING, false); if (!convertedArgument.isOk()) { return ExpressionResult.newError(getFunctionStatus(convertedArgument.getStatus())); } String regexpValue = convertedArgument.getValue(); final FunctionArgument elementArgument = arguments.get(1); final ConvertedArgument<I> convertedElement = new ConvertedArgument<>(elementArgument, this.getDataTypeArgs(), false); if (!convertedElement.isOk()) { return ExpressionResult.newError(getFunctionStatus(convertedElement.getStatus())); } final I elementValueObject = convertedElement.getValue(); String elementValueString; try { elementValueString = this.getDataTypeArgs().toStringValue(elementValueObject); } catch (final DataTypeException e) { logger.error(e.getMessage() + e); String message = e.getMessage(); if (e.getCause() != null) { message = e.getCause().getMessage(); } return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, this.getShortFunctionId() + " " + message)); } elementValueString = elementValueString + regexpValue; regexpValue = elementValueString.substring(0, (elementValueString.length() - regexpValue.length())); elementValueString = elementValueString.substring(regexpValue.length(), (elementValueString.length())); if (elementValueString.contains(",")) { final String[] elements = elementValueString.split(","); for (int i = 0; i < elements.length; i++) { if (elements[i].trim().matches(regexpValue)) { return ER_TRUE; } } } if (elementValueString.matches(regexpValue)) { return ER_TRUE; } else { return ER_FALSE; } } }
FunctionDefinitionCustomRegexpMatch extends FunctionDefinitionBase<Boolean, I> { @Override public ExpressionResult evaluate(final EvaluationContext evaluationContext, final List<FunctionArgument> arguments) { if (arguments == null || arguments.size() != 2) { return ExpressionResult .newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, this.getShortFunctionId() + " Expected 2 arguments, got " + ((arguments == null) ? "null" : arguments.size()))); } final FunctionArgument regexpArgument = arguments.get(0); final ConvertedArgument<String> convertedArgument = new ConvertedArgument<>(regexpArgument, DataTypes.DT_STRING, false); if (!convertedArgument.isOk()) { return ExpressionResult.newError(getFunctionStatus(convertedArgument.getStatus())); } String regexpValue = convertedArgument.getValue(); final FunctionArgument elementArgument = arguments.get(1); final ConvertedArgument<I> convertedElement = new ConvertedArgument<>(elementArgument, this.getDataTypeArgs(), false); if (!convertedElement.isOk()) { return ExpressionResult.newError(getFunctionStatus(convertedElement.getStatus())); } final I elementValueObject = convertedElement.getValue(); String elementValueString; try { elementValueString = this.getDataTypeArgs().toStringValue(elementValueObject); } catch (final DataTypeException e) { logger.error(e.getMessage() + e); String message = e.getMessage(); if (e.getCause() != null) { message = e.getCause().getMessage(); } return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, this.getShortFunctionId() + " " + message)); } elementValueString = elementValueString + regexpValue; regexpValue = elementValueString.substring(0, (elementValueString.length() - regexpValue.length())); elementValueString = elementValueString.substring(regexpValue.length(), (elementValueString.length())); if (elementValueString.contains(",")) { final String[] elements = elementValueString.split(","); for (int i = 0; i < elements.length; i++) { if (elements[i].trim().matches(regexpValue)) { return ER_TRUE; } } } if (elementValueString.matches(regexpValue)) { return ER_TRUE; } else { return ER_FALSE; } } FunctionDefinitionCustomRegexpMatch(final Identifier idIn, final DataType<I> dataTypeArgsIn); }
FunctionDefinitionCustomRegexpMatch extends FunctionDefinitionBase<Boolean, I> { @Override public ExpressionResult evaluate(final EvaluationContext evaluationContext, final List<FunctionArgument> arguments) { if (arguments == null || arguments.size() != 2) { return ExpressionResult .newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, this.getShortFunctionId() + " Expected 2 arguments, got " + ((arguments == null) ? "null" : arguments.size()))); } final FunctionArgument regexpArgument = arguments.get(0); final ConvertedArgument<String> convertedArgument = new ConvertedArgument<>(regexpArgument, DataTypes.DT_STRING, false); if (!convertedArgument.isOk()) { return ExpressionResult.newError(getFunctionStatus(convertedArgument.getStatus())); } String regexpValue = convertedArgument.getValue(); final FunctionArgument elementArgument = arguments.get(1); final ConvertedArgument<I> convertedElement = new ConvertedArgument<>(elementArgument, this.getDataTypeArgs(), false); if (!convertedElement.isOk()) { return ExpressionResult.newError(getFunctionStatus(convertedElement.getStatus())); } final I elementValueObject = convertedElement.getValue(); String elementValueString; try { elementValueString = this.getDataTypeArgs().toStringValue(elementValueObject); } catch (final DataTypeException e) { logger.error(e.getMessage() + e); String message = e.getMessage(); if (e.getCause() != null) { message = e.getCause().getMessage(); } return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, this.getShortFunctionId() + " " + message)); } elementValueString = elementValueString + regexpValue; regexpValue = elementValueString.substring(0, (elementValueString.length() - regexpValue.length())); elementValueString = elementValueString.substring(regexpValue.length(), (elementValueString.length())); if (elementValueString.contains(",")) { final String[] elements = elementValueString.split(","); for (int i = 0; i < elements.length; i++) { if (elements[i].trim().matches(regexpValue)) { return ER_TRUE; } } } if (elementValueString.matches(regexpValue)) { return ER_TRUE; } else { return ER_FALSE; } } FunctionDefinitionCustomRegexpMatch(final Identifier idIn, final DataType<I> dataTypeArgsIn); @Override ExpressionResult evaluate(final EvaluationContext evaluationContext,
            final List<FunctionArgument> arguments); }
FunctionDefinitionCustomRegexpMatch extends FunctionDefinitionBase<Boolean, I> { @Override public ExpressionResult evaluate(final EvaluationContext evaluationContext, final List<FunctionArgument> arguments) { if (arguments == null || arguments.size() != 2) { return ExpressionResult .newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, this.getShortFunctionId() + " Expected 2 arguments, got " + ((arguments == null) ? "null" : arguments.size()))); } final FunctionArgument regexpArgument = arguments.get(0); final ConvertedArgument<String> convertedArgument = new ConvertedArgument<>(regexpArgument, DataTypes.DT_STRING, false); if (!convertedArgument.isOk()) { return ExpressionResult.newError(getFunctionStatus(convertedArgument.getStatus())); } String regexpValue = convertedArgument.getValue(); final FunctionArgument elementArgument = arguments.get(1); final ConvertedArgument<I> convertedElement = new ConvertedArgument<>(elementArgument, this.getDataTypeArgs(), false); if (!convertedElement.isOk()) { return ExpressionResult.newError(getFunctionStatus(convertedElement.getStatus())); } final I elementValueObject = convertedElement.getValue(); String elementValueString; try { elementValueString = this.getDataTypeArgs().toStringValue(elementValueObject); } catch (final DataTypeException e) { logger.error(e.getMessage() + e); String message = e.getMessage(); if (e.getCause() != null) { message = e.getCause().getMessage(); } return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, this.getShortFunctionId() + " " + message)); } elementValueString = elementValueString + regexpValue; regexpValue = elementValueString.substring(0, (elementValueString.length() - regexpValue.length())); elementValueString = elementValueString.substring(regexpValue.length(), (elementValueString.length())); if (elementValueString.contains(",")) { final String[] elements = elementValueString.split(","); for (int i = 0; i < elements.length; i++) { if (elements[i].trim().matches(regexpValue)) { return ER_TRUE; } } } if (elementValueString.matches(regexpValue)) { return ER_TRUE; } else { return ER_FALSE; } } FunctionDefinitionCustomRegexpMatch(final Identifier idIn, final DataType<I> dataTypeArgsIn); @Override ExpressionResult evaluate(final EvaluationContext evaluationContext,
            final List<FunctionArgument> arguments);  }