Search in sources :

Example 16 with Permission

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);
}
Also used : UserService(io.gravitee.am.management.service.UserService) PathParam(javax.ws.rs.PathParam) Produces(javax.ws.rs.Produces) Permission(io.gravitee.am.model.permissions.Permission) Maybe(io.reactivex.Maybe) DomainService(io.gravitee.am.service.DomainService) Autowired(org.springframework.beans.factory.annotation.Autowired) AbstractResource(io.gravitee.am.management.handlers.management.api.resources.AbstractResource) ApiResponses(io.swagger.annotations.ApiResponses) Single(io.reactivex.Single) ArrayList(java.util.ArrayList) io.gravitee.am.service.exception(io.gravitee.am.service.exception) Acl(io.gravitee.am.model.Acl) ApiOperation(io.swagger.annotations.ApiOperation) ReferenceType(io.gravitee.am.model.ReferenceType) GroupService(io.gravitee.am.service.GroupService) DELETE(javax.ws.rs.DELETE) POST(javax.ws.rs.POST) Permissions.of(io.gravitee.am.management.service.permissions.Permissions.of) AsyncResponse(javax.ws.rs.container.AsyncResponse) UpdateGroup(io.gravitee.am.service.model.UpdateGroup) Suspended(javax.ws.rs.container.Suspended) List(java.util.List) MediaType(io.gravitee.common.http.MediaType) Response(javax.ws.rs.core.Response) ApiResponse(io.swagger.annotations.ApiResponse) Permissions.or(io.gravitee.am.management.service.permissions.Permissions.or) ArrayList(java.util.ArrayList) PathParam(javax.ws.rs.PathParam) ArrayList(java.util.ArrayList) List(java.util.List) UpdateGroup(io.gravitee.am.service.model.UpdateGroup) DELETE(javax.ws.rs.DELETE) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 17 with Permission

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);
}
Also used : ReporterServiceProxy(io.gravitee.am.management.service.ReporterServiceProxy) Permission(io.gravitee.am.model.permissions.Permission) Maybe(io.reactivex.Maybe) DomainService(io.gravitee.am.service.DomainService) Autowired(org.springframework.beans.factory.annotation.Autowired) AbstractResource(io.gravitee.am.management.handlers.management.api.resources.AbstractResource) ApiResponses(io.swagger.annotations.ApiResponses) Single(io.reactivex.Single) NewReporter(io.gravitee.am.service.model.NewReporter) Acl(io.gravitee.am.model.Acl) ApiOperation(io.swagger.annotations.ApiOperation) User(io.gravitee.am.identityprovider.api.User) Api(io.swagger.annotations.Api) URI(java.net.URI) Context(javax.ws.rs.core.Context) AsyncResponse(javax.ws.rs.container.AsyncResponse) Reporter(io.gravitee.am.model.Reporter) DomainNotFoundException(io.gravitee.am.service.exception.DomainNotFoundException) Suspended(javax.ws.rs.container.Suspended) Collectors(java.util.stream.Collectors) MediaType(io.gravitee.common.http.MediaType) javax.ws.rs(javax.ws.rs) Response(javax.ws.rs.core.Response) ApiResponse(io.swagger.annotations.ApiResponse) ResourceContext(javax.ws.rs.container.ResourceContext) User(io.gravitee.am.identityprovider.api.User) DomainNotFoundException(io.gravitee.am.service.exception.DomainNotFoundException) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 18 with Permission

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);
}
Also used : Role(io.gravitee.am.model.Role) Permission(io.gravitee.am.model.permissions.Permission) Maybe(io.reactivex.Maybe) RoleEntity(io.gravitee.am.management.handlers.management.api.model.RoleEntity) DomainService(io.gravitee.am.service.DomainService) ApiParam(io.swagger.annotations.ApiParam) Autowired(org.springframework.beans.factory.annotation.Autowired) AbstractResource(io.gravitee.am.management.handlers.management.api.resources.AbstractResource) ApiResponses(io.swagger.annotations.ApiResponses) Valid(javax.validation.Valid) Acl(io.gravitee.am.model.Acl) ApiOperation(io.swagger.annotations.ApiOperation) User(io.gravitee.am.identityprovider.api.User) ReferenceType(io.gravitee.am.model.ReferenceType) RoleService(io.gravitee.am.service.RoleService) Context(javax.ws.rs.core.Context) AsyncResponse(javax.ws.rs.container.AsyncResponse) DomainNotFoundException(io.gravitee.am.service.exception.DomainNotFoundException) RoleNotFoundException(io.gravitee.am.service.exception.RoleNotFoundException) NotNull(javax.validation.constraints.NotNull) Suspended(javax.ws.rs.container.Suspended) UpdateRole(io.gravitee.am.service.model.UpdateRole) MediaType(io.gravitee.common.http.MediaType) javax.ws.rs(javax.ws.rs) Response(javax.ws.rs.core.Response) ApiResponse(io.swagger.annotations.ApiResponse) ResourceContext(javax.ws.rs.container.ResourceContext) User(io.gravitee.am.identityprovider.api.User) DomainNotFoundException(io.gravitee.am.service.exception.DomainNotFoundException) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 19 with Permission

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);
}
Also used : Context(javax.ws.rs.core.Context) NewBotDetection(io.gravitee.am.service.model.NewBotDetection) AsyncResponse(javax.ws.rs.container.AsyncResponse) Permission(io.gravitee.am.model.permissions.Permission) Maybe(io.reactivex.Maybe) BotDetectionServiceProxy(io.gravitee.am.management.service.BotDetectionServiceProxy) DomainService(io.gravitee.am.service.DomainService) Autowired(org.springframework.beans.factory.annotation.Autowired) AbstractResource(io.gravitee.am.management.handlers.management.api.resources.AbstractResource) DomainNotFoundException(io.gravitee.am.service.exception.DomainNotFoundException) NotNull(javax.validation.constraints.NotNull) Suspended(javax.ws.rs.container.Suspended) Valid(javax.validation.Valid) Acl(io.gravitee.am.model.Acl) MediaType(io.gravitee.common.http.MediaType) javax.ws.rs(javax.ws.rs) Response(javax.ws.rs.core.Response) User(io.gravitee.am.identityprovider.api.User) ResourceContext(javax.ws.rs.container.ResourceContext) io.swagger.annotations(io.swagger.annotations) URI(java.net.URI) BotDetection(io.gravitee.am.model.BotDetection) User(io.gravitee.am.identityprovider.api.User) DomainNotFoundException(io.gravitee.am.service.exception.DomainNotFoundException)

