@Test public void testX500Name() { String regexp = new String(".*Duke.*"); X500Principal addr1 = null; X500Principal addr2 = null; try { addr1 = new X500Principal("CN=Duke, OU=JavaSoft, O=Sun Microsystems, C=US"); addr2 = new X500Principal("CN=Policy Engine, OU=Research, O=ATT, C=US"); } catch (Exception e) { fail("Unable to create X500Name, e="+e); } FunctionArgumentAttributeValue attrRegexp = null; FunctionArgumentAttributeValue attrAddr1 = null; FunctionArgumentAttributeValue attrAddr2 = null; FunctionArgumentAttributeValue attrInteger = null; try { attrRegexp = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(regexp)); attrAddr1 = new FunctionArgumentAttributeValue(DataTypes.DT_X500NAME.createAttributeValue(addr1)); attrAddr2 = new FunctionArgumentAttributeValue(DataTypes.DT_X500NAME.createAttributeValue(addr2)); attrInteger = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1234)); } catch (Exception e) { fail("creating attributes e="+ e); } FunctionDefinitionRegexpMatch<?> fd = (FunctionDefinitionRegexpMatch<?>) StdFunctions.FD_X500NAME_REGEXP_MATCH; assertEquals(XACML3.ID_FUNCTION_X500NAME_REGEXP_MATCH, fd.getId()); assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); assertFalse(fd.returnsBag()); arguments.clear(); arguments.add(attrRegexp); arguments.add(attrAddr1); ExpressionResult res = fd.evaluate(null, arguments); assertTrue(res.isOk()); assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); Boolean resValue = (Boolean)res.getValue().getValue(); assertEquals(true, resValue); arguments.clear(); arguments.add(attrRegexp); arguments.add(attrAddr2); res = fd.evaluate(null, arguments); assertTrue(res.isOk()); assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); resValue = (Boolean)res.getValue().getValue(); assertEquals(false, resValue); arguments.clear(); arguments.add(attrRegexp); arguments.add(attrInteger); res = fd.evaluate(null, arguments); assertFalse(res.isOk()); assertEquals("function:x500Name-regexp-match Expected data type 'x500Name' saw 'integer'", res.getStatus().getStatusMessage()); assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); }
@Override public ExpressionResult evaluate(EvaluationContext evaluationContext, 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()) )); } FunctionArgument regexpArgument = arguments.get(0); ConvertedArgument<String> convertedArgument = new ConvertedArgument<String>(regexpArgument, DataTypes.DT_STRING, false); if ( ! convertedArgument.isOk()) { return ExpressionResult.newError(getFunctionStatus(convertedArgument.getStatus())); } String regexpValue = convertedArgument.getValue(); FunctionArgument elementArgument = arguments.get(1); ConvertedArgument<I> convertedElement = new ConvertedArgument<I>(elementArgument, this.getDataTypeArgs(), false); if ( ! convertedElement.isOk()) { return ExpressionResult.newError(getFunctionStatus(convertedElement.getStatus())); } I elementValueObject = convertedElement.getValue(); String elementValueString; try { elementValueString = this.getDataTypeArgs().toStringValue(elementValueObject); } catch (DataTypeException 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)); } if (elementValueString.matches(regexpValue)) { return ER_TRUE; } else { return ER_FALSE; } }
FunctionDefinitionRegexpMatch extends FunctionDefinitionBase<Boolean, I> { @Override public ExpressionResult evaluate(EvaluationContext evaluationContext, 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()) )); } FunctionArgument regexpArgument = arguments.get(0); ConvertedArgument<String> convertedArgument = new ConvertedArgument<String>(regexpArgument, DataTypes.DT_STRING, false); if ( ! convertedArgument.isOk()) { return ExpressionResult.newError(getFunctionStatus(convertedArgument.getStatus())); } String regexpValue = convertedArgument.getValue(); FunctionArgument elementArgument = arguments.get(1); ConvertedArgument<I> convertedElement = new ConvertedArgument<I>(elementArgument, this.getDataTypeArgs(), false); if ( ! convertedElement.isOk()) { return ExpressionResult.newError(getFunctionStatus(convertedElement.getStatus())); } I elementValueObject = convertedElement.getValue(); String elementValueString; try { elementValueString = this.getDataTypeArgs().toStringValue(elementValueObject); } catch (DataTypeException 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)); } if (elementValueString.matches(regexpValue)) { return ER_TRUE; } else { return ER_FALSE; } } }
FunctionDefinitionRegexpMatch extends FunctionDefinitionBase<Boolean, I> { @Override public ExpressionResult evaluate(EvaluationContext evaluationContext, 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()) )); } FunctionArgument regexpArgument = arguments.get(0); ConvertedArgument<String> convertedArgument = new ConvertedArgument<String>(regexpArgument, DataTypes.DT_STRING, false); if ( ! convertedArgument.isOk()) { return ExpressionResult.newError(getFunctionStatus(convertedArgument.getStatus())); } String regexpValue = convertedArgument.getValue(); FunctionArgument elementArgument = arguments.get(1); ConvertedArgument<I> convertedElement = new ConvertedArgument<I>(elementArgument, this.getDataTypeArgs(), false); if ( ! convertedElement.isOk()) { return ExpressionResult.newError(getFunctionStatus(convertedElement.getStatus())); } I elementValueObject = convertedElement.getValue(); String elementValueString; try { elementValueString = this.getDataTypeArgs().toStringValue(elementValueObject); } catch (DataTypeException 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)); } if (elementValueString.matches(regexpValue)) { return ER_TRUE; } else { return ER_FALSE; } } FunctionDefinitionRegexpMatch(Identifier idIn, DataType<I> dataTypeArgsIn); }
FunctionDefinitionRegexpMatch extends FunctionDefinitionBase<Boolean, I> { @Override public ExpressionResult evaluate(EvaluationContext evaluationContext, 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()) )); } FunctionArgument regexpArgument = arguments.get(0); ConvertedArgument<String> convertedArgument = new ConvertedArgument<String>(regexpArgument, DataTypes.DT_STRING, false); if ( ! convertedArgument.isOk()) { return ExpressionResult.newError(getFunctionStatus(convertedArgument.getStatus())); } String regexpValue = convertedArgument.getValue(); FunctionArgument elementArgument = arguments.get(1); ConvertedArgument<I> convertedElement = new ConvertedArgument<I>(elementArgument, this.getDataTypeArgs(), false); if ( ! convertedElement.isOk()) { return ExpressionResult.newError(getFunctionStatus(convertedElement.getStatus())); } I elementValueObject = convertedElement.getValue(); String elementValueString; try { elementValueString = this.getDataTypeArgs().toStringValue(elementValueObject); } catch (DataTypeException 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)); } if (elementValueString.matches(regexpValue)) { return ER_TRUE; } else { return ER_FALSE; } } FunctionDefinitionRegexpMatch(Identifier idIn, DataType<I> dataTypeArgsIn); @Override ExpressionResult evaluate(EvaluationContext evaluationContext, List<FunctionArgument> arguments); }
FunctionDefinitionRegexpMatch extends FunctionDefinitionBase<Boolean, I> { @Override public ExpressionResult evaluate(EvaluationContext evaluationContext, 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()) )); } FunctionArgument regexpArgument = arguments.get(0); ConvertedArgument<String> convertedArgument = new ConvertedArgument<String>(regexpArgument, DataTypes.DT_STRING, false); if ( ! convertedArgument.isOk()) { return ExpressionResult.newError(getFunctionStatus(convertedArgument.getStatus())); } String regexpValue = convertedArgument.getValue(); FunctionArgument elementArgument = arguments.get(1); ConvertedArgument<I> convertedElement = new ConvertedArgument<I>(elementArgument, this.getDataTypeArgs(), false); if ( ! convertedElement.isOk()) { return ExpressionResult.newError(getFunctionStatus(convertedElement.getStatus())); } I elementValueObject = convertedElement.getValue(); String elementValueString; try { elementValueString = this.getDataTypeArgs().toStringValue(elementValueObject); } catch (DataTypeException 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)); } if (elementValueString.matches(regexpValue)) { return ER_TRUE; } else { return ER_FALSE; } } FunctionDefinitionRegexpMatch(Identifier idIn, DataType<I> dataTypeArgsIn); @Override ExpressionResult evaluate(EvaluationContext evaluationContext, List<FunctionArgument> arguments);  }