use of io.gravitee.am.model.permissions.Permission in project gravitee-access-management by gravitee-io.
the class GroupMemberResource method removeMember.
@DELETE
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Remove a group member", notes = "User must have the DOMAIN_GROUP[UPDATE] permission on the specified domain " + "or DOMAIN_GROUP[UPDATE] permission on the specified environment " + "or DOMAIN_GROUP[UPDATE] permission on the specified organization")
@ApiResponses({ @ApiResponse(code = 200, message = "Member has been removed successfully"), @ApiResponse(code = 400, message = "User does not exist"), @ApiResponse(code = 500, message = "Internal server error") })
public void removeMember(@PathParam("organizationId") String organizationId, @PathParam("environmentId") String environmentId, @PathParam("domain") String domain, @PathParam("group") String group, @PathParam("member") String userId, @Suspended final AsyncResponse response) {
final io.gravitee.am.identityprovider.api.User authenticatedUser = getAuthenticatedUser();
checkAnyPermission(organizationId, environmentId, domain, Permission.DOMAIN_GROUP, Acl.UPDATE).andThen(domainService.findById(domain).switchIfEmpty(Maybe.error(new DomainNotFoundException(domain))).flatMap(__ -> groupService.findById(group)).switchIfEmpty(Maybe.error(new GroupNotFoundException(group))).flatMapSingle(group1 -> userService.findById(userId).switchIfEmpty(Maybe.error(new UserNotFoundException(userId))).flatMapSingle(user -> {
if (group1.getMembers() == null || !group1.getMembers().contains(userId)) {
return Single.error(new MemberNotFoundException(userId));
}
List<String> groupMembers = group1.getMembers() != null ? new ArrayList<>(group1.getMembers()) : new ArrayList<>();
groupMembers.remove(userId);
UpdateGroup updateGroup = new UpdateGroup();
updateGroup.setName(group1.getName());
updateGroup.setDescription(group1.getDescription());
updateGroup.setRoles(group1.getRoles());
updateGroup.setMembers(groupMembers);
return groupService.update(domain, group, updateGroup, authenticatedUser);
}))).subscribe(response::resume, response::resume);
}
use of io.gravitee.am.model.permissions.Permission in project gravitee-access-management by gravitee-io.
the class ReportersResource method create.
@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Create a reporter for a security domain", notes = "User must have the DOMAIN_REPORTER[CREATE] permission on the specified domain " + "or DOMAIN_REPORTER[CREATE] permission on the specified environment " + "or DOMAIN_REPORTER[CREATE] permission on the specified organization.")
@ApiResponses({ @ApiResponse(code = 201, message = "Reporter created for a security domain", response = Reporter.class), @ApiResponse(code = 500, message = "Internal server error") })
public void create(@PathParam("organizationId") String organizationId, @PathParam("environmentId") String environmentId, @PathParam("domain") String domain, NewReporter newReporter, @Suspended final AsyncResponse response) {
User authenticatedUser = getAuthenticatedUser();
checkAnyPermission(organizationId, environmentId, domain, Permission.DOMAIN_REPORTER, Acl.CREATE).andThen(domainService.findById(domain).switchIfEmpty(Maybe.error(new DomainNotFoundException(domain))).flatMapSingle(irrelevant -> reporterService.create(domain, newReporter, authenticatedUser, false)).map(reporter -> response.resume(Response.created(URI.create("/organizations/" + organizationId + "/environments/" + environmentId + "/domains/" + domain + "/reporters/" + reporter.getId())).entity(reporter).build()))).subscribe(response::resume, response::resume);
}
use of io.gravitee.am.model.permissions.Permission in project gravitee-access-management by gravitee-io.
the class RoleResource method update.
@PUT
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Update a role", notes = "User must have the DOMAIN_ROLE[UPDATE] permission on the specified domain " + "or DOMAIN_ROLE[UPDATE] permission on the specified environment " + "or DOMAIN_ROLE[UPDATE] permission on the specified organization")
@ApiResponses({ @ApiResponse(code = 201, message = "Role successfully updated", response = RoleEntity.class), @ApiResponse(code = 500, message = "Internal server error") })
public void update(@PathParam("organizationId") String organizationId, @PathParam("environmentId") String environmentId, @PathParam("domain") String domain, @PathParam("role") String role, @ApiParam(name = "role", required = true) @Valid @NotNull UpdateRole updateRole, @Suspended final AsyncResponse response) {
final User authenticatedUser = getAuthenticatedUser();
checkAnyPermission(organizationId, environmentId, domain, Permission.DOMAIN_ROLE, Acl.UPDATE).andThen(domainService.findById(domain).switchIfEmpty(Maybe.error(new DomainNotFoundException(domain))).flatMapSingle(irrelevant -> roleService.update(domain, role, convert(updateRole), authenticatedUser)).map(this::convert)).subscribe(response::resume, response::resume);
}
use of io.gravitee.am.model.permissions.Permission in project gravitee-access-management by gravitee-io.
the class BotDetectionsResource method create.
@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Create a bot detection", notes = "User must have the DOMAIN_BOT_DETECTION[CREATE] permission on the specified domain " + "or DOMAIN_BOT_DETECTION[CREATE] permission on the specified environment " + "or DOMAIN_BOT_DETECTION[CREATE] permission on the specified organization")
@ApiResponses({ @ApiResponse(code = 201, message = "Bot detection 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 = "detection", required = true) @Valid @NotNull final NewBotDetection newBotDetection, @Suspended final AsyncResponse response) {
final User authenticatedUser = getAuthenticatedUser();
checkAnyPermission(organizationId, environmentId, domain, Permission.DOMAIN_BOT_DETECTION, Acl.CREATE).andThen(domainService.findById(domain).switchIfEmpty(Maybe.error(new DomainNotFoundException(domain))).flatMapSingle(__ -> botDetectionService.create(domain, newBotDetection, authenticatedUser)).map(botDetection -> Response.created(URI.create("/organizations/" + organizationId + "/environments/" + environmentId + "/domains/" + domain + "/bot-detections/" + botDetection.getId())).entity(botDetection).build())).subscribe(response::resume, response::resume);
}
use of io.gravitee.am.model.permissions.Permission in project gravitee-access-management by gravitee-io.
the class CertificatesResource method create.
@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Create a certificate", notes = "User must have the DOMAIN_CERTIFICATE[CREATE] permission on the specified domain " + "or DOMAIN_CERTIFICATE[CREATE] permission on the specified environment " + "or DOMAIN_CERTIFICATE[CREATE] permission on the specified organization")
@ApiResponses({ @ApiResponse(code = 201, message = "Certificate 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 = "certificate", required = true) @Valid @NotNull final NewCertificate newCertificate, @Suspended final AsyncResponse response) {
final User authenticatedUser = getAuthenticatedUser();
checkAnyPermission(organizationId, environmentId, domain, Permission.DOMAIN_CERTIFICATE, Acl.CREATE).andThen(domainService.findById(domain).switchIfEmpty(Maybe.error(new DomainNotFoundException(domain))).flatMapSingle(schema -> certificateService.create(domain, newCertificate, authenticatedUser)).map(certificate -> Response.created(URI.create("/organizations/" + organizationId + "/environments/" + environmentId + "/domains/" + domain + "/certificates/" + certificate.getId())).entity(certificate).build())).subscribe(response::resume, response::resume);
}
Aggregations