Search in sources :

Example 11 with UmaPermission

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

the class RegisterPermissionWSTest method testRegisterPermissionWithInvalidResourceSet.

@Test(dependsOnMethods = { "testRegisterPermission" })
@Parameters({ "umaAmHost", "umaHost" })
public void testRegisterPermissionWithInvalidResourceSet(final String umaAmHost, String umaHost) {
    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());
        request.header("Host", umaAmHost);
        String json = null;
        try {
            final UmaPermission r = new UmaPermission();
            r.setResourceSetId(resourceSet.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.testRegisterPermissionWithInvalidResourceSet() : ", response, entity);
        assertEquals(response.getStatus(), Response.Status.BAD_REQUEST.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) ResourceSetResponse(org.xdi.oxauth.model.uma.ResourceSetResponse) PermissionTicket(org.xdi.oxauth.model.uma.PermissionTicket) ResteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder) Builder(javax.ws.rs.client.Invocation.Builder) UmaPermission(org.xdi.oxauth.model.uma.UmaPermission) IOException(java.io.IOException) IOException(java.io.IOException) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test) BaseTest(org.xdi.oxauth.BaseTest)

Example 12 with UmaPermission

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

the class RegisterPermissionWSTest method testRegisterPermission.

@Test(dependsOnMethods = { "init" })
@Parameters({ "umaAmHost", "umaHost" })
public void testRegisterPermission(final String umaAmHost, String umaHost) throws Exception {
    final UmaPermission r = new UmaPermission();
    r.setResourceSetId(resourceSet.getId());
    r.setScopes(Arrays.asList("http://photoz.example.com/dev/scopes/view"));
    final PermissionTicket ticket = TUma.registerPermission(url, pat, umaAmHost, umaHost, r, umaPermissionPath);
    UmaTestUtil.assert_(ticket);
}
Also used : PermissionTicket(org.xdi.oxauth.model.uma.PermissionTicket) UmaPermission(org.xdi.oxauth.model.uma.UmaPermission) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test) BaseTest(org.xdi.oxauth.BaseTest)

Example 13 with UmaPermission

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

the class TrustElevationWSTest method registerPermissionForRpt.

@Test(dependsOnMethods = { "init" })
@Parameters({ "umaAmHost", "umaHost", "umaPermissionPath" })
public void registerPermissionForRpt(final String umaAmHost, String umaHost, String umaPermissionPath) throws Exception {
    final UmaPermission r = new UmaPermission();
    r.setResourceSetId(resourceSet.getId());
    r.setScopes(Arrays.asList("http://photoz.example.com/dev/scopes/view"));
    ticket = TUma.registerPermission(url, pat, umaAmHost, umaHost, r, umaPermissionPath);
    UmaTestUtil.assert_(ticket);
}
Also used : UmaPermission(org.xdi.oxauth.model.uma.UmaPermission) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test) BaseTest(org.xdi.oxauth.BaseTest)

Example 14 with UmaPermission

use of org.xdi.oxauth.model.uma.UmaPermission in project oxTrust by GluuFederation.

the class UmaPermissionService method registerResourcePermission.

public String registerResourcePermission(Token patToken, String resourceId, List<String> scopeIds) {
    UmaPermission permission = new UmaPermission();
    permission.setResourceId(resourceId);
    permission.setScopes(scopeIds);
    PermissionTicket ticket = permissionService.registerPermission("Bearer " + patToken.getAccessToken(), UmaPermissionList.instance(permission));
    if (ticket == null) {
        return null;
    }
    return ticket.getTicket();
}
Also used : PermissionTicket(org.xdi.oxauth.model.uma.PermissionTicket) UmaPermission(org.xdi.oxauth.model.uma.UmaPermission)

Aggregations

UmaPermission (org.xdi.oxauth.model.uma.UmaPermission)14 PermissionTicket (org.xdi.oxauth.model.uma.PermissionTicket)6 Parameters (org.testng.annotations.Parameters)5 Test (org.testng.annotations.Test)5 BaseTest (org.xdi.oxauth.BaseTest)5 RptIntrospectionResponse (org.xdi.oxauth.model.uma.RptIntrospectionResponse)4 Response (javax.ws.rs.core.Response)3 ClientResponseFailure (org.jboss.resteasy.client.ClientResponseFailure)3 IOException (java.io.IOException)2 Date (java.util.Date)2 HttpResponse (org.apache.http.HttpResponse)2 PermissionRegistrationService (org.xdi.oxauth.client.uma.PermissionRegistrationService)2 Pair (org.xdi.util.Pair)2 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)1 ApiResponses (com.wordnik.swagger.annotations.ApiResponses)1 MalformedURLException (java.net.MalformedURLException)1 LinkedList (java.util.LinkedList)1 POST (javax.ws.rs.POST)1 Produces (javax.ws.rs.Produces)1 WebApplicationException (javax.ws.rs.WebApplicationException)1