use of org.opensaml.xacml.ctx.RequestType in project cxf by apache.
the class XACMLRequestBuilderTest method testAction.
@org.junit.Test
public void testAction() 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/DoubleIt}DoubleItService";
msg.put(Message.WSDL_SERVICE, QName.valueOf(service));
String resourceURL = "https://localhost:8080/doubleit";
msg.put(Message.REQUEST_URI, resourceURL);
DefaultXACMLRequestBuilder builder = new DefaultXACMLRequestBuilder();
RequestType request = builder.createRequest(principal, Collections.singletonList("manager"), msg);
assertNotNull(request);
String action = request.getAction().getAttributes().get(0).getAttributeValues().get(0).getValue();
assertEquals("execute", action);
builder.setAction("write");
request = builder.createRequest(principal, Collections.singletonList("manager"), msg);
assertNotNull(request);
action = request.getAction().getAttributes().get(0).getAttributeValues().get(0).getValue();
assertEquals("write", action);
}
use of org.opensaml.xacml.ctx.RequestType in project cxf by apache.
the class XACMLRequestBuilderTest method testSOAPResource.
@org.junit.Test
public void testSOAPResource() 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/DoubleIt}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;
for (AttributeType attribute : resource.getAttributes()) {
String attributeValue = attribute.getAttributeValues().get(0).getValue();
if (XACMLConstants.RESOURCE_ID.equals(attribute.getAttributeId()) && "{http://www.example.org/contract/DoubleIt}DoubleItService#DoubleIt".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);
}
use of org.opensaml.xacml.ctx.RequestType in project cxf by apache.
the class XACMLRequestBuilderTest method testXACMLRequestBuilder.
@org.junit.Test
public void testXACMLRequestBuilder() 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/DoubleIt}DoubleItService";
msg.put(Message.WSDL_SERVICE, QName.valueOf(service));
String resourceURL = "https://localhost:8080/doubleit";
msg.put(Message.REQUEST_URI, resourceURL);
XACMLRequestBuilder builder = new DefaultXACMLRequestBuilder();
RequestType request = builder.createRequest(principal, Collections.singletonList("manager"), msg);
assertNotNull(request);
}
use of org.opensaml.xacml.ctx.RequestType in project cxf by apache.
the class AbstractXACMLAuthorizingInterceptor method authorize.
/**
* Perform a (remote) authorization decision and return a boolean depending on the result
*/
protected boolean authorize(Principal principal, List<String> roles, Message message) throws Exception {
RequestType request = requestBuilder.createRequest(principal, roles, message);
if (LOG.isLoggable(Level.FINE)) {
Document doc = DOMUtils.createDocument();
Element requestElement = OpenSAMLUtil.toDom(request, doc);
LOG.log(Level.FINE, DOM2Writer.nodeToString(requestElement));
}
ResponseType response = performRequest(request, message);
List<ResultType> results = response.getResults();
if (results == null) {
return false;
}
for (ResultType result : results) {
// Handle any Obligations returned by the PDP
handleObligations(request, principal, message, result);
DECISION decision = result.getDecision() != null ? result.getDecision().getDecision() : DECISION.Deny;
String code = "";
String statusMessage = "";
if (result.getStatus() != null) {
StatusType status = result.getStatus();
code = status.getStatusCode() != null ? status.getStatusCode().getValue() : "";
statusMessage = status.getStatusMessage() != null ? status.getStatusMessage().getValue() : "";
}
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("XACML authorization result: " + decision + ", code: " + code + ", message: " + statusMessage);
}
return decision == DECISION.Permit;
}
return false;
}
Aggregations