Example 20 with Permission

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);
}
Also used : Certificate(io.gravitee.am.model.Certificate) Json(io.vertx.core.json.Json) CertificateServiceProxy(io.gravitee.am.management.service.CertificateServiceProxy) Permission(io.gravitee.am.model.permissions.Permission) Maybe(io.reactivex.Maybe) DomainService(io.gravitee.am.service.DomainService) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) AbstractResource(io.gravitee.am.management.handlers.management.api.resources.AbstractResource) InitializingBean(org.springframework.beans.factory.InitializingBean) Value(org.springframework.beans.factory.annotation.Value) Valid(javax.validation.Valid) Acl(io.gravitee.am.model.Acl) User(io.gravitee.am.identityprovider.api.User) CertificateStatus(io.gravitee.am.management.handlers.management.api.model.CertificateStatus) io.swagger.annotations(io.swagger.annotations) JsonObject(io.vertx.core.json.JsonObject) CertificateEntity(io.gravitee.am.management.handlers.management.api.model.CertificateEntity) URI(java.net.URI) Context(javax.ws.rs.core.Context) AsyncResponse(javax.ws.rs.container.AsyncResponse) DomainNotFoundException(io.gravitee.am.service.exception.DomainNotFoundException) NotNull(javax.validation.constraints.NotNull) Instant(java.time.Instant) Suspended(javax.ws.rs.container.Suspended) NewCertificate(io.gravitee.am.service.model.NewCertificate) MediaType(io.gravitee.common.http.MediaType) ChronoUnit(java.time.temporal.ChronoUnit) javax.ws.rs(javax.ws.rs) Response(javax.ws.rs.core.Response) Environment(org.springframework.core.env.Environment) ResourceContext(javax.ws.rs.container.ResourceContext) StringUtils(org.springframework.util.StringUtils) User(io.gravitee.am.identityprovider.api.User) DomainNotFoundException(io.gravitee.am.service.exception.DomainNotFoundException)

Aggregations

Permission (io.gravitee.am.model.permissions.Permission)56 Acl (io.gravitee.am.model.Acl)49 AsyncResponse (javax.ws.rs.container.AsyncResponse)49 Suspended (javax.ws.rs.container.Suspended)49 Autowired (org.springframework.beans.factory.annotation.Autowired)49 User (io.gravitee.am.identityprovider.api.User)47 MediaType (io.gravitee.common.http.MediaType)47 AbstractResource (io.gravitee.am.management.handlers.management.api.resources.AbstractResource)44 Response (javax.ws.rs.core.Response)41 javax.ws.rs (javax.ws.rs)40 Maybe (io.reactivex.Maybe)39 ResourceContext (javax.ws.rs.container.ResourceContext)39 Context (javax.ws.rs.core.Context)39 DomainService (io.gravitee.am.service.DomainService)38 DomainNotFoundException (io.gravitee.am.service.exception.DomainNotFoundException)37 Valid (javax.validation.Valid)36 NotNull (javax.validation.constraints.NotNull)36 ReferenceType (io.gravitee.am.model.ReferenceType)30 ApiOperation (io.swagger.annotations.ApiOperation)30 ApiResponses (io.swagger.annotations.ApiResponses)30