use of org.opensaml.xacml.ctx.RequestType in project testcases by coheigea.
the class MockPDPImpl method requestSourceToRequestType.
private RequestType requestSourceToRequestType(Source requestSource) {
try {
Transformer trans = TransformerFactory.newInstance().newTransformer();
DOMResult res = new DOMResult();
trans.transform(requestSource, res);
Node nd = res.getNode();
if (nd instanceof Document) {
nd = ((Document) nd).getDocumentElement();
}
return (RequestType) OpenSAMLUtil.fromDom((Element) nd);
} catch (Exception e) {
throw new RuntimeException("Error converting pdp response to ResponseType", e);
}
}
use of org.opensaml.xacml.ctx.RequestType in project cxf by apache.
the class RequestComponentBuilder method createRequestType.
@SuppressWarnings("unchecked")
public static RequestType createRequestType(List<SubjectType> subjects, List<ResourceType> resources, ActionType action, EnvironmentType environment) {
if (requestTypeBuilder == null) {
requestTypeBuilder = (XACMLObjectBuilder<RequestType>) builderFactory.getBuilder(RequestType.DEFAULT_ELEMENT_NAME);
}
RequestType request = requestTypeBuilder.buildObject();
request.getSubjects().addAll(subjects);
request.getResources().addAll(resources);
request.setAction(action);
request.setEnvironment(environment);
return request;
}
use of org.opensaml.xacml.ctx.RequestType in project cxf by apache.
the class RequestComponentBuilderTest method testEnvironment.
@org.junit.Test
public void testEnvironment() throws Exception {
Document doc = docBuilder.newDocument();
// Subject
AttributeValueType subjectIdAttributeValue = RequestComponentBuilder.createAttributeValueType("alice-user@apache.org");
AttributeType subjectIdAttribute = RequestComponentBuilder.createAttributeType(XACMLConstants.SUBJECT_ID, XACMLConstants.RFC_822_NAME, null, Collections.singletonList(subjectIdAttributeValue));
List<AttributeType> attributes = new ArrayList<>();
attributes.add(subjectIdAttribute);
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);
// Environment
DateTime dateTime = new DateTime();
AttributeValueType environmentAttributeValue = RequestComponentBuilder.createAttributeValueType(dateTime.toString());
AttributeType environmentAttribute = RequestComponentBuilder.createAttributeType(XACMLConstants.CURRENT_DATETIME, XACMLConstants.XS_DATETIME, null, Collections.singletonList(environmentAttributeValue));
attributes.clear();
attributes.add(environmentAttribute);
EnvironmentType environmentType = RequestComponentBuilder.createEnvironmentType(attributes);
// Request
RequestType request = RequestComponentBuilder.createRequestType(Collections.singletonList(subject), Collections.singletonList(resource), action, environmentType);
Element policyElement = OpenSAMLUtil.toDom(request, doc);
// String outputString = DOM2Writer.nodeToString(policyElement);
assertNotNull(policyElement);
}
use of org.opensaml.xacml.ctx.RequestType in project cxf by apache.
the class RequestComponentBuilderTest method testCreateXACMLRequest.
@org.junit.Test
public void testCreateXACMLRequest() throws Exception {
Document doc = docBuilder.newDocument();
// 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);
Element policyElement = OpenSAMLUtil.toDom(request, doc);
// String outputString = DOM2Writer.nodeToString(policyElement);
assertNotNull(policyElement);
}
use of org.opensaml.xacml.ctx.RequestType in project cxf by apache.
the class XACMLRequestBuilderTest method testRESTResource.
@org.junit.Test
public void testRESTResource() throws Exception {
// Mock up a request
Principal principal = new Principal() {
public String getName() {
return "alice";
}
};
MessageImpl msg = new MessageImpl();
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(1, resource.getAttributes().size());
for (AttributeType attribute : resource.getAttributes()) {
String attributeValue = attribute.getAttributeValues().get(0).getValue();
assertEquals(attributeValue, resourceURL);
}
}
Aggregations