@SuppressWarnings("deprecation") @Test public void testURI_string_concatenate() { FunctionArgumentAttributeValue attrURI1 = null; FunctionArgumentAttributeValue attrStrAbc = null; FunctionArgumentAttributeValue attrStrSlashMno = null; FunctionArgumentAttributeValue attrStrSlashInMiddle = null; FunctionArgumentAttributeValue attrStrWithSpace = null; try { attrURI1 = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue("http: attrStrAbc = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("Abc")); attrStrSlashMno = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("/Mno")); attrStrSlashInMiddle = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("hij/pqr")); attrStrWithSpace = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("x y z")); } catch (Exception e) { fail("creating attributes e="+ e); } FunctionDefinitionURIStringConcatenate fd = (FunctionDefinitionURIStringConcatenate) StdFunctions.FD_URI_STRING_CONCATENATE; assertEquals(XACML2.ID_FUNCTION_URI_STRING_CONCATENATE, fd.getId()); assertEquals(DataTypes.DT_ANYURI.getId(), fd.getDataTypeId()); assertFalse(fd.returnsBag()); arguments.clear(); arguments.add(attrURI1); arguments.add(attrStrAbc); ExpressionResult res = fd.evaluate(null, arguments); assertTrue(res.isOk()); assertEquals(java.net.URI.class, res.getValue().getValue().getClass()); URI resValue = (URI)res.getValue().getValue(); assertEquals("http: arguments.clear(); arguments.add(attrURI1); arguments.add(attrStrAbc); arguments.add(attrStrSlashMno); res = fd.evaluate(null, arguments); assertTrue(res.isOk()); assertEquals(java.net.URI.class, res.getValue().getValue().getClass()); resValue = (URI)res.getValue().getValue(); assertEquals("http: arguments.clear(); arguments.add(attrURI1); arguments.add(attrStrSlashInMiddle); arguments.add(attrStrSlashMno); res = fd.evaluate(null, arguments); assertTrue(res.isOk()); assertEquals(java.net.URI.class, res.getValue().getValue().getClass()); resValue = (URI)res.getValue().getValue(); assertEquals("http: arguments.clear(); arguments.add(attrURI1); arguments.add(attrStrWithSpace); arguments.add(attrStrSlashMno); res = fd.evaluate(null, arguments); assertFalse(res.isOk()); assertEquals("function:uri-string-concatenate Final string 'http: assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); arguments.clear(); res = fd.evaluate(null, arguments); assertFalse(res.isOk()); assertEquals("function:uri-string-concatenate Expected 2 or more arguments, got 0", res.getStatus().getStatusMessage()); assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); arguments.clear(); arguments.add(attrURI1); res = fd.evaluate(null, arguments); assertFalse(res.isOk()); assertEquals("function:uri-string-concatenate Expected 2 or more arguments, got 1", res.getStatus().getStatusMessage()); assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); arguments.clear(); arguments.add(attrStrAbc); arguments.add(attrURI1); res = fd.evaluate(null, arguments); assertFalse(res.isOk()); assertEquals("function:uri-string-concatenate Expected data type 'anyURI' saw 'string' at arg index 0", res.getStatus().getStatusMessage()); assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); arguments.clear(); arguments.add(attrURI1); arguments.add(attrURI1); res = fd.evaluate(null, arguments); assertFalse(res.isOk()); assertEquals("function:uri-string-concatenate Expected data type 'string' saw 'anyURI' at arg index 1", 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, getShortFunctionId() + " Expected 2 or more arguments, got " + ((arguments == null) ? "null" : arguments.size()) )); } ConvertedArgument<URI> uriArgument = new ConvertedArgument<URI>(arguments.get(0), DataTypes.DT_ANYURI, false); if ( ! uriArgument.isOk()) { Status decoratedStatus = new StdStatus(uriArgument.getStatus().getStatusCode(), uriArgument.getStatus().getStatusMessage() + " at arg index 0" ); return ExpressionResult.newError(getFunctionStatus(decoratedStatus)); } String uriString = uriArgument.getValue().toString(); String[] stringValues = new String[arguments.size() - 1]; for (int i = 1; i < arguments.size(); i++) { ConvertedArgument<String> stringArgument = new ConvertedArgument<String>(arguments.get(i), DataTypes.DT_STRING, false); if ( ! stringArgument.isOk()) { Status decoratedStatus = new StdStatus(stringArgument.getStatus().getStatusCode(), stringArgument.getStatus().getStatusMessage() + " at arg index " + i ); return ExpressionResult.newError(getFunctionStatus(decoratedStatus)); } stringValues[i-1] = stringArgument.getValue(); } for (int i = 0; i < stringValues.length; i++) { uriString += stringValues[i]; } URI resultURI = null; try { resultURI = DataTypes.DT_ANYURI.convert(uriString); } catch (DataTypeException e) { String message = e.getMessage(); if (e.getCause() != null) { message = e.getCause().getMessage(); } return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_SYNTAX_ERROR, getShortFunctionId() + " Final string '" + uriString + "' not URI, " + message)); } return ExpressionResult.newSingle(new StdAttributeValue<URI>(XACML.ID_DATATYPE_ANYURI, resultURI)); }
FunctionDefinitionURIStringConcatenate extends FunctionDefinitionBase<URI, URI> { @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, getShortFunctionId() + " Expected 2 or more arguments, got " + ((arguments == null) ? "null" : arguments.size()) )); } ConvertedArgument<URI> uriArgument = new ConvertedArgument<URI>(arguments.get(0), DataTypes.DT_ANYURI, false); if ( ! uriArgument.isOk()) { Status decoratedStatus = new StdStatus(uriArgument.getStatus().getStatusCode(), uriArgument.getStatus().getStatusMessage() + " at arg index 0" ); return ExpressionResult.newError(getFunctionStatus(decoratedStatus)); } String uriString = uriArgument.getValue().toString(); String[] stringValues = new String[arguments.size() - 1]; for (int i = 1; i < arguments.size(); i++) { ConvertedArgument<String> stringArgument = new ConvertedArgument<String>(arguments.get(i), DataTypes.DT_STRING, false); if ( ! stringArgument.isOk()) { Status decoratedStatus = new StdStatus(stringArgument.getStatus().getStatusCode(), stringArgument.getStatus().getStatusMessage() + " at arg index " + i ); return ExpressionResult.newError(getFunctionStatus(decoratedStatus)); } stringValues[i-1] = stringArgument.getValue(); } for (int i = 0; i < stringValues.length; i++) { uriString += stringValues[i]; } URI resultURI = null; try { resultURI = DataTypes.DT_ANYURI.convert(uriString); } catch (DataTypeException e) { String message = e.getMessage(); if (e.getCause() != null) { message = e.getCause().getMessage(); } return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_SYNTAX_ERROR, getShortFunctionId() + " Final string '" + uriString + "' not URI, " + message)); } return ExpressionResult.newSingle(new StdAttributeValue<URI>(XACML.ID_DATATYPE_ANYURI, resultURI)); } }
FunctionDefinitionURIStringConcatenate extends FunctionDefinitionBase<URI, URI> { @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, getShortFunctionId() + " Expected 2 or more arguments, got " + ((arguments == null) ? "null" : arguments.size()) )); } ConvertedArgument<URI> uriArgument = new ConvertedArgument<URI>(arguments.get(0), DataTypes.DT_ANYURI, false); if ( ! uriArgument.isOk()) { Status decoratedStatus = new StdStatus(uriArgument.getStatus().getStatusCode(), uriArgument.getStatus().getStatusMessage() + " at arg index 0" ); return ExpressionResult.newError(getFunctionStatus(decoratedStatus)); } String uriString = uriArgument.getValue().toString(); String[] stringValues = new String[arguments.size() - 1]; for (int i = 1; i < arguments.size(); i++) { ConvertedArgument<String> stringArgument = new ConvertedArgument<String>(arguments.get(i), DataTypes.DT_STRING, false); if ( ! stringArgument.isOk()) { Status decoratedStatus = new StdStatus(stringArgument.getStatus().getStatusCode(), stringArgument.getStatus().getStatusMessage() + " at arg index " + i ); return ExpressionResult.newError(getFunctionStatus(decoratedStatus)); } stringValues[i-1] = stringArgument.getValue(); } for (int i = 0; i < stringValues.length; i++) { uriString += stringValues[i]; } URI resultURI = null; try { resultURI = DataTypes.DT_ANYURI.convert(uriString); } catch (DataTypeException e) { String message = e.getMessage(); if (e.getCause() != null) { message = e.getCause().getMessage(); } return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_SYNTAX_ERROR, getShortFunctionId() + " Final string '" + uriString + "' not URI, " + message)); } return ExpressionResult.newSingle(new StdAttributeValue<URI>(XACML.ID_DATATYPE_ANYURI, resultURI)); } FunctionDefinitionURIStringConcatenate(Identifier idIn); }
FunctionDefinitionURIStringConcatenate extends FunctionDefinitionBase<URI, URI> { @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, getShortFunctionId() + " Expected 2 or more arguments, got " + ((arguments == null) ? "null" : arguments.size()) )); } ConvertedArgument<URI> uriArgument = new ConvertedArgument<URI>(arguments.get(0), DataTypes.DT_ANYURI, false); if ( ! uriArgument.isOk()) { Status decoratedStatus = new StdStatus(uriArgument.getStatus().getStatusCode(), uriArgument.getStatus().getStatusMessage() + " at arg index 0" ); return ExpressionResult.newError(getFunctionStatus(decoratedStatus)); } String uriString = uriArgument.getValue().toString(); String[] stringValues = new String[arguments.size() - 1]; for (int i = 1; i < arguments.size(); i++) { ConvertedArgument<String> stringArgument = new ConvertedArgument<String>(arguments.get(i), DataTypes.DT_STRING, false); if ( ! stringArgument.isOk()) { Status decoratedStatus = new StdStatus(stringArgument.getStatus().getStatusCode(), stringArgument.getStatus().getStatusMessage() + " at arg index " + i ); return ExpressionResult.newError(getFunctionStatus(decoratedStatus)); } stringValues[i-1] = stringArgument.getValue(); } for (int i = 0; i < stringValues.length; i++) { uriString += stringValues[i]; } URI resultURI = null; try { resultURI = DataTypes.DT_ANYURI.convert(uriString); } catch (DataTypeException e) { String message = e.getMessage(); if (e.getCause() != null) { message = e.getCause().getMessage(); } return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_SYNTAX_ERROR, getShortFunctionId() + " Final string '" + uriString + "' not URI, " + message)); } return ExpressionResult.newSingle(new StdAttributeValue<URI>(XACML.ID_DATATYPE_ANYURI, resultURI)); } FunctionDefinitionURIStringConcatenate(Identifier idIn); @Override ExpressionResult evaluate(EvaluationContext evaluationContext, List<FunctionArgument> arguments); }
FunctionDefinitionURIStringConcatenate extends FunctionDefinitionBase<URI, URI> { @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, getShortFunctionId() + " Expected 2 or more arguments, got " + ((arguments == null) ? "null" : arguments.size()) )); } ConvertedArgument<URI> uriArgument = new ConvertedArgument<URI>(arguments.get(0), DataTypes.DT_ANYURI, false); if ( ! uriArgument.isOk()) { Status decoratedStatus = new StdStatus(uriArgument.getStatus().getStatusCode(), uriArgument.getStatus().getStatusMessage() + " at arg index 0" ); return ExpressionResult.newError(getFunctionStatus(decoratedStatus)); } String uriString = uriArgument.getValue().toString(); String[] stringValues = new String[arguments.size() - 1]; for (int i = 1; i < arguments.size(); i++) { ConvertedArgument<String> stringArgument = new ConvertedArgument<String>(arguments.get(i), DataTypes.DT_STRING, false); if ( ! stringArgument.isOk()) { Status decoratedStatus = new StdStatus(stringArgument.getStatus().getStatusCode(), stringArgument.getStatus().getStatusMessage() + " at arg index " + i ); return ExpressionResult.newError(getFunctionStatus(decoratedStatus)); } stringValues[i-1] = stringArgument.getValue(); } for (int i = 0; i < stringValues.length; i++) { uriString += stringValues[i]; } URI resultURI = null; try { resultURI = DataTypes.DT_ANYURI.convert(uriString); } catch (DataTypeException e) { String message = e.getMessage(); if (e.getCause() != null) { message = e.getCause().getMessage(); } return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_SYNTAX_ERROR, getShortFunctionId() + " Final string '" + uriString + "' not URI, " + message)); } return ExpressionResult.newSingle(new StdAttributeValue<URI>(XACML.ID_DATATYPE_ANYURI, resultURI)); } FunctionDefinitionURIStringConcatenate(Identifier idIn); @Override ExpressionResult evaluate(EvaluationContext evaluationContext, List<FunctionArgument> arguments);  }