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);
}
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();
}
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();
}
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");
}
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.");
}
}
Aggregations