Search in sources :

Example 1 with PermissionTicket

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

the class RegisterPermissionWSTest method testRegisterPermission.

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

Example 2 with PermissionTicket

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

the class UmaRegisterPermissionFlowHttpTest method registerResourcePermission.

public String registerResourcePermission(String resourceId, List<String> scopes) throws Exception {
    UmaPermission permission = new UmaPermission();
    permission.setResourceId(resourceId);
    permission.setScopes(scopes);
    PermissionTicket ticket = getPermissionService().registerPermission("Bearer " + this.registerResourceTest.pat.getAccessToken(), UmaPermissionList.instance(permission));
    UmaTestUtil.assert_(ticket);
    this.ticket = ticket.getTicket();
    return ticket.getTicket();
}
Also used : PermissionTicket(org.gluu.oxauth.model.uma.PermissionTicket) UmaPermission(org.gluu.oxauth.model.uma.UmaPermission)

Example 3 with PermissionTicket

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

the class UmaPermissionService method registerResourcePermission.

public String registerResourcePermission(Token patToken, String resourceId, List<String> scopes) {
    // TODO: Added this if as a hack since init method is not called upon app startup in scim project
    if (permissionService == null) {
        init(null);
    }
    // end
    UmaPermission permission = new UmaPermission();
    permission.setResourceId(resourceId);
    permission.setScopes(scopes);
    PermissionTicket ticket = permissionService.registerPermission("Bearer " + patToken.getAccessToken(), UmaPermissionList.instance(permission));
    if (ticket == null) {
        return null;
    }
    return ticket.getTicket();
}
Also used : PermissionTicket(org.gluu.oxauth.model.uma.PermissionTicket) UmaPermission(org.gluu.oxauth.model.uma.UmaPermission)

Example 4 with PermissionTicket

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

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

the class UmaPermissionRegistrationWS method registerPermission.

@POST
@Consumes({ UmaConstants.JSON_MEDIA_TYPE })
@Produces({ UmaConstants.JSON_MEDIA_TYPE })
public Response registerPermission(@Context HttpServletRequest request, @HeaderParam("Authorization") String authorization, String requestAsString) {
    try {
        final AuthorizationGrant authorizationGrant = umaValidationService.assertHasProtectionScope(authorization);
        // UMA2 spec defined 2 possible requests, single permission or list of permission. So here we parse manually
        UmaPermissionList permissionList = parseRequest(requestAsString);
        umaValidationService.validatePermissions(permissionList, authorizationGrant.getClient());
        String ticket = permissionService.addPermission(permissionList, tokenService.getClientDn(authorization));
        return Response.status(Response.Status.CREATED).type(MediaType.APPLICATION_JSON_TYPE).entity(new PermissionTicket(ticket)).build();
    } catch (Exception ex) {
        if (ex instanceof WebApplicationException) {
            throw (WebApplicationException) ex;
        }
        log.error("Exception happened", ex);
        throw errorResponseFactory.createWebApplicationException(Response.Status.INTERNAL_SERVER_ERROR, UmaErrorResponseType.SERVER_ERROR, "Internal error.");
    }
}
Also used : PermissionTicket(org.gluu.oxauth.model.uma.PermissionTicket) UmaPermissionList(org.gluu.oxauth.model.uma.UmaPermissionList) AuthorizationGrant(org.gluu.oxauth.model.common.AuthorizationGrant) IOException(java.io.IOException)

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