Search in sources :

Example 11 with AttributeType

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);
}
Also used : AttributeType(org.opensaml.xacml.ctx.AttributeType) ResourceType(org.opensaml.xacml.ctx.ResourceType) MessageImpl(org.apache.cxf.message.MessageImpl) Principal(java.security.Principal) RequestType(org.opensaml.xacml.ctx.RequestType)

Example 12 with AttributeType

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);
}
Also used : AttributeType(org.opensaml.xacml.ctx.AttributeType) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList)

Aggregations

AttributeType (org.opensaml.xacml.ctx.AttributeType)12 ResourceType (org.opensaml.xacml.ctx.ResourceType)8 RequestType (org.opensaml.xacml.ctx.RequestType)7 ArrayList (java.util.ArrayList)6 Principal (java.security.Principal)4 MessageImpl (org.apache.cxf.message.MessageImpl)4 ActionType (org.opensaml.xacml.ctx.ActionType)4 AttributeValueType (org.opensaml.xacml.ctx.AttributeValueType)4 SubjectType (org.opensaml.xacml.ctx.SubjectType)4 Document (org.w3c.dom.Document)3 Element (org.w3c.dom.Element)3 DateTime (org.joda.time.DateTime)2 QName (javax.xml.namespace.QName)1 CXFMessageParser (org.apache.cxf.rt.security.saml.xacml.CXFMessageParser)1 EnvironmentType (org.opensaml.xacml.ctx.EnvironmentType)1 XACMLAuthzDecisionQueryType (org.opensaml.xacml.profile.saml.XACMLAuthzDecisionQueryType)1