use of io.gravitee.am.service.model.NewRole in project gravitee-access-management by gravitee-io.
the class RolesResource method create.
@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Create a role", notes = "User must have the DOMAIN_ROLE[CREATE] permission on the specified domain " + "or DOMAIN_ROLE[CREATE] permission on the specified environment " + "or DOMAIN_ROLE[CREATE] permission on the specified organization")
@ApiResponses({ @ApiResponse(code = 201, message = "Role successfully created"), @ApiResponse(code = 500, message = "Internal server error") })
public void create(@PathParam("organizationId") String organizationId, @PathParam("environmentId") String environmentId, @PathParam("domain") String domain, @ApiParam(name = "role", required = true) @Valid @NotNull final NewRole newRole, @Suspended final AsyncResponse response) {
final User authenticatedUser = getAuthenticatedUser();
checkAnyPermission(organizationId, environmentId, domain, Permission.DOMAIN_ROLE, Acl.CREATE).andThen(domainService.findById(domain).switchIfEmpty(Maybe.error(new DomainNotFoundException(domain))).flatMapSingle(irrelevant -> roleService.create(domain, newRole, authenticatedUser).map(role -> Response.created(URI.create("/organizations/" + organizationId + "/environments/" + environmentId + "/domains/" + domain + "/roles/" + role.getId())).entity(role).build()))).subscribe(response::resume, response::resume);
}
Aggregations