/** * Sets up the Subject section of the request. Takes a list of Maps of * URI/AttributeValue pairs. Each list element represents one subject which * contains a map of URI/AttributeValues. * * @return a Set of Subject instances for inclusion in a Request */ public List<Subject> setupSubjects(List<Map<URI, List<AttributeValue>>> subjs) { if (subjs == null || subjs.size() == 0) { return Collections.singletonList(new Subject(new ArrayList<Attribute>())); } List<Subject> subjects = new ArrayList<Subject>(subjs.size()); // Go through each of the subjects for (Map<URI, List<AttributeValue>> s : subjs) { List<Attribute> attributes = new ArrayList<Attribute>(); // Extract and create the attributes for this subject and add them // to the set for (URI uri : s.keySet()) { List<AttributeValue> attributeValues = s.get(uri); if (attributeValues != null && attributeValues.size() > 0) { attributes.add( new BasicAttribute(uri, attributeValues.get(0).getType(), null, null, attributeValues)); } } // Create a new subject and add the attributes for this subject subjects.add(new Subject(attributes)); } return subjects; }
private static List parseAttributes(Node root) throws ParsingException { List set = new ArrayList(); // the Environment section is just a list of Attributes NodeList nodes = root.getChildNodes(); for (int i = 0; i < nodes.getLength(); i++) { Node node = nodes.item(i); if (SunxacmlUtil.getNodeName(node).equals("Attribute")) set.add(BasicAttribute.getInstance(node)); } return set; }
@Test public void testBasicRoundtrip() throws ParsingException { URI id = URI.create("lol:wut"); String issuer = null; BasicAttribute expected = new BasicAttribute(id, issuer, null, StringAttribute.getInstance("foo")); String encoded = expected.encode(); ByteArrayInputStream input = new ByteArrayInputStream(encoded.getBytes()); Attribute actual = BasicAttribute.getInstance(InputParser.parseInput(input, "Attribute")); assertEquals(expected, actual); }
if (val != null) valCollection.add(val); return new BasicAttribute(id, type, iString, getCurrentDateTime(), valCollection);
private static List parseAttributes(Node root) throws ParsingException { List set = new ArrayList(); // the Environment section is just a list of Attributes NodeList nodes = root.getChildNodes(); for (int i = 0; i < nodes.getLength(); i++) { Node node = nodes.item(i); if (SunxacmlUtil.getNodeName(node).equals("Attribute")) set.add(BasicAttribute.getInstance(node)); } return set; }
throw new ParsingException("Attribute must contain a value"); return new BasicAttribute(id, type, issuer, issueInstant, valueSet);
@Test public void testSingletonRoundtrip() throws ParsingException { URI id = URI.create("lol:wut"); String issuer = null; Attribute expected = new SingletonAttribute(id, issuer, null, StringAttribute.getInstance("foo")); String encoded = expected.encode(); ByteArrayInputStream input = new ByteArrayInputStream(encoded.getBytes()); Attribute actual = BasicAttribute.getInstance(InputParser.parseInput(input, "Attribute")); assertEquals(expected, actual); } // Supports legacy test runners
throw new ParsingException("Attribute must contain a value"); return new BasicAttribute(id, type, issuer, issueInstant, valueSet);
if (val != null) valCollection.add(val); return new BasicAttribute(id, type, iString, getCurrentDateTime(), valCollection);