Search in sources :

Example 6 with PermissionTicket

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

the class TRegisterPermission method registerPermission.

public PermissionTicket registerPermission(final Token p_pat, final UmaPermission p_request, String path) {
    final Holder<PermissionTicket> ticketH = new Holder<PermissionTicket>();
    Builder request = ResteasyClientBuilder.newClient().target(baseUri.toString() + path).request();
    request.header("Accept", UmaConstants.JSON_MEDIA_TYPE);
    request.header("Authorization", "Bearer " + p_pat.getAccessToken());
    String json = null;
    try {
        json = ServerUtil.createJsonMapper().writeValueAsString(p_request);
    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }
    Response response = request.post(Entity.json(json));
    String entity = response.readEntity(String.class);
    BaseTest.showResponse("UMA : TRegisterPermission.registerPermission() : ", response, entity);
    assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode(), "Unexpected response code.");
    try {
        final PermissionTicket t = ServerUtil.createJsonMapper().readValue(entity, PermissionTicket.class);
        UmaTestUtil.assert_(t);
        ticketH.setT(t);
    } catch (IOException e) {
        e.printStackTrace();
        fail();
    }
    return ticketH.getT();
}
Also used : Response(javax.ws.rs.core.Response) PermissionTicket(org.gluu.oxauth.model.uma.PermissionTicket) Holder(org.gluu.oxauth.model.common.Holder) ResteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder) Builder(javax.ws.rs.client.Invocation.Builder) IOException(java.io.IOException) IOException(java.io.IOException)

Example 7 with PermissionTicket

use of org.gluu.oxauth.model.uma.PermissionTicket 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

PermissionTicket (org.gluu.oxauth.model.uma.PermissionTicket)7 UmaPermission (org.gluu.oxauth.model.uma.UmaPermission)5 IOException (java.io.IOException)3 BaseTest (org.gluu.oxauth.BaseTest)3 Test (org.testng.annotations.Test)3 Builder (javax.ws.rs.client.Invocation.Builder)2 Response (javax.ws.rs.core.Response)2 ResteasyClientBuilder (org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder)2 ClientErrorException (javax.ws.rs.ClientErrorException)1 AuthorizationGrant (org.gluu.oxauth.model.common.AuthorizationGrant)1 Holder (org.gluu.oxauth.model.common.Holder)1 UmaPermissionList (org.gluu.oxauth.model.uma.UmaPermissionList)1 UmaResourceResponse (org.gluu.oxauth.model.uma.UmaResourceResponse)1