Search in sources :

Example 11 with User

use of io.gravitee.am.identityprovider.api.User in project gravitee-access-management by gravitee-io.

the class ApplicationsResource method createApplication.

@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Create an application", notes = "User must have APPLICATION[CREATE] permission on the specified domain " + "or APPLICATION[CREATE] permission on the specified environment " + "or APPLICATION[CREATE] permission on the specified organization")
@ApiResponses({ @ApiResponse(code = 201, message = "Application successfully created"), @ApiResponse(code = 500, message = "Internal server error") })
public void createApplication(@PathParam("organizationId") String organizationId, @PathParam("environmentId") String environmentId, @PathParam("domain") String domain, @ApiParam(name = "application", required = true) @Valid @NotNull final NewApplication newApplication, @Suspended final AsyncResponse response) {
    final User authenticatedUser = getAuthenticatedUser();
    checkAnyPermission(organizationId, environmentId, domain, Permission.APPLICATION, Acl.CREATE).andThen(domainService.findById(domain).switchIfEmpty(Maybe.error(new DomainNotFoundException(domain))).flatMapSingle(__ -> applicationService.create(domain, newApplication, authenticatedUser).map(application -> Response.created(URI.create("/organizations/" + organizationId + "/environments/" + environmentId + "/domains/" + domain + "/applications/" + application.getId())).entity(application).build()))).subscribe(response::resume, response::resume);
}
Also used : ApplicationService(io.gravitee.am.service.ApplicationService) Permission(io.gravitee.am.model.permissions.Permission) Maybe(io.reactivex.Maybe) DomainService(io.gravitee.am.service.DomainService) Autowired(org.springframework.beans.factory.annotation.Autowired) Application(io.gravitee.am.model.Application) AbstractResource(io.gravitee.am.management.handlers.management.api.resources.AbstractResource) Valid(javax.validation.Valid) Acl(io.gravitee.am.model.Acl) Flowable(io.reactivex.Flowable) User(io.gravitee.am.identityprovider.api.User) ReferenceType(io.gravitee.am.model.ReferenceType) io.swagger.annotations(io.swagger.annotations) URI(java.net.URI) Page(io.gravitee.am.model.common.Page) Context(javax.ws.rs.core.Context) Permissions.of(io.gravitee.am.management.service.permissions.Permissions.of) NewApplication(io.gravitee.am.service.model.NewApplication) AsyncResponse(javax.ws.rs.container.AsyncResponse) DomainNotFoundException(io.gravitee.am.service.exception.DomainNotFoundException) NotNull(javax.validation.constraints.NotNull) Suspended(javax.ws.rs.container.Suspended) Collectors(java.util.stream.Collectors) List(java.util.List) MediaType(io.gravitee.common.http.MediaType) javax.ws.rs(javax.ws.rs) Response(javax.ws.rs.core.Response) ResourceContext(javax.ws.rs.container.ResourceContext) Permissions.or(io.gravitee.am.management.service.permissions.Permissions.or) User(io.gravitee.am.identityprovider.api.User) DomainNotFoundException(io.gravitee.am.service.exception.DomainNotFoundException)

Example 12 with User

use of io.gravitee.am.identityprovider.api.User in project gravitee-access-management by gravitee-io.

the class ApplicationsResource method list.

