use of org.opensaml.xacml.ctx.AttributeType in project cxf by apache.
the class DefaultXACMLRequestBuilder method createSubjectType.
private SubjectType createSubjectType(Principal principal, List<String> roles, String issuer) {
List<AttributeType> attributes = new ArrayList<>();
attributes.add(createAttribute(XACMLConstants.SUBJECT_ID, XACMLConstants.XS_STRING, issuer, principal.getName()));
if (roles != null) {
List<AttributeValueType> roleAttributes = new ArrayList<>();
for (String role : roles) {
if (role != null) {
AttributeValueType subjectRoleAttributeValue = RequestComponentBuilder.createAttributeValueType(role);
roleAttributes.add(subjectRoleAttributeValue);
}
}
if (!roleAttributes.isEmpty()) {
AttributeType subjectRoleAttribute = createAttribute(XACMLConstants.SUBJECT_ROLE, XACMLConstants.XS_ANY_URI, issuer, roleAttributes);
attributes.add(subjectRoleAttribute);
}
}
return RequestComponentBuilder.createSubjectType(attributes, null);
}
use of org.opensaml.xacml.ctx.AttributeType in project cxf by apache.
the class DefaultXACMLRequestBuilder method createEnvironmentType.
private EnvironmentType createEnvironmentType() {
if (sendDateTime) {
List<AttributeType> attributes = new ArrayList<>();
AttributeType environmentAttribute = createAttribute(XACMLConstants.CURRENT_DATETIME, XACMLConstants.XS_DATETIME, null, new DateTime().toString());
attributes.add(environmentAttribute);
return RequestComponentBuilder.createEnvironmentType(attributes);
}
List<AttributeType> attributes = Collections.emptyList();
return RequestComponentBuilder.createEnvironmentType(attributes);
}
use of org.opensaml.xacml.ctx.AttributeType in project cxf by apache.
the class DefaultXACMLRequestBuilder method createRequest.
/**
* Create an XACML Request given a Principal, list of roles and Message.
*/
public RequestType createRequest(Principal principal, List<String> roles, Message message) throws Exception {
CXFMessageParser messageParser = new CXFMessageParser(message);
String issuer = messageParser.getIssuer();
String actionToUse = messageParser.getAction(action);
SubjectType subjectType = createSubjectType(principal, roles, issuer);
ResourceType resourceType = createResourceType(messageParser);
AttributeType actionAttribute = createAttribute(XACMLConstants.ACTION_ID, XACMLConstants.XS_STRING, null, actionToUse);
ActionType actionType = RequestComponentBuilder.createActionType(Collections.singletonList(actionAttribute));
return RequestComponentBuilder.createRequestType(Collections.singletonList(subjectType), Collections.singletonList(resourceType), actionType, createEnvironmentType());
}
use of org.opensaml.xacml.ctx.AttributeType in project cxf by apache.
the class SamlRequestComponentBuilderTest method testCreateXACMLSamlAuthzQueryRequest.
@org.junit.Test
public void testCreateXACMLSamlAuthzQueryRequest() throws Exception {
Document doc = docBuilder.newDocument();
//
// Create XACML request
//
// Subject
AttributeValueType subjectIdAttributeValue = RequestComponentBuilder.createAttributeValueType("alice-user@apache.org");
AttributeType subjectIdAttribute = RequestComponentBuilder.createAttributeType(XACMLConstants.SUBJECT_ID, XACMLConstants.RFC_822_NAME, null, Collections.singletonList(subjectIdAttributeValue));
AttributeValueType subjectGroupAttributeValue = RequestComponentBuilder.createAttributeValueType("manager");
AttributeType subjectGroupAttribute = RequestComponentBuilder.createAttributeType(XACMLConstants.SUBJECT_ROLE, XACMLConstants.XS_ANY_URI, "admin-user@apache.org", Collections.singletonList(subjectGroupAttributeValue));
List<AttributeType> attributes = new ArrayList<>();
attributes.add(subjectIdAttribute);
attributes.add(subjectGroupAttribute);
SubjectType subject = RequestComponentBuilder.createSubjectType(attributes, null);
// Resource
AttributeValueType resourceAttributeValue = RequestComponentBuilder.createAttributeValueType("{http://www.example.org/contract/DoubleIt}DoubleIt");
AttributeType resourceAttribute = RequestComponentBuilder.createAttributeType(XACMLConstants.RESOURCE_ID, XACMLConstants.XS_STRING, null, Collections.singletonList(resourceAttributeValue));
attributes.clear();
attributes.add(resourceAttribute);
ResourceType resource = RequestComponentBuilder.createResourceType(attributes, null);
// Action
AttributeValueType actionAttributeValue = RequestComponentBuilder.createAttributeValueType("execute");
AttributeType actionAttribute = RequestComponentBuilder.createAttributeType(XACMLConstants.ACTION_ID, XACMLConstants.XS_STRING, null, Collections.singletonList(actionAttributeValue));
attributes.clear();
attributes.add(actionAttribute);
ActionType action = RequestComponentBuilder.createActionType(attributes);
// Request
RequestType request = RequestComponentBuilder.createRequestType(Collections.singletonList(subject), Collections.singletonList(resource), action, null);
//
// Create SAML wrapper
//
XACMLAuthzDecisionQueryType authzQuery = SamlRequestComponentBuilder.createAuthzDecisionQuery("Issuer", request, SAMLProfileConstants.SAML20XACML20P_NS);
Element policyElement = OpenSAMLUtil.toDom(authzQuery, doc);
// String outputString = DOM2Writer.nodeToString(policyElement);
assertNotNull(policyElement);
}
use of org.opensaml.xacml.ctx.AttributeType in project cxf by apache.
the class XACMLRequestBuilderTest method testSOAPResourceDifferentNamespace.
@org.junit.Test
public void testSOAPResourceDifferentNamespace() throws Exception {
// Mock up a request
Principal principal = new Principal() {
public String getName() {
return "alice";
}
};
String operation = "{http://www.example.org/contract/DoubleIt}DoubleIt";
MessageImpl msg = new MessageImpl();
msg.put(Message.WSDL_OPERATION, QName.valueOf(operation));
String service = "{http://www.example.org/contract/DoubleItService}DoubleItService";
msg.put(Message.WSDL_SERVICE, QName.valueOf(service));
String resourceURL = "https://localhost:8080/doubleit";
msg.put(Message.REQUEST_URL, resourceURL);
XACMLRequestBuilder builder = new DefaultXACMLRequestBuilder();
RequestType request = builder.createRequest(principal, Collections.singletonList("manager"), msg);
assertNotNull(request);
List<ResourceType> resources = request.getResources();
assertNotNull(resources);
assertEquals(1, resources.size());
ResourceType resource = resources.get(0);
assertEquals(4, resource.getAttributes().size());
boolean resourceIdSatisfied = false;
boolean soapServiceSatisfied = false;
boolean soapOperationSatisfied = false;
boolean resourceURISatisfied = false;
String expectedResourceId = service + "#" + operation;
for (AttributeType attribute : resource.getAttributes()) {
String attributeValue = attribute.getAttributeValues().get(0).getValue();
if (XACMLConstants.RESOURCE_ID.equals(attribute.getAttributeId()) && expectedResourceId.equals(attributeValue)) {
resourceIdSatisfied = true;
} else if (XACMLConstants.RESOURCE_WSDL_SERVICE_ID.equals(attribute.getAttributeId()) && service.equals(attributeValue)) {
soapServiceSatisfied = true;
} else if (XACMLConstants.RESOURCE_WSDL_OPERATION_ID.equals(attribute.getAttributeId()) && operation.equals(attributeValue)) {
soapOperationSatisfied = true;
} else if (XACMLConstants.RESOURCE_WSDL_ENDPOINT.equals(attribute.getAttributeId()) && resourceURL.equals(attributeValue)) {
resourceURISatisfied = true;
}
}
assertTrue(resourceIdSatisfied && soapServiceSatisfied && soapOperationSatisfied && resourceURISatisfied);
}
Aggregations