Search in sources :

Example 6 with UmaPermission

use of org.gluu.oxauth.model.uma.UmaPermission in project oxAuth by GluuFederation.

the class UmaRegisterPermissionFlowHttpTest method testRegisterPermissionForInvalidResource.

/**
 * Test for registering permissions for resource
 */
@Test
public void testRegisterPermissionForInvalidResource() throws Exception {
    showTitle("testRegisterPermissionForInvalidResource");
    UmaPermission permission = new UmaPermission();
    permission.setResourceId(this.registerResourceTest.resourceId + "1");
    permission.setScopes(Arrays.asList("http://photoz.example.com/dev/scopes/view", "http://photoz.example.com/dev/scopes/all"));
    PermissionTicket ticket = null;
    try {
        ticket = getPermissionService().registerPermission("Bearer " + this.registerResourceTest.pat.getAccessToken(), UmaPermissionList.instance(permission));
    } catch (ClientErrorException ex) {
        System.err.println(ex.getResponse().readEntity(String.class));
        assertTrue(ex.getResponse().getStatus() != Response.Status.CREATED.getStatusCode() && ex.getResponse().getStatus() != Response.Status.OK.getStatusCode(), "Unexpected response status");
    }
    assertNull(ticket, "Resource permission is not null");
}
Also used : PermissionTicket(org.gluu.oxauth.model.uma.PermissionTicket) ClientErrorException(javax.ws.rs.ClientErrorException) UmaPermission(org.gluu.oxauth.model.uma.UmaPermission) BaseTest(org.gluu.oxauth.BaseTest) Test(org.testng.annotations.Test)

Example 7 with UmaPermission

use of org.gluu.oxauth.model.uma.UmaPermission in project oxAuth by GluuFederation.

the class RegisterPermissionWSTest method testRegisterPermissionWithInvalidResource.

@Test(dependsOnMethods = { "testRegisterPermission" })
public void testRegisterPermissionWithInvalidResource() {
    final String path = umaPermissionPath;
    try {
        Builder request = ResteasyClientBuilder.newClient().target(url.toString() + path).request();
        request.header("Accept", UmaConstants.JSON_MEDIA_TYPE);
        request.header("Authorization", "Bearer " + pat.getAccessToken());
        String json = null;
        try {
            final UmaPermission r = new UmaPermission();
            r.setResourceId(resource.getId() + "x");
            json = ServerUtil.createJsonMapper().writeValueAsString(r);
        } catch (IOException e) {
            e.printStackTrace();
            fail();
        }
        Response response = request.post(Entity.json(json));
        String entity = response.readEntity(String.class);
        BaseTest.showResponse("UMA : RegisterPermissionWSTest.testRegisterPermissionWithInvalidResource() : ", response, entity);
        assertEquals(response.getStatus(), Response.Status.NOT_FOUND.getStatusCode(), "Unexpected response code.");
        try {
            final PermissionTicket t = ServerUtil.createJsonMapper().readValue(entity, PermissionTicket.class);
            Assert.assertNull(t);
        } catch (Exception e) {
        // it's ok if it fails here, we expect ticket as null.
        }
    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }
}
Also used : Response(javax.ws.rs.core.Response) UmaResourceResponse(org.gluu.oxauth.model.uma.UmaResourceResponse) PermissionTicket(org.gluu.oxauth.model.uma.PermissionTicket) ResteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder) Builder(javax.ws.rs.client.Invocation.Builder) UmaPermission(org.gluu.oxauth.model.uma.UmaPermission) IOException(java.io.IOException) IOException(java.io.IOException) BaseTest(org.gluu.oxauth.BaseTest) Test(org.testng.annotations.Test)

Aggregations

UmaPermission (org.gluu.oxauth.model.uma.UmaPermission)7 PermissionTicket (org.gluu.oxauth.model.uma.PermissionTicket)5 BaseTest (org.gluu.oxauth.BaseTest)4 Test (org.testng.annotations.Test)4 Response (javax.ws.rs.core.Response)2 IOException (java.io.IOException)1 LinkedList (java.util.LinkedList)1 ClientErrorException (javax.ws.rs.ClientErrorException)1 Builder (javax.ws.rs.client.Invocation.Builder)1 HttpResponse (org.apache.http.HttpResponse)1 RptIntrospectionResponse (org.gluu.oxauth.model.uma.RptIntrospectionResponse)1 UmaResourceResponse (org.gluu.oxauth.model.uma.UmaResourceResponse)1 Pair (org.gluu.util.Pair)1 ResteasyClientBuilder (org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder)1 Parameters (org.testng.annotations.Parameters)1