@Test public void testHtmlProcessorTarget() { PolicySetType mockPolicySetType = Mockito.mock(PolicySetType.class); processor = new HtmlProcessor(temp, mockPolicySetType); processor.target(null); AnyOfType mockAnyOfType = Mockito.mock(AnyOfType.class); List<AnyOfType> anyOfList = new ArrayList<AnyOfType>(); anyOfList.add(mockAnyOfType); anyOfList.add(mockAnyOfType); AllOfType mockAllOfType = Mockito.mock(AllOfType.class); List<AllOfType> allOfTypeList = new ArrayList<AllOfType>(); allOfTypeList.add(mockAllOfType); allOfTypeList.add(mockAllOfType); MatchType mockMatchType = Mockito.mock(MatchType.class); List<MatchType> matchTypeList = new ArrayList<MatchType>(); matchTypeList.add(mockMatchType); matchTypeList.add(mockMatchType); AttributeValueType mockAttrValType = Mockito.mock(AttributeValueType.class); AttributeDesignatorType mockAttrDesType = Mockito.mock(AttributeDesignatorType.class); AttributeSelectorType mockAttrSelType = Mockito.mock(AttributeSelectorType.class); List<Object> contentList = new ArrayList<Object>(); when(mockAnyOfType.getAllOf()).thenReturn(allOfTypeList); when(mockAllOfType.getMatch()).thenReturn(matchTypeList); when(mockMatchType.getAttributeValue()).thenReturn(mockAttrValType); when(mockMatchType.getMatchId()).thenReturn(XACML1.ID_FUNCTION_STRING_EQUAL.stringValue()); when(mockMatchType.getAttributeDesignator()).thenReturn(mockAttrDesType); when(mockAttrValType.getDataType()).thenReturn(""); when(mockAttrValType.getContent()).thenReturn(contentList); when(mockAttrDesType.getCategory()).thenReturn(""); when(mockAttrDesType.getAttributeId()).thenReturn(""); when(mockAttrDesType.getIssuer()).thenReturn(""); when(mockAttrDesType.getDataType()).thenReturn(""); processor.target(anyOfList); verify(mockAnyOfType, atLeast(1)).getAllOf(); verify(mockAllOfType, atLeast(1)).getMatch(); verify(mockMatchType, atLeast(1)).getAttributeValue(); verify(mockMatchType, atLeast(1)).getMatchId(); verify(mockMatchType, atLeast(1)).getAttributeDesignator(); verify(mockAttrValType, atLeast(1)).getDataType(); verify(mockAttrValType, atLeast(1)).getContent(); verify(mockAttrDesType, atLeast(1)).getCategory(); verify(mockAttrDesType, atLeast(1)).getAttributeId(); verify(mockAttrDesType, atLeast(1)).getIssuer(); verify(mockAttrDesType, atLeast(1)).getDataType(); when(mockMatchType.getAttributeDesignator()).thenReturn(null); when(mockMatchType.getAttributeSelector()).thenReturn(mockAttrSelType); when(mockAttrSelType.getCategory()).thenReturn(""); when(mockAttrSelType.getContextSelectorId()).thenReturn(""); when(mockAttrSelType.getDataType()).thenReturn(""); processor.target(anyOfList); verify(mockMatchType, atLeast(1)).getAttributeDesignator(); verify(mockMatchType, atLeast(1)).getAttributeSelector(); verify(mockAttrSelType, atLeast(1)).getCategory(); verify(mockAttrSelType, atLeast(1)).getContextSelectorId(); verify(mockAttrSelType, atLeast(1)).getDataType(); when(mockMatchType.getAttributeDesignator()).thenReturn(null); when(mockMatchType.getAttributeSelector()).thenReturn(null); processor.target(anyOfList); verify(mockMatchType, atLeast(1)).getAttributeDesignator(); verify(mockMatchType, atLeast(1)).getAttributeSelector(); }
public void target(List<AnyOfType> anyOfList) { if (LOGGER.isTraceEnabled()) { LOGGER.trace(ENTER); } if (anyOfList == null) { return; } Iterator<AnyOfType> iterAnyOf = anyOfList.iterator(); StringBuilder targetInHuman = new StringBuilder(); while (iterAnyOf.hasNext()) { AnyOfType anyOf = iterAnyOf.next(); List<AllOfType> allOfList = anyOf.getAllOf(); Iterator<AllOfType> iterAllOf = allOfList.iterator(); while (iterAllOf.hasNext()) { AllOfType allOf = iterAllOf.next(); List<MatchType> matchList = allOf.getMatch(); Iterator<MatchType> iterMatch = matchList.iterator(); if (matchList.size() > 1) { targetInHuman.append("("); } while (iterMatch.hasNext()) { MatchType match = iterMatch.next(); StdAttribute attribute = null; AttributeValueType value = match.getAttributeValue(); String attributeDataType; if (match.getAttributeDesignator() != null && value != null) { AttributeDesignatorType designator = match.getAttributeDesignator(); attribute = new StdAttribute(new IdentifierImpl(designator.getCategory()), new IdentifierImpl(designator.getAttributeId()), new StdAttributeValue<List<?>>(new IdentifierImpl(value.getDataType()), value.getContent()), designator.getIssuer(), false); attributeDataType = designator.getDataType(); } else if (match.getAttributeSelector() != null && value != null) { AttributeSelectorType selector = match.getAttributeSelector(); attribute = new StdAttribute(new IdentifierImpl(selector.getCategory()), new IdentifierImpl(selector.getContextSelectorId()), new StdAttributeValue<List<?>>(new IdentifierImpl(value.getDataType()), value.getContent()), null, false); attributeDataType = selector.getDataType(); } else { LOGGER.warn("NULL designator/selector or value for match."); attributeDataType = "NA"; } String functionName = getHumanFunction(match.getMatchId()); if (attribute != null) { String succintIdentifier = extractLastIdentifier( attribute.getCategory().stringValue(), ":") + ":" + extractLastIdentifier(attribute.getAttributeId().stringValue(), ":"); AttributeIdentifiers ai = new AttributeIdentifiers(attribute.getCategory().stringValue(), attributeDataType, attribute.getAttributeId().stringValue()); this.attributeIdentifiersMap.put(succintIdentifier, ai); targetInHuman.append("<i><a href=\"#" + succintIdentifier + "\">" + succintIdentifier + "</a></i> " + functionName + " "); int numAttributes = attribute.getValues().size(); int count = 0; for (AttributeValue<?> v : attribute.getValues()) { count++; if (v.getValue() instanceof Collection<?>) { Collection<?> collectionValues = (Collection<?>) v.getValue(); int numValues = collectionValues.size(); int countValues = 0; for (Object o : collectionValues) { countValues++; targetInHuman.append(" <I>" + o + "</I>"); if (countValues < numValues) { targetInHuman.append(", or"); } } } else { targetInHuman.append(" <I>" + v.getValue() + "</I>"); if (count < numAttributes) { targetInHuman.append(", or "); } } } } if (iterMatch.hasNext()) { targetInHuman.append(" and "); } } if (matchList.size() > 1) { targetInHuman.append(")"); } } if (iterAllOf.hasNext()) { targetInHuman.append(" or "); } } if (iterAnyOf.hasNext()) { targetInHuman = new StringBuilder(); targetInHuman.append("(" + targetInHuman + ")" + " or "); } else { if (anyOfList.size() > 1) { targetInHuman.append(")"); } } htmlOut.println(targetInHuman); }
HtmlProcessor extends SimpleCallback { public void target(List<AnyOfType> anyOfList) { if (LOGGER.isTraceEnabled()) { LOGGER.trace(ENTER); } if (anyOfList == null) { return; } Iterator<AnyOfType> iterAnyOf = anyOfList.iterator(); StringBuilder targetInHuman = new StringBuilder(); while (iterAnyOf.hasNext()) { AnyOfType anyOf = iterAnyOf.next(); List<AllOfType> allOfList = anyOf.getAllOf(); Iterator<AllOfType> iterAllOf = allOfList.iterator(); while (iterAllOf.hasNext()) { AllOfType allOf = iterAllOf.next(); List<MatchType> matchList = allOf.getMatch(); Iterator<MatchType> iterMatch = matchList.iterator(); if (matchList.size() > 1) { targetInHuman.append("("); } while (iterMatch.hasNext()) { MatchType match = iterMatch.next(); StdAttribute attribute = null; AttributeValueType value = match.getAttributeValue(); String attributeDataType; if (match.getAttributeDesignator() != null && value != null) { AttributeDesignatorType designator = match.getAttributeDesignator(); attribute = new StdAttribute(new IdentifierImpl(designator.getCategory()), new IdentifierImpl(designator.getAttributeId()), new StdAttributeValue<List<?>>(new IdentifierImpl(value.getDataType()), value.getContent()), designator.getIssuer(), false); attributeDataType = designator.getDataType(); } else if (match.getAttributeSelector() != null && value != null) { AttributeSelectorType selector = match.getAttributeSelector(); attribute = new StdAttribute(new IdentifierImpl(selector.getCategory()), new IdentifierImpl(selector.getContextSelectorId()), new StdAttributeValue<List<?>>(new IdentifierImpl(value.getDataType()), value.getContent()), null, false); attributeDataType = selector.getDataType(); } else { LOGGER.warn("NULL designator/selector or value for match."); attributeDataType = "NA"; } String functionName = getHumanFunction(match.getMatchId()); if (attribute != null) { String succintIdentifier = extractLastIdentifier( attribute.getCategory().stringValue(), ":") + ":" + extractLastIdentifier(attribute.getAttributeId().stringValue(), ":"); AttributeIdentifiers ai = new AttributeIdentifiers(attribute.getCategory().stringValue(), attributeDataType, attribute.getAttributeId().stringValue()); this.attributeIdentifiersMap.put(succintIdentifier, ai); targetInHuman.append("<i><a href=\"#" + succintIdentifier + "\">" + succintIdentifier + "</a></i> " + functionName + " "); int numAttributes = attribute.getValues().size(); int count = 0; for (AttributeValue<?> v : attribute.getValues()) { count++; if (v.getValue() instanceof Collection<?>) { Collection<?> collectionValues = (Collection<?>) v.getValue(); int numValues = collectionValues.size(); int countValues = 0; for (Object o : collectionValues) { countValues++; targetInHuman.append(" <I>" + o + "</I>"); if (countValues < numValues) { targetInHuman.append(", or"); } } } else { targetInHuman.append(" <I>" + v.getValue() + "</I>"); if (count < numAttributes) { targetInHuman.append(", or "); } } } } if (iterMatch.hasNext()) { targetInHuman.append(" and "); } } if (matchList.size() > 1) { targetInHuman.append(")"); } } if (iterAllOf.hasNext()) { targetInHuman.append(" or "); } } if (iterAnyOf.hasNext()) { targetInHuman = new StringBuilder(); targetInHuman.append("(" + targetInHuman + ")" + " or "); } else { if (anyOfList.size() > 1) { targetInHuman.append(")"); } } htmlOut.println(targetInHuman); } }
HtmlProcessor extends SimpleCallback { public void target(List<AnyOfType> anyOfList) { if (LOGGER.isTraceEnabled()) { LOGGER.trace(ENTER); } if (anyOfList == null) { return; } Iterator<AnyOfType> iterAnyOf = anyOfList.iterator(); StringBuilder targetInHuman = new StringBuilder(); while (iterAnyOf.hasNext()) { AnyOfType anyOf = iterAnyOf.next(); List<AllOfType> allOfList = anyOf.getAllOf(); Iterator<AllOfType> iterAllOf = allOfList.iterator(); while (iterAllOf.hasNext()) { AllOfType allOf = iterAllOf.next(); List<MatchType> matchList = allOf.getMatch(); Iterator<MatchType> iterMatch = matchList.iterator(); if (matchList.size() > 1) { targetInHuman.append("("); } while (iterMatch.hasNext()) { MatchType match = iterMatch.next(); StdAttribute attribute = null; AttributeValueType value = match.getAttributeValue(); String attributeDataType; if (match.getAttributeDesignator() != null && value != null) { AttributeDesignatorType designator = match.getAttributeDesignator(); attribute = new StdAttribute(new IdentifierImpl(designator.getCategory()), new IdentifierImpl(designator.getAttributeId()), new StdAttributeValue<List<?>>(new IdentifierImpl(value.getDataType()), value.getContent()), designator.getIssuer(), false); attributeDataType = designator.getDataType(); } else if (match.getAttributeSelector() != null && value != null) { AttributeSelectorType selector = match.getAttributeSelector(); attribute = new StdAttribute(new IdentifierImpl(selector.getCategory()), new IdentifierImpl(selector.getContextSelectorId()), new StdAttributeValue<List<?>>(new IdentifierImpl(value.getDataType()), value.getContent()), null, false); attributeDataType = selector.getDataType(); } else { LOGGER.warn("NULL designator/selector or value for match."); attributeDataType = "NA"; } String functionName = getHumanFunction(match.getMatchId()); if (attribute != null) { String succintIdentifier = extractLastIdentifier( attribute.getCategory().stringValue(), ":") + ":" + extractLastIdentifier(attribute.getAttributeId().stringValue(), ":"); AttributeIdentifiers ai = new AttributeIdentifiers(attribute.getCategory().stringValue(), attributeDataType, attribute.getAttributeId().stringValue()); this.attributeIdentifiersMap.put(succintIdentifier, ai); targetInHuman.append("<i><a href=\"#" + succintIdentifier + "\">" + succintIdentifier + "</a></i> " + functionName + " "); int numAttributes = attribute.getValues().size(); int count = 0; for (AttributeValue<?> v : attribute.getValues()) { count++; if (v.getValue() instanceof Collection<?>) { Collection<?> collectionValues = (Collection<?>) v.getValue(); int numValues = collectionValues.size(); int countValues = 0; for (Object o : collectionValues) { countValues++; targetInHuman.append(" <I>" + o + "</I>"); if (countValues < numValues) { targetInHuman.append(", or"); } } } else { targetInHuman.append(" <I>" + v.getValue() + "</I>"); if (count < numAttributes) { targetInHuman.append(", or "); } } } } if (iterMatch.hasNext()) { targetInHuman.append(" and "); } } if (matchList.size() > 1) { targetInHuman.append(")"); } } if (iterAllOf.hasNext()) { targetInHuman.append(" or "); } } if (iterAnyOf.hasNext()) { targetInHuman = new StringBuilder(); targetInHuman.append("(" + targetInHuman + ")" + " or "); } else { if (anyOfList.size() > 1) { targetInHuman.append(")"); } } htmlOut.println(targetInHuman); } HtmlProcessor(File policyFile, Object policyObject); }
HtmlProcessor extends SimpleCallback { public void target(List<AnyOfType> anyOfList) { if (LOGGER.isTraceEnabled()) { LOGGER.trace(ENTER); } if (anyOfList == null) { return; } Iterator<AnyOfType> iterAnyOf = anyOfList.iterator(); StringBuilder targetInHuman = new StringBuilder(); while (iterAnyOf.hasNext()) { AnyOfType anyOf = iterAnyOf.next(); List<AllOfType> allOfList = anyOf.getAllOf(); Iterator<AllOfType> iterAllOf = allOfList.iterator(); while (iterAllOf.hasNext()) { AllOfType allOf = iterAllOf.next(); List<MatchType> matchList = allOf.getMatch(); Iterator<MatchType> iterMatch = matchList.iterator(); if (matchList.size() > 1) { targetInHuman.append("("); } while (iterMatch.hasNext()) { MatchType match = iterMatch.next(); StdAttribute attribute = null; AttributeValueType value = match.getAttributeValue(); String attributeDataType; if (match.getAttributeDesignator() != null && value != null) { AttributeDesignatorType designator = match.getAttributeDesignator(); attribute = new StdAttribute(new IdentifierImpl(designator.getCategory()), new IdentifierImpl(designator.getAttributeId()), new StdAttributeValue<List<?>>(new IdentifierImpl(value.getDataType()), value.getContent()), designator.getIssuer(), false); attributeDataType = designator.getDataType(); } else if (match.getAttributeSelector() != null && value != null) { AttributeSelectorType selector = match.getAttributeSelector(); attribute = new StdAttribute(new IdentifierImpl(selector.getCategory()), new IdentifierImpl(selector.getContextSelectorId()), new StdAttributeValue<List<?>>(new IdentifierImpl(value.getDataType()), value.getContent()), null, false); attributeDataType = selector.getDataType(); } else { LOGGER.warn("NULL designator/selector or value for match."); attributeDataType = "NA"; } String functionName = getHumanFunction(match.getMatchId()); if (attribute != null) { String succintIdentifier = extractLastIdentifier( attribute.getCategory().stringValue(), ":") + ":" + extractLastIdentifier(attribute.getAttributeId().stringValue(), ":"); AttributeIdentifiers ai = new AttributeIdentifiers(attribute.getCategory().stringValue(), attributeDataType, attribute.getAttributeId().stringValue()); this.attributeIdentifiersMap.put(succintIdentifier, ai); targetInHuman.append("<i><a href=\"#" + succintIdentifier + "\">" + succintIdentifier + "</a></i> " + functionName + " "); int numAttributes = attribute.getValues().size(); int count = 0; for (AttributeValue<?> v : attribute.getValues()) { count++; if (v.getValue() instanceof Collection<?>) { Collection<?> collectionValues = (Collection<?>) v.getValue(); int numValues = collectionValues.size(); int countValues = 0; for (Object o : collectionValues) { countValues++; targetInHuman.append(" <I>" + o + "</I>"); if (countValues < numValues) { targetInHuman.append(", or"); } } } else { targetInHuman.append(" <I>" + v.getValue() + "</I>"); if (count < numAttributes) { targetInHuman.append(", or "); } } } } if (iterMatch.hasNext()) { targetInHuman.append(" and "); } } if (matchList.size() > 1) { targetInHuman.append(")"); } } if (iterAllOf.hasNext()) { targetInHuman.append(" or "); } } if (iterAnyOf.hasNext()) { targetInHuman = new StringBuilder(); targetInHuman.append("(" + targetInHuman + ")" + " or "); } else { if (anyOfList.size() > 1) { targetInHuman.append(")"); } } htmlOut.println(targetInHuman); } HtmlProcessor(File policyFile, Object policyObject); Map<String, AttributeIdentifiers> getAttributeIdentifiersMap(); @Override void onFinishScan(Object root); @Override CallbackResult onPreVisitPolicySet(PolicySetType parent, PolicySetType policySet); @Override CallbackResult onPostVisitPolicySet(PolicySetType parent, PolicySetType policySet); void policySet(PolicySetType policySet, String htmlListElement); @Override CallbackResult onPreVisitPolicy(PolicySetType parent, PolicyType policy); @Override CallbackResult onPostVisitPolicy(PolicySetType parent, PolicyType policy); void policy(PolicyType policy); @Override CallbackResult onPreVisitRule(PolicyType parent, RuleType rule); @Override CallbackResult onPostVisitRule(PolicyType parent, RuleType rule); void rule(RuleType rule); void target(List<AnyOfType> anyOfList); String html(); }
HtmlProcessor extends SimpleCallback { public void target(List<AnyOfType> anyOfList) { if (LOGGER.isTraceEnabled()) { LOGGER.trace(ENTER); } if (anyOfList == null) { return; } Iterator<AnyOfType> iterAnyOf = anyOfList.iterator(); StringBuilder targetInHuman = new StringBuilder(); while (iterAnyOf.hasNext()) { AnyOfType anyOf = iterAnyOf.next(); List<AllOfType> allOfList = anyOf.getAllOf(); Iterator<AllOfType> iterAllOf = allOfList.iterator(); while (iterAllOf.hasNext()) { AllOfType allOf = iterAllOf.next(); List<MatchType> matchList = allOf.getMatch(); Iterator<MatchType> iterMatch = matchList.iterator(); if (matchList.size() > 1) { targetInHuman.append("("); } while (iterMatch.hasNext()) { MatchType match = iterMatch.next(); StdAttribute attribute = null; AttributeValueType value = match.getAttributeValue(); String attributeDataType; if (match.getAttributeDesignator() != null && value != null) { AttributeDesignatorType designator = match.getAttributeDesignator(); attribute = new StdAttribute(new IdentifierImpl(designator.getCategory()), new IdentifierImpl(designator.getAttributeId()), new StdAttributeValue<List<?>>(new IdentifierImpl(value.getDataType()), value.getContent()), designator.getIssuer(), false); attributeDataType = designator.getDataType(); } else if (match.getAttributeSelector() != null && value != null) { AttributeSelectorType selector = match.getAttributeSelector(); attribute = new StdAttribute(new IdentifierImpl(selector.getCategory()), new IdentifierImpl(selector.getContextSelectorId()), new StdAttributeValue<List<?>>(new IdentifierImpl(value.getDataType()), value.getContent()), null, false); attributeDataType = selector.getDataType(); } else { LOGGER.warn("NULL designator/selector or value for match."); attributeDataType = "NA"; } String functionName = getHumanFunction(match.getMatchId()); if (attribute != null) { String succintIdentifier = extractLastIdentifier( attribute.getCategory().stringValue(), ":") + ":" + extractLastIdentifier(attribute.getAttributeId().stringValue(), ":"); AttributeIdentifiers ai = new AttributeIdentifiers(attribute.getCategory().stringValue(), attributeDataType, attribute.getAttributeId().stringValue()); this.attributeIdentifiersMap.put(succintIdentifier, ai); targetInHuman.append("<i><a href=\"#" + succintIdentifier + "\">" + succintIdentifier + "</a></i> " + functionName + " "); int numAttributes = attribute.getValues().size(); int count = 0; for (AttributeValue<?> v : attribute.getValues()) { count++; if (v.getValue() instanceof Collection<?>) { Collection<?> collectionValues = (Collection<?>) v.getValue(); int numValues = collectionValues.size(); int countValues = 0; for (Object o : collectionValues) { countValues++; targetInHuman.append(" <I>" + o + "</I>"); if (countValues < numValues) { targetInHuman.append(", or"); } } } else { targetInHuman.append(" <I>" + v.getValue() + "</I>"); if (count < numAttributes) { targetInHuman.append(", or "); } } } } if (iterMatch.hasNext()) { targetInHuman.append(" and "); } } if (matchList.size() > 1) { targetInHuman.append(")"); } } if (iterAllOf.hasNext()) { targetInHuman.append(" or "); } } if (iterAnyOf.hasNext()) { targetInHuman = new StringBuilder(); targetInHuman.append("(" + targetInHuman + ")" + " or "); } else { if (anyOfList.size() > 1) { targetInHuman.append(")"); } } htmlOut.println(targetInHuman); } HtmlProcessor(File policyFile, Object policyObject); Map<String, AttributeIdentifiers> getAttributeIdentifiersMap(); @Override void onFinishScan(Object root); @Override CallbackResult onPreVisitPolicySet(PolicySetType parent, PolicySetType policySet); @Override CallbackResult onPostVisitPolicySet(PolicySetType parent, PolicySetType policySet); void policySet(PolicySetType policySet, String htmlListElement); @Override CallbackResult onPreVisitPolicy(PolicySetType parent, PolicyType policy); @Override CallbackResult onPostVisitPolicy(PolicySetType parent, PolicyType policy); void policy(PolicyType policy); @Override CallbackResult onPreVisitRule(PolicyType parent, RuleType rule); @Override CallbackResult onPostVisitRule(PolicyType parent, RuleType rule); void rule(RuleType rule); void target(List<AnyOfType> anyOfList); String html();  }