/** * Creates the Environment attributes. * * @return a Set of Attributes for inclusion in a Request */ public List<Attribute> setupEnvironment(Map<URI, AttributeValue> e) { if (e == null || e.size() == 0) { return Collections.emptyList(); } List<Attribute> environment = new ArrayList<Attribute>(e.size()); for (URI uri : e.keySet()) { environment.add(new SingletonAttribute(uri, null, null, e.get(uri))); } return environment; }
actions.add(new SingletonAttribute(uri, null, null, newActions.get(uri)));
/** * Changes the value of the resource-id attribute in this context. This * is useful when you have multiple resources (ie, a scope other than * IMMEDIATE), and you need to keep changing only the resource-id to * evaluate the different effective requests. * * @param resourceId the new resource-id value */ public void setResourceId(AttributeValue resourceId) { this.resourceId = resourceId; // there will always be exactly one value for this attribute Collection attrSet = (Collection)(resourceMap.get(RESOURCE_ID)); Attribute attr = (Attribute)(attrSet.iterator().next()); // remove the old value... attrSet.remove(attr); // ...and insert the new value attrSet.add(new SingletonAttribute(attr.getId(), attr.getIssuer(), attr.getIssueInstant(), resourceId)); }
/** * Changes the value of the resource-id attribute in this context. This * is useful when you have multiple resources (ie, a scope other than * IMMEDIATE), and you need to keep changing only the resource-id to * evaluate the different effective requests. * * @param resourceId the new resource-id value */ public void setResourceId(AttributeValue resourceId) { this.resourceId = resourceId; // there will always be exactly one value for this attribute Collection attrSet = (Collection)(resourceMap.get(RESOURCE_ID)); Attribute attr = (Attribute)(attrSet.iterator().next()); // remove the old value... attrSet.remove(attr); // ...and insert the new value attrSet.add(new SingletonAttribute(attr.getId(), attr.getIssuer(), attr.getIssueInstant(), resourceId)); }
protected List<Attribute> wrapResources(String pid, String namespace) throws AuthzOperationalException { List<Attribute> resources = new ArrayList<Attribute>(3); Attribute attribute; try { attribute = new SingletonAttribute(Constants.XACML1_RESOURCE.ID.attributeId, null, null, AnyURIAttribute.getInstance(pid)); } catch (Exception e) { logger.warn("pid {} is not a valid uri; write policies against the StringAttribute {} instead.", pid, Constants.OBJECT.PID.uri); attribute = new SingletonAttribute(Constants.XACML1_RESOURCE.ID.attributeId, null, null, StringAttribute.getInstance(pid)); } resources.add(attribute); attribute = new SingletonAttribute(RESOURCE_PID_URI, null, null, new StringAttribute(pid)); resources.add(attribute); attribute = new SingletonAttribute(RESOURCE_NAMESPACE_URI, null, null, new StringAttribute(namespace)); resources.add(attribute); return resources; }
protected List<Attribute> wrapResources(String pid, String namespace) throws AuthzOperationalException { List<Attribute> resources = new ArrayList<Attribute>(3); Attribute attribute; try { attribute = new SingletonAttribute(Constants.XACML1_RESOURCE.ID.attributeId, null, null, AnyURIAttribute.getInstance(pid)); } catch (Exception e) { logger.warn("pid {} is not a valid uri; write policies against the StringAttribute {} instead.", pid, Constants.OBJECT.PID.uri); attribute = new SingletonAttribute(Constants.XACML1_RESOURCE.ID.attributeId, null, null, StringAttribute.getInstance(pid)); } resources.add(attribute); attribute = new SingletonAttribute(RESOURCE_PID_URI, null, null, new StringAttribute(pid)); resources.add(attribute); attribute = new SingletonAttribute(RESOURCE_NAMESPACE_URI, null, null, new StringAttribute(namespace)); resources.add(attribute); return resources; }
protected List<Attribute> wrapActions(String actionId, String actionApi, String contextIndex) { List<Attribute> actions = new ArrayList<Attribute>(4); actions.add(ACTION_ATTRIBUTE); Attribute action = new SingletonAttribute(ACTION_ID_URI, null, null, new StringAttribute(actionId)); actions.add(action); action = new SingletonAttribute(ACTION_API_URI, null, null, new StringAttribute(actionApi)); actions.add(action); if (contextIndex != null) { action = new SingletonAttribute(ACTION_CONTEXT_URI, null, null, new StringAttribute(contextIndex)); actions.add(action); } return actions; }
protected List<Attribute> wrapActions(String actionId, String actionApi, String contextIndex) { List<Attribute> actions = new ArrayList<Attribute>(4); actions.add(ACTION_ATTRIBUTE); Attribute action = new SingletonAttribute(ACTION_ID_URI, null, null, new StringAttribute(actionId)); actions.add(action); action = new SingletonAttribute(ACTION_API_URI, null, null, new StringAttribute(actionApi)); actions.add(action); if (contextIndex != null) { action = new SingletonAttribute(ACTION_CONTEXT_URI, null, null, new StringAttribute(contextIndex)); actions.add(action); } return actions; }
attributes.add(new SingletonAttribute(uri, null, null, res.get(uri)));
protected List<Subject> wrapSubjects(String subjectLoginId) { logger.debug("wrapSubjectIdAsSubjects(): {}", subjectLoginId); StringAttribute stringAttribute = EMPTY_ATTRIBUTE; Attribute subjectAttribute = SUBJECT_ATTRIBUTE; logger.debug("wrapSubjectIdAsSubjects(): subjectAttribute, id={}, type={}, value={}", subjectAttribute.getId(), subjectAttribute.getType(), subjectAttribute.getValue()); List<Attribute> subjectAttributes; if (subjectLoginId != null && !subjectLoginId.isEmpty()) { subjectAttributes = new ArrayList<Attribute>(2); subjectAttributes.add(subjectAttribute); stringAttribute = new StringAttribute(subjectLoginId); subjectAttribute = new SingletonAttribute(SUBJECT_ID_URI, null, null, stringAttribute); logger.debug("wrapSubjectIdAsSubjects(): subjectAttribute, id={}, type={}, value={}", subjectAttribute.getId(), subjectAttribute.getType(), subjectAttribute.getValue()); subjectAttributes.add(subjectAttribute); } else { subjectAttributes = new ArrayList<Attribute>(1); subjectAttributes.add(subjectAttribute); } Subject singleSubject = new Subject(subjectAttributes); return Collections.singletonList(singleSubject); }
protected List<Subject> wrapSubjects(String subjectLoginId) { logger.debug("wrapSubjectIdAsSubjects(): {}", subjectLoginId); StringAttribute stringAttribute = EMPTY_ATTRIBUTE; Attribute subjectAttribute = SUBJECT_ATTRIBUTE; logger.debug("wrapSubjectIdAsSubjects(): subjectAttribute, id={}, type={}, value={}", subjectAttribute.getId(), subjectAttribute.getType(), subjectAttribute.getValue()); List<Attribute> subjectAttributes; if (subjectLoginId != null && !subjectLoginId.isEmpty()) { subjectAttributes = new ArrayList<Attribute>(2); subjectAttributes.add(subjectAttribute); stringAttribute = new StringAttribute(subjectLoginId); subjectAttribute = new SingletonAttribute(SUBJECT_ID_URI, null, null, stringAttribute); logger.debug("wrapSubjectIdAsSubjects(): subjectAttribute, id={}, type={}, value={}", subjectAttribute.getId(), subjectAttribute.getType(), subjectAttribute.getValue()); subjectAttributes.add(subjectAttribute); } else { subjectAttributes = new ArrayList<Attribute>(1); subjectAttributes.add(subjectAttribute); } Subject singleSubject = new Subject(subjectAttributes); return Collections.singletonList(singleSubject); }
AttributeValue val = stringToValue(values[0], tString); return (val == null) ? null : new SingletonAttribute(id, iString, getCurrentDateTime(), val); } else { ArrayList<AttributeValue> valCollection = new ArrayList<AttributeValue>(values.length);
AttributeValue val = stringToValue(values[0], tString); return (val == null) ? null : new SingletonAttribute(id, iString, getCurrentDateTime(), val); } else { ArrayList<AttributeValue> valCollection = new ArrayList<AttributeValue>(values.length);
@Before public void setUp() throws ParsingException{ fixtureSubject = new Subject(Collections.emptyList()); List<Subject> subjects = Collections.singletonList(fixtureSubject); List<Attribute> action = Collections.emptyList(); List<Attribute> environment = Collections.emptyList(); List<Attribute> resource = Arrays.asList(new Attribute[]{ AbstractPolicyEnforcementPoint.RESOURCE_ATTRIBUTE, new SingletonAttribute(Constants.OBJECT.PID.attributeId, null, null, new StringAttribute("lol:wut")) }); test = new BasicRequestCtx(subjects, resource, action, environment); }
@Before public void setUp() throws ParsingException{ List<Subject> subjects = Collections.singletonList(mockSubject); List<Attribute> action = Collections.emptyList(); List<Attribute> environment = Collections.emptyList(); List<Attribute> resource = Arrays.asList(new Attribute[]{ AbstractPolicyEnforcementPoint.RESOURCE_ATTRIBUTE, new SingletonAttribute(Constants.OBJECT.PID.attributeId, null, null, new StringAttribute("lol:wut")) }); RequestCtx request = new BasicRequestCtx(subjects, resource, action, environment); test = new BasicEvaluationCtx(request, mockFinder, mockContext); }
@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
@Test public void testEquals() throws ParsingException { List<Subject> subjects = Collections.singletonList(fixtureSubject); List<Attribute> action = Collections.emptyList(); List<Attribute> environment = Collections.emptyList(); List<Attribute> resource = Arrays.asList(new Attribute[]{ AbstractPolicyEnforcementPoint.RESOURCE_ATTRIBUTE, new SingletonAttribute(Constants.OBJECT.PID.attributeId, null, null, new StringAttribute("foo:bar")) }); RequestCtx actual = new BasicRequestCtx(subjects, resource, action, environment); assertFalse(test.equals(actual)); resource = Arrays.asList(new Attribute[]{ AbstractPolicyEnforcementPoint.RESOURCE_ATTRIBUTE, new SingletonAttribute(Constants.OBJECT.PID.attributeId, null, null, new StringAttribute("lol:wut")) }); actual = new BasicRequestCtx(subjects, resource, action, environment); assertTrue(test.equals(actual)); }