FindAction { public StdMutableResponse run(final StdMutableResponse stdResponse, final Request pepRequest) { int count = 0; boolean config = false; boolean decide = false; final Collection<RequestAttributes> requestAttributes = pepRequest.getRequestAttributes(); for (final RequestAttributes requestAttribute : requestAttributes) { final Collection<Attribute> attributes = requestAttribute.getAttributes(); for (final Attribute attribute : attributes) { if (attribute.getAttributeId().stringValue().equals("urn:oasis:names:tc:xacml:1.0:action:action-id")) { for (final AttributeValue<?> attributeValue : attribute.getValues()) { if (attributeValue.getValue().toString().equalsIgnoreCase("ACCESS")) { count++; } if (attributeValue.getValue().toString().equalsIgnoreCase("DECIDE")) { decide = true; } } } if (attribute.getAttributeId().stringValue() .equals("urn:oasis:names:tc:xacml:1.0:resource:resource-id")) { for (final AttributeValue<?> attributeValue : attribute.getValues()) { if (attributeValue.getValue().toString().equalsIgnoreCase("Config")) { count++; } } } } } if (count == 2) { config = true; } if (!config) { search(stdResponse); } addResults(stdResponse, config, decide); logger.info("Original Result is " + stdResponse.toString()); logger.info("Generated Result is " + addResult.toString()); return newResponse; }  StdMutableResponse run(final StdMutableResponse stdResponse, final Request pepRequest);  }
@Test public final void testRun() { final FindAction action = new FindAction(); final StdMutableResponse response = new StdMutableResponse(); StdMutableStatus status = new StdMutableStatus(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE); status.setStatusMessage("some status message"); final StdMutableStatusDetail statusDetailIn = new StdMutableStatusDetail(); final StdMutableMissingAttributeDetail mad = new StdMutableMissingAttributeDetail(); mad.addAttributeValue(new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "PEPACTION")); mad.addAttributeValue(new StdAttributeValue<String>(DataTypes.DT_INTEGER.getId(), "PDPACTION")); mad.setAttributeId(XACML3.ID_ACTION_PURPOSE); mad.setCategory(XACML3.ID_ATTRIBUTE_CATEGORY_ACTION); mad.setDataTypeId(XACML3.ID_DATATYPE_STRING); mad.setIssuer("an Issuer"); statusDetailIn.addMissingAttributeDetail(mad); status.setStatusDetail(statusDetailIn); StdMutableResult result = new StdMutableResult(status); result.setDecision(Decision.INDETERMINATE); response.add(result); status = new StdMutableStatus(StdStatusCode.STATUS_CODE_OK); result = new StdMutableResult(status); result.setDecision(Decision.DENY); StdMutableObligation obligation = new StdMutableObligation(); obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION); obligation.addAttributeAssignment( new StdMutableAttributeAssignment(XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, XACML3.ID_SUBJECT, "obligation-issuer1", new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Test"))); result.addObligation(obligation); final StdMutableAdvice advice = new StdMutableAdvice(); advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION); advice.addAttributeAssignment( new StdMutableAttributeAssignment(XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, XACML3.ID_SUBJECT, "advice-issuer1", new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Test"))); response.add(result); status = new StdMutableStatus(StdStatusCode.STATUS_CODE_OK); result = new StdMutableResult(status); result.setDecision(Decision.PERMIT); obligation = new StdMutableObligation(); obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION); obligation.addAttributeAssignment(new StdMutableAttributeAssignment(XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, new IdentifierImpl("performer"), "obligation-issuer", new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "PDPACTION"))); obligation.addAttributeAssignment(new StdMutableAttributeAssignment(XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, new IdentifierImpl("URL"), "obligation-issuer", new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "http: obligation.addAttributeAssignment( new StdMutableAttributeAssignment(XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, new IdentifierImpl("method"), "obligation-issuer", new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "GET"))); obligation.addAttributeAssignment( new StdMutableAttributeAssignment(XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, new IdentifierImpl("headers"), "obligation-issuer", new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "foobar"))); result.addObligation(obligation); response.add(result); status = new StdMutableStatus(StdStatusCode.STATUS_CODE_OK); result = new StdMutableResult(status); result.setDecision(Decision.PERMIT); obligation = new StdMutableObligation(); obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION); obligation.addAttributeAssignment(new StdMutableAttributeAssignment(XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, new IdentifierImpl("performer"), "obligation-issuer", new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "PDPACTION"))); obligation.addAttributeAssignment(new StdMutableAttributeAssignment(XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, new IdentifierImpl("URL"), "obligation-issuer", new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "http: obligation.addAttributeAssignment( new StdMutableAttributeAssignment(XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, new IdentifierImpl("method"), "obligation-issuer", new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "POST"))); obligation.addAttributeAssignment(new StdMutableAttributeAssignment(XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, new IdentifierImpl("body"), "obligation-issuer", new StdAttributeValue<String>( DataTypes.DT_STRING.getId(), "http: result.addObligation(obligation); response.add(result); status = new StdMutableStatus(StdStatusCode.STATUS_CODE_OK); result = new StdMutableResult(status); result.setDecision(Decision.PERMIT); obligation = new StdMutableObligation(); obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION); obligation.addAttributeAssignment(new StdMutableAttributeAssignment(XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, new IdentifierImpl("performer"), "obligation-issuer", new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "PDPACTION"))); obligation.addAttributeAssignment(new StdMutableAttributeAssignment(XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, new IdentifierImpl("URL"), "obligation-issuer", new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "http: obligation.addAttributeAssignment( new StdMutableAttributeAssignment(XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, new IdentifierImpl("method"), "obligation-issuer", new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "PUT"))); obligation.addAttributeAssignment(new StdMutableAttributeAssignment(XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, new IdentifierImpl("body"), "obligation-issuer", new StdAttributeValue<String>( DataTypes.DT_STRING.getId(), "http: result.addObligation(obligation); response.add(result); try { assertTrue(action.run(response, request) != null); } catch (final Exception e) { fail("operation failed, e=" + e); } }