use of org.gluu.oxauth.model.uma.UmaPermissionList 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.");
}
}
use of org.gluu.oxauth.model.uma.UmaPermissionList in project oxAuth by GluuFederation.
the class UmaPermissionRegistrationWS method parseRequest.
/**
* UMA2 spec (edit 4) defined to possible requests, single permission or list of permission. So here we parse manually
*
* @param requestAsString request as string
* @return uma permission list
*/
private UmaPermissionList parseRequest(String requestAsString) {
final ObjectMapper mapper = ServerUtil.createJsonMapper().configure(SerializationFeature.WRAP_ROOT_VALUE, false);
try {
org.gluu.oxauth.model.uma.UmaPermission permission = mapper.readValue(requestAsString, org.gluu.oxauth.model.uma.UmaPermission.class);
return new UmaPermissionList().addPermission(permission);
} catch (IOException e) {
// ignore
}
try {
UmaPermissionList permissions = mapper.readValue(requestAsString, org.gluu.oxauth.model.uma.UmaPermissionList.class);
if (!permissions.isEmpty()) {
return permissions;
}
log.error("Permission list is empty.");
} catch (IOException e) {
log.error("Failed to parse uma permission request" + requestAsString, e);
}
throw errorResponseFactory.createWebApplicationException(Response.Status.BAD_REQUEST, UmaErrorResponseType.INVALID_PERMISSION_REQUEST, "Failed to parse uma permission request.");
}
Aggregations