@Ignore @Test public void testAccess_permitted() { ExpressionResult res = null; Boolean resValue = null; FunctionDefinitionAccessPermitted fd = (FunctionDefinitionAccessPermitted) StdFunctions.FD_ACCESS_PERMITTED; assertEquals(XACML3.ID_FUNCTION_ACCESS_PERMITTED, fd.getId()); assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); assertFalse(fd.returnsBag()); arguments.clear(); arguments.add(attrUriResources); arguments.add(attrXEmpty); res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); assertTrue(res.isOk()); resValue = (Boolean)res.getValue().getValue(); assertTrue(resValue); arguments.clear(); arguments.add(attrUriResources); arguments.add(attrXContentSpringer); res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); assertTrue(res.isOk()); resValue = (Boolean)res.getValue().getValue(); assertTrue(resValue); arguments.clear(); arguments.add(attrUriResources); arguments.add(attrXSpringer); res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); assertTrue(res.isOk()); resValue = (Boolean)res.getValue().getValue(); assertTrue(resValue); arguments.clear(); arguments.add(attrUriResources); arguments.add(attrXBadXML); res = fd.evaluate(null, arguments); assertFalse(res.getStatus().isOk()); assertEquals( "function:access-permitted Parsing of XML string failed. Cause='The element type \"md:hospital_info\" must be terminated by the matching end-tag \"</md:hospital_info>\".'", res.getStatus().getStatusMessage()); assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); arguments.clear(); arguments.add(attrUriNotCategory); arguments.add(attrXContentSimpson); res = fd.evaluate(null, arguments); assertFalse(res.getStatus().isOk()); assertEquals( "function:access-permitted First argument must be a urn for an attribute-category, not 'urn:oasis:names:tc:xacml:1.0:resource:resource-id", res.getStatus().getStatusMessage()); assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); arguments.clear(); arguments.add(attrUriAction); arguments.add(attrXContentSimpson); res = fd.evaluate(new StdEvaluationContext(null, null, null), arguments); assertFalse(res.getStatus().isOk()); assertEquals( "function:access-permitted Got null Request in EvaluationContext", res.getStatus().getStatusMessage()); assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); arguments.clear(); arguments.add(attrUriNotCategory); arguments.add(attrXContentSimpson); res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); assertFalse(res.getStatus().isOk()); assertEquals( "function:access-permitted First argument must be a urn for an attribute-category, not 'urn:oasis:names:tc:xacml:1.0:resource:resource-id", res.getStatus().getStatusMessage()); assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); arguments.clear(); arguments.add(attrXContentSimpson); arguments.add(attrXContentSimpson); res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); assertFalse(res.getStatus().isOk()); assertEquals( "function:access-permitted Expected data type 'anyURI' saw 'string'", res.getStatus().getStatusMessage()); assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); arguments.clear(); arguments.add(attrUriAction); arguments.add(attrUriAction); res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); assertFalse(res.getStatus().isOk()); assertEquals( "function:access-permitted Expected data type 'string' saw 'anyURI'", res.getStatus().getStatusMessage()); assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); arguments.clear(); res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); assertFalse(res.getStatus().isOk()); assertEquals( "function:access-permitted Expected 2 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(attrXContentSimpson); res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); assertFalse(res.getStatus().isOk()); assertEquals( "function:access-permitted Expected 2 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(attrUriEmpty); arguments.add(attrXContentSimpson); arguments.add(attrXContentSimpson); res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); assertFalse(res.getStatus().isOk()); assertEquals( "function:access-permitted Expected 2 arguments, got 3", 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 functionArgument = arguments.get(0); ConvertedArgument<URI> convertedArgument0 = new ConvertedArgument<URI>(functionArgument, DataTypes.DT_ANYURI, false); if ( ! convertedArgument0.isOk()) { return ExpressionResult.newError(getFunctionStatus(convertedArgument0.getStatus())); } URI attributesURI = convertedArgument0.getValue(); if ( ! attributesURI.toString().startsWith("urn:") || ! attributesURI.toString().contains(":attribute-category:")) { return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_SYNTAX_ERROR, this.getShortFunctionId() + " First argument must be a urn for an attribute-category, not '" + attributesURI.toString() )); } functionArgument = arguments.get(1); ConvertedArgument<String> convertedArgument1 = new ConvertedArgument<String>(functionArgument, DataTypes.DT_STRING, false); if ( ! convertedArgument1.isOk()) { return ExpressionResult.newError(getFunctionStatus(convertedArgument1.getStatus())); } String xmlContent = convertedArgument1.getValue(); if ( ! xmlContent.trim().toLowerCase().startsWith("<content>") ) { xmlContent = "<Content>" + xmlContent + "</Content>"; } Node newContentNode = null; try (InputStream is = new ByteArrayInputStream(xmlContent.getBytes())) { DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); docBuilderFactory.setNamespaceAware(true); newContentNode = docBuilderFactory .newDocumentBuilder() .parse(is) .getDocumentElement(); } catch (Exception e) { String message = e.getMessage(); if (e.getCause() != null) { message = e.getCause().getMessage(); } return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_SYNTAX_ERROR, this.getShortFunctionId() + " Parsing of XML string failed. Cause='" + message + "'" )); } @SuppressWarnings("unused") RequestAttributes newRequestAttributes = null; try { newRequestAttributes = DOMRequestAttributes.newInstance(newContentNode); } catch (DOMStructureException e) { String message = e.getMessage(); if (e.getCause() != null) { message = e.getCause().getMessage(); } return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_SYNTAX_ERROR, this.getShortFunctionId() + " Conversion of XML to RequestAttributes failed. Cause='" + message + "'" )); } if (evaluationContext == null) { return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, this.getShortFunctionId() + " Got null EvaluationContext")); } if (evaluationContext.getRequest() == null) { return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, this.getShortFunctionId() + " Got null Request in EvaluationContext")); } Request originalRequest = evaluationContext.getRequest(); @SuppressWarnings("unused") Request newRequest = new StdRequest(originalRequest); return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, this.getShortFunctionId() + " Not Implemented")); }
FunctionDefinitionAccessPermitted extends FunctionDefinitionBase<Boolean, 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, this.getShortFunctionId() + " Expected 2 arguments, got " + ((arguments == null) ? "null" : arguments.size()) )); } FunctionArgument functionArgument = arguments.get(0); ConvertedArgument<URI> convertedArgument0 = new ConvertedArgument<URI>(functionArgument, DataTypes.DT_ANYURI, false); if ( ! convertedArgument0.isOk()) { return ExpressionResult.newError(getFunctionStatus(convertedArgument0.getStatus())); } URI attributesURI = convertedArgument0.getValue(); if ( ! attributesURI.toString().startsWith("urn:") || ! attributesURI.toString().contains(":attribute-category:")) { return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_SYNTAX_ERROR, this.getShortFunctionId() + " First argument must be a urn for an attribute-category, not '" + attributesURI.toString() )); } functionArgument = arguments.get(1); ConvertedArgument<String> convertedArgument1 = new ConvertedArgument<String>(functionArgument, DataTypes.DT_STRING, false); if ( ! convertedArgument1.isOk()) { return ExpressionResult.newError(getFunctionStatus(convertedArgument1.getStatus())); } String xmlContent = convertedArgument1.getValue(); if ( ! xmlContent.trim().toLowerCase().startsWith("<content>") ) { xmlContent = "<Content>" + xmlContent + "</Content>"; } Node newContentNode = null; try (InputStream is = new ByteArrayInputStream(xmlContent.getBytes())) { DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); docBuilderFactory.setNamespaceAware(true); newContentNode = docBuilderFactory .newDocumentBuilder() .parse(is) .getDocumentElement(); } catch (Exception e) { String message = e.getMessage(); if (e.getCause() != null) { message = e.getCause().getMessage(); } return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_SYNTAX_ERROR, this.getShortFunctionId() + " Parsing of XML string failed. Cause='" + message + "'" )); } @SuppressWarnings("unused") RequestAttributes newRequestAttributes = null; try { newRequestAttributes = DOMRequestAttributes.newInstance(newContentNode); } catch (DOMStructureException e) { String message = e.getMessage(); if (e.getCause() != null) { message = e.getCause().getMessage(); } return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_SYNTAX_ERROR, this.getShortFunctionId() + " Conversion of XML to RequestAttributes failed. Cause='" + message + "'" )); } if (evaluationContext == null) { return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, this.getShortFunctionId() + " Got null EvaluationContext")); } if (evaluationContext.getRequest() == null) { return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, this.getShortFunctionId() + " Got null Request in EvaluationContext")); } Request originalRequest = evaluationContext.getRequest(); @SuppressWarnings("unused") Request newRequest = new StdRequest(originalRequest); return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, this.getShortFunctionId() + " Not Implemented")); } }
FunctionDefinitionAccessPermitted extends FunctionDefinitionBase<Boolean, 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, this.getShortFunctionId() + " Expected 2 arguments, got " + ((arguments == null) ? "null" : arguments.size()) )); } FunctionArgument functionArgument = arguments.get(0); ConvertedArgument<URI> convertedArgument0 = new ConvertedArgument<URI>(functionArgument, DataTypes.DT_ANYURI, false); if ( ! convertedArgument0.isOk()) { return ExpressionResult.newError(getFunctionStatus(convertedArgument0.getStatus())); } URI attributesURI = convertedArgument0.getValue(); if ( ! attributesURI.toString().startsWith("urn:") || ! attributesURI.toString().contains(":attribute-category:")) { return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_SYNTAX_ERROR, this.getShortFunctionId() + " First argument must be a urn for an attribute-category, not '" + attributesURI.toString() )); } functionArgument = arguments.get(1); ConvertedArgument<String> convertedArgument1 = new ConvertedArgument<String>(functionArgument, DataTypes.DT_STRING, false); if ( ! convertedArgument1.isOk()) { return ExpressionResult.newError(getFunctionStatus(convertedArgument1.getStatus())); } String xmlContent = convertedArgument1.getValue(); if ( ! xmlContent.trim().toLowerCase().startsWith("<content>") ) { xmlContent = "<Content>" + xmlContent + "</Content>"; } Node newContentNode = null; try (InputStream is = new ByteArrayInputStream(xmlContent.getBytes())) { DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); docBuilderFactory.setNamespaceAware(true); newContentNode = docBuilderFactory .newDocumentBuilder() .parse(is) .getDocumentElement(); } catch (Exception e) { String message = e.getMessage(); if (e.getCause() != null) { message = e.getCause().getMessage(); } return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_SYNTAX_ERROR, this.getShortFunctionId() + " Parsing of XML string failed. Cause='" + message + "'" )); } @SuppressWarnings("unused") RequestAttributes newRequestAttributes = null; try { newRequestAttributes = DOMRequestAttributes.newInstance(newContentNode); } catch (DOMStructureException e) { String message = e.getMessage(); if (e.getCause() != null) { message = e.getCause().getMessage(); } return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_SYNTAX_ERROR, this.getShortFunctionId() + " Conversion of XML to RequestAttributes failed. Cause='" + message + "'" )); } if (evaluationContext == null) { return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, this.getShortFunctionId() + " Got null EvaluationContext")); } if (evaluationContext.getRequest() == null) { return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, this.getShortFunctionId() + " Got null Request in EvaluationContext")); } Request originalRequest = evaluationContext.getRequest(); @SuppressWarnings("unused") Request newRequest = new StdRequest(originalRequest); return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, this.getShortFunctionId() + " Not Implemented")); } FunctionDefinitionAccessPermitted(Identifier idIn); }
FunctionDefinitionAccessPermitted extends FunctionDefinitionBase<Boolean, 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, this.getShortFunctionId() + " Expected 2 arguments, got " + ((arguments == null) ? "null" : arguments.size()) )); } FunctionArgument functionArgument = arguments.get(0); ConvertedArgument<URI> convertedArgument0 = new ConvertedArgument<URI>(functionArgument, DataTypes.DT_ANYURI, false); if ( ! convertedArgument0.isOk()) { return ExpressionResult.newError(getFunctionStatus(convertedArgument0.getStatus())); } URI attributesURI = convertedArgument0.getValue(); if ( ! attributesURI.toString().startsWith("urn:") || ! attributesURI.toString().contains(":attribute-category:")) { return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_SYNTAX_ERROR, this.getShortFunctionId() + " First argument must be a urn for an attribute-category, not '" + attributesURI.toString() )); } functionArgument = arguments.get(1); ConvertedArgument<String> convertedArgument1 = new ConvertedArgument<String>(functionArgument, DataTypes.DT_STRING, false); if ( ! convertedArgument1.isOk()) { return ExpressionResult.newError(getFunctionStatus(convertedArgument1.getStatus())); } String xmlContent = convertedArgument1.getValue(); if ( ! xmlContent.trim().toLowerCase().startsWith("<content>") ) { xmlContent = "<Content>" + xmlContent + "</Content>"; } Node newContentNode = null; try (InputStream is = new ByteArrayInputStream(xmlContent.getBytes())) { DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); docBuilderFactory.setNamespaceAware(true); newContentNode = docBuilderFactory .newDocumentBuilder() .parse(is) .getDocumentElement(); } catch (Exception e) { String message = e.getMessage(); if (e.getCause() != null) { message = e.getCause().getMessage(); } return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_SYNTAX_ERROR, this.getShortFunctionId() + " Parsing of XML string failed. Cause='" + message + "'" )); } @SuppressWarnings("unused") RequestAttributes newRequestAttributes = null; try { newRequestAttributes = DOMRequestAttributes.newInstance(newContentNode); } catch (DOMStructureException e) { String message = e.getMessage(); if (e.getCause() != null) { message = e.getCause().getMessage(); } return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_SYNTAX_ERROR, this.getShortFunctionId() + " Conversion of XML to RequestAttributes failed. Cause='" + message + "'" )); } if (evaluationContext == null) { return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, this.getShortFunctionId() + " Got null EvaluationContext")); } if (evaluationContext.getRequest() == null) { return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, this.getShortFunctionId() + " Got null Request in EvaluationContext")); } Request originalRequest = evaluationContext.getRequest(); @SuppressWarnings("unused") Request newRequest = new StdRequest(originalRequest); return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, this.getShortFunctionId() + " Not Implemented")); } FunctionDefinitionAccessPermitted(Identifier idIn); @Override ExpressionResult evaluate(EvaluationContext evaluationContext, List<FunctionArgument> arguments); }
FunctionDefinitionAccessPermitted extends FunctionDefinitionBase<Boolean, 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, this.getShortFunctionId() + " Expected 2 arguments, got " + ((arguments == null) ? "null" : arguments.size()) )); } FunctionArgument functionArgument = arguments.get(0); ConvertedArgument<URI> convertedArgument0 = new ConvertedArgument<URI>(functionArgument, DataTypes.DT_ANYURI, false); if ( ! convertedArgument0.isOk()) { return ExpressionResult.newError(getFunctionStatus(convertedArgument0.getStatus())); } URI attributesURI = convertedArgument0.getValue(); if ( ! attributesURI.toString().startsWith("urn:") || ! attributesURI.toString().contains(":attribute-category:")) { return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_SYNTAX_ERROR, this.getShortFunctionId() + " First argument must be a urn for an attribute-category, not '" + attributesURI.toString() )); } functionArgument = arguments.get(1); ConvertedArgument<String> convertedArgument1 = new ConvertedArgument<String>(functionArgument, DataTypes.DT_STRING, false); if ( ! convertedArgument1.isOk()) { return ExpressionResult.newError(getFunctionStatus(convertedArgument1.getStatus())); } String xmlContent = convertedArgument1.getValue(); if ( ! xmlContent.trim().toLowerCase().startsWith("<content>") ) { xmlContent = "<Content>" + xmlContent + "</Content>"; } Node newContentNode = null; try (InputStream is = new ByteArrayInputStream(xmlContent.getBytes())) { DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); docBuilderFactory.setNamespaceAware(true); newContentNode = docBuilderFactory .newDocumentBuilder() .parse(is) .getDocumentElement(); } catch (Exception e) { String message = e.getMessage(); if (e.getCause() != null) { message = e.getCause().getMessage(); } return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_SYNTAX_ERROR, this.getShortFunctionId() + " Parsing of XML string failed. Cause='" + message + "'" )); } @SuppressWarnings("unused") RequestAttributes newRequestAttributes = null; try { newRequestAttributes = DOMRequestAttributes.newInstance(newContentNode); } catch (DOMStructureException e) { String message = e.getMessage(); if (e.getCause() != null) { message = e.getCause().getMessage(); } return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_SYNTAX_ERROR, this.getShortFunctionId() + " Conversion of XML to RequestAttributes failed. Cause='" + message + "'" )); } if (evaluationContext == null) { return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, this.getShortFunctionId() + " Got null EvaluationContext")); } if (evaluationContext.getRequest() == null) { return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, this.getShortFunctionId() + " Got null Request in EvaluationContext")); } Request originalRequest = evaluationContext.getRequest(); @SuppressWarnings("unused") Request newRequest = new StdRequest(originalRequest); return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, this.getShortFunctionId() + " Not Implemented")); } FunctionDefinitionAccessPermitted(Identifier idIn); @Override ExpressionResult evaluate(EvaluationContext evaluationContext, List<FunctionArgument> arguments);  }