Java Code Examples for org.opensaml.xacml.ctx.RequestType#getResources()

The following examples show how to use org.opensaml.xacml.ctx.RequestType#getResources() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XACMLRequestBuilderTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@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);
    }
}
 
Example 2
Source File: XACMLRequestBuilderTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@org.junit.Test
public void testRESTResourceTruncatedURI() 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);
    String resourceURI = "/doubleit";
    msg.put(Message.REQUEST_URI, resourceURI);

    XACMLRequestBuilder builder = new DefaultXACMLRequestBuilder();
    ((DefaultXACMLRequestBuilder)builder).setSendFullRequestURL(false);
    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, resourceURI);
    }
}
 
Example 3
Source File: XACMLRequestBuilderTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@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);
}
 
Example 4
Source File: XACMLRequestBuilderTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@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);
}