@GET
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "List registered applications for a security domain", notes = "User must have the APPLICATION[LIST] permission on the specified domain, environment or organization " + "AND either APPLICATION[READ] permission on each domain's application " + "or APPLICATION[READ] permission on the specified domain " + "or APPLICATION[READ] permission on the specified environment " + "or APPLICATION[READ] permission on the specified organization. " + "Each returned application is filtered and contains only basic information such as id, name, description and isEnabled.")
@ApiResponses({ @ApiResponse(code = 200, message = "List registered applications for a security domain", response = Application.class, responseContainer = "List"), @ApiResponse(code = 500, message = "Internal server error") })
public void list(@PathParam("organizationId") String organizationId, @PathParam("environmentId") String environmentId, @PathParam("domain") String domain, @QueryParam("page") @DefaultValue("0") int page, @QueryParam("size") @DefaultValue(MAX_APPLICATIONS_SIZE_PER_PAGE_STRING) int size, @QueryParam("q") String query, @Suspended final AsyncResponse response) {
    final User authenticatedUser = getAuthenticatedUser();
    checkAnyPermission(organizationId, environmentId, domain, Permission.APPLICATION, Acl.LIST).andThen(domainService.findById(domain).switchIfEmpty(Maybe.error(new DomainNotFoundException(domain))).flatMapSingle(__ -> {
        if (query != null) {
            return applicationService.search(domain, query, 0, Integer.MAX_VALUE);
        } else {
            return applicationService.findByDomain(domain, 0, Integer.MAX_VALUE);
        }
    }).flatMap(pagedApplications -> Maybe.concat(pagedApplications.getData().stream().map(application -> hasAnyPermission(authenticatedUser, organizationId, environmentId, domain, application.getId(), Permission.APPLICATION, Acl.READ).filter(Boolean::booleanValue).map(__ -> filterApplicationInfos(application))).collect(Collectors.toList())).sorted((a1, a2) -> a2.getUpdatedAt().compareTo(a1.getUpdatedAt())).toList().map(applications -> new Page<>(applications.stream().skip(page * size).limit(size).collect(Collectors.toList()), page, applications.size())))).subscribe(response::resume, response::resume);
}
Also used : ApplicationService(io.gravitee.am.service.ApplicationService) Permission(io.gravitee.am.model.permissions.Permission) Maybe(io.reactivex.Maybe) DomainService(io.gravitee.am.service.DomainService) Autowired(org.springframework.beans.factory.annotation.Autowired) Application(io.gravitee.am.model.Application) AbstractResource(io.gravitee.am.management.handlers.management.api.resources.AbstractResource) Valid(javax.validation.Valid) Acl(io.gravitee.am.model.Acl) Flowable(io.reactivex.Flowable) User(io.gravitee.am.identityprovider.api.User) ReferenceType(io.gravitee.am.model.ReferenceType) io.swagger.annotations(io.swagger.annotations) URI(java.net.URI) Page(io.gravitee.am.model.common.Page) Context(javax.ws.rs.core.Context) Permissions.of(io.gravitee.am.management.service.permissions.Permissions.of) NewApplication(io.gravitee.am.service.model.NewApplication) AsyncResponse(javax.ws.rs.container.AsyncResponse) DomainNotFoundException(io.gravitee.am.service.exception.DomainNotFoundException) NotNull(javax.validation.constraints.NotNull) Suspended(javax.ws.rs.container.Suspended) Collectors(java.util.stream.Collectors) List(java.util.List) MediaType(io.gravitee.common.http.MediaType) javax.ws.rs(javax.ws.rs) Response(javax.ws.rs.core.Response) ResourceContext(javax.ws.rs.container.ResourceContext) Permissions.or(io.gravitee.am.management.service.permissions.Permissions.or) User(io.gravitee.am.identityprovider.api.User) DomainNotFoundException(io.gravitee.am.service.exception.DomainNotFoundException) Page(io.gravitee.am.model.common.Page)

Example 13 with User

use of io.gravitee.am.identityprovider.api.User in project gravitee-access-management by gravitee-io.

the class AuthenticationDeviceNotifiersResource method create.

