0

I'm aware there is already a question here on stackoverflow where this is discussed, but I still have trouble to send the correct values to Bag.newAttributeBag and was hoping for some help.

final Collection<StringValue> subjectList = new ArrayList<>();

    subjectList.add("123456");
    subjectList.add("John Smith");

final AttributeFqn subjectIdAttributeId = AttributeFqns.newInstance(XACML_1_0_ACCESS_SUBJECT.value(), Optional.empty(), XacmlAttributeId.XACML_1_0_SUBJECT_ID.value());
final AttributeBag<?> subjectIdAttributeValues = Bags.newAttributeBag(StandardDatatypes.STRING, subjectList);
requestBuilder.putNamedAttributeIfAbsent(subjectIdAttributeId, subjectIdAttributeValues);

If I use Collection StringValue I get an error on subjectList.add

The method add(StringValue) in the type Collection is not applicable for the arguments (String)

If I use Collection<String> I get an error on newAttributeBag. How can I add multiple values to my Bag.newAttributeBag?

The method newAttributeBag(Datatype, Collection) in the type Bags is not applicable for the arguments (AttributeDatatype, Collection)

Code-Apprentice
  • 81,660
  • 23
  • 145
  • 268
Steffinho
  • 27
  • 6
  • What are the exact error messages? Please [edit] your question to include them. – Code-Apprentice Nov 03 '21 at 22:42
  • @Code-Apprentice I have updated with error messages. – Steffinho Nov 04 '21 at 08:55
  • Thanks for adding the main error message. Please also include enough of the stack trace to give some context. And show which lines cause the errors. – Code-Apprentice Nov 04 '21 at 15:11
  • What is the declaration for `StandardDataTypes`? What is `StringValue`? Your code is incomplete and I'm unable to answer your question without more details. Please check out [mcve] for suggestions on creating a good code example. – Code-Apprentice Nov 04 '21 at 15:12
  • I'm using the example from here: https://github.com/authzforce/core (Evaluating Requests in AuthzForce native API). As you can see they use Bags.singletonAttributeBag for a single value, but I want multiple values. How do I do that? – Steffinho Nov 05 '21 at 08:02
  • I'm not familiar with authzforce. However, I can help you solve the problem if you modify your code example as described in the link in my previous comment. – Code-Apprentice Nov 06 '21 at 16:17

1 Answers1

1

You should do:

subjectList.add(new StringValue("123456"));
subjectList.add(new StringValue("John Smith"));
cdan
  • 3,470
  • 13
  • 27
  • It worked! Thanks! I still got a problem though. The error I get now is: "Cannot find the declaration of element 'Policy'". That’s weird since I'm just using a template policy from OASIS called XACML 2.0 Interop Example Policy 01. I managed to get past this with another policy and request by changing some of the values in the Policy parameter and using different parameters below (i.e. using AnyOf, AllOf instead of Resources, Resources etc.). But I think this is just cheating and not really fixes the problem? – Steffinho Nov 08 '21 at 08:02
  • XACML 2.0 is a bit obsolete and no longer supported by AuthzForce. Please upgrade to XACML 3.0 policies. If still doesn't work, please show the Policy content. – cdan Nov 09 '21 at 01:18