// Subject
List<AttributeType> attributes = new ArrayList<AttributeType>();
AttributeValueType subjectIdAttributeValue =
RequestComponentBuilder.createAttributeValueType(principal.getName());
AttributeType subjectIdAttribute =
RequestComponentBuilder.createAttributeType(
XACMLConstants.SUBJECT_ID,
XACMLConstants.XS_STRING,
issuer,
Collections.singletonList(subjectIdAttributeValue)
);
attributes.add(subjectIdAttribute);
if (roles != null) {
List<AttributeValueType> roleAttributes = new ArrayList<AttributeValueType>();
for (String role : roles) {
if (role != null) {
AttributeValueType subjectRoleAttributeValue =
RequestComponentBuilder.createAttributeValueType(role);
roleAttributes.add(subjectRoleAttributeValue);
}
}
if (!roleAttributes.isEmpty()) {
AttributeType subjectRoleAttribute =
RequestComponentBuilder.createAttributeType(
XACMLConstants.SUBJECT_ROLE,
XACMLConstants.XS_ANY_URI,
issuer,
roleAttributes
);
attributes.add(subjectRoleAttribute);
}
}
SubjectType subjectType = RequestComponentBuilder.createSubjectType(attributes, null);
// Resource
ResourceType resourceType = createResourceType(message);
// Action
AttributeValueType actionAttributeValue =
RequestComponentBuilder.createAttributeValueType(actionToUse);
AttributeType actionAttribute =
RequestComponentBuilder.createAttributeType(
XACMLConstants.ACTION_ID,
XACMLConstants.XS_STRING,
null,
Collections.singletonList(actionAttributeValue)
);
attributes.clear();
attributes.add(actionAttribute);
ActionType actionType = RequestComponentBuilder.createActionType(attributes);
// Environment
attributes.clear();
if (sendDateTime) {
DateTime dateTime = new DateTime();
AttributeValueType environmentAttributeValue =
RequestComponentBuilder.createAttributeValueType(dateTime.toString());
AttributeType environmentAttribute =
RequestComponentBuilder.createAttributeType(
XACMLConstants.CURRENT_DATETIME,
XACMLConstants.XS_DATETIME,
null,
Collections.singletonList(environmentAttributeValue)