use of org.opensaml.xacml.ctx.AttributeType 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.AttributeType in project cxf by apache.
the class DefaultXACMLRequestBuilder method createResourceType.
private ResourceType createResourceType(CXFMessageParser messageParser) {
List<AttributeType> attributes = new ArrayList<>();
// Resource-id
String resourceId = null;
boolean isSoapService = messageParser.isSOAPService();
if (isSoapService) {
QName serviceName = messageParser.getWSDLService();
QName operationName = messageParser.getWSDLOperation();
if (serviceName != null) {
resourceId = serviceName.toString() + "#";
if (serviceName.getNamespaceURI() != null && serviceName.getNamespaceURI().equals(operationName.getNamespaceURI())) {
resourceId += operationName.getLocalPart();
} else {
resourceId += operationName.toString();
}
} else {
resourceId = operationName.toString();
}
} else {
resourceId = messageParser.getResourceURI(sendFullRequestURL);
}
attributes.add(createAttribute(XACMLConstants.RESOURCE_ID, XACMLConstants.XS_STRING, null, resourceId));
if (isSoapService) {
// WSDL Service
QName wsdlService = messageParser.getWSDLService();
if (wsdlService != null) {
attributes.add(createAttribute(XACMLConstants.RESOURCE_WSDL_SERVICE_ID, XACMLConstants.XS_STRING, null, wsdlService.toString()));
}
// WSDL Operation
QName wsdlOperation = messageParser.getWSDLOperation();
attributes.add(createAttribute(XACMLConstants.RESOURCE_WSDL_OPERATION_ID, XACMLConstants.XS_STRING, null, wsdlOperation.toString()));
// WSDL Endpoint
String endpointURI = messageParser.getResourceURI(sendFullRequestURL);
attributes.add(createAttribute(XACMLConstants.RESOURCE_WSDL_ENDPOINT, XACMLConstants.XS_STRING, null, endpointURI));
}
return RequestComponentBuilder.createResourceType(attributes, null);
}
Aggregations