@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Create an Authentication Device Notifier", notes = "User must have the DOMAIN_AUTHDEVICE_NOTIFIER[CREATE] permission on the specified domain " + "or DOMAIN_AUTHDEVICE_NOTIFIER[CREATE] permission on the specified environment " + "or DOMAIN_AUTHDEVICE_NOTIFIER[CREATE] permission on the specified organization")
@ApiResponses({ @ApiResponse(code = 201, message = "Authentication Device Notifier 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 = "notifier", required = true) @Valid @NotNull final NewAuthenticationDeviceNotifier newDeviceNotifier, @Suspended final AsyncResponse response) {
    final User authenticatedUser = getAuthenticatedUser();
    checkAnyPermission(organizationId, environmentId, domain, Permission.DOMAIN_AUTHDEVICE_NOTIFIER, Acl.CREATE).andThen(domainService.findById(domain).switchIfEmpty(Maybe.error(new DomainNotFoundException(domain))).flatMapSingle(__ -> authDeviceNotifierService.create(domain, newDeviceNotifier, authenticatedUser)).map(deviceNotifier -> Response.created(URI.create("/organizations/" + organizationId + "/environments/" + environmentId + "/domains/" + domain + "/auth-device-notifiers/" + deviceNotifier.getId())).entity(deviceNotifier).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) 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) AuthenticationDeviceNotifier(io.gravitee.am.model.AuthenticationDeviceNotifier) Suspended(javax.ws.rs.container.Suspended) Valid(javax.validation.Valid) Acl(io.gravitee.am.model.Acl) AuthenticationDeviceNotifierService(io.gravitee.am.service.AuthenticationDeviceNotifierService) 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) NewAuthenticationDeviceNotifier(io.gravitee.am.service.model.NewAuthenticationDeviceNotifier) 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 14 with User

use of io.gravitee.am.identityprovider.api.User in project gravitee-access-management by gravitee-io.

the class BotDetectionResource method delete.

@DELETE
@ApiOperation(value = "Delete a bot detection", notes = "User must have the DOMAIN_BOT_DETECTION[DELETE] permission on the specified domain " + "or DOMAIN_BOT_DETECTION[DELETE] permission on the specified environment " + "or DOMAIN_BOT_DETECTION[DELETE] permission on the specified organization")
@ApiResponses({ @ApiResponse(code = 204, message = "Bot detection successfully deleted"), @ApiResponse(code = 500, message = "Internal server error") })
public void delete(@PathParam("organizationId") String organizationId, @PathParam("environmentId") String environmentId, @PathParam("domain") String domain, @PathParam("botDetection") String botDetectionId, @Suspended final AsyncResponse response) {
    final User authenticatedUser = getAuthenticatedUser();
    checkAnyPermission(organizationId, environmentId, domain, Permission.DOMAIN_BOT_DETECTION, Acl.DELETE).andThen(botDetectionService.delete(domain, botDetectionId, authenticatedUser)).subscribe(() -> response.resume(Response.noContent().build()), response::resume);
}
Also used : User(io.gravitee.am.identityprovider.api.User) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 15 with User

use of io.gravitee.am.identityprovider.api.User in project gravitee-access-management by gravitee-io.

the class BotDetectionResource method update.

@PUT
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Update a bot detection", notes = "User must have the DOMAIN_BOT_DETECTION[UPDATE] permission on the specified domain " + "or DOMAIN_BOT_DETECTION[UPDATE] permission on the specified environment " + "or DOMAIN_BOT_DETECTION[UPDATE] permission on the specified organization")
@ApiResponses({ @ApiResponse(code = 201, message = "Bot detection successfully updated", response = BotDetection.class), @ApiResponse(code = 500, message = "Internal server error") })
public void update(@PathParam("organizationId") String organizationId, @PathParam("environmentId") String environmentId, @PathParam("domain") String domain, @PathParam("botDetection") String botDetection, @ApiParam(name = "identity", required = true) @Valid @NotNull UpdateBotDetection updateBotDetection, @Suspended final AsyncResponse response) {
    final User authenticatedUser = getAuthenticatedUser();
    checkAnyPermission(organizationId, environmentId, domain, Permission.DOMAIN_BOT_DETECTION, Acl.UPDATE).andThen(domainService.findById(domain).switchIfEmpty(Maybe.error(new DomainNotFoundException(domain))).flatMapSingle(__ -> botDetectionService.update(domain, botDetection, updateBotDetection, authenticatedUser))).subscribe(response::resume, response::resume);
}
Also used : User(io.gravitee.am.identityprovider.api.User) DomainNotFoundException(io.gravitee.am.service.exception.DomainNotFoundException) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

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