Search in sources :

Example 6 with NewRole

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);
}
Also used : Role(io.gravitee.am.model.Role) 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) Single(io.reactivex.Single) Valid(javax.validation.Valid) Acl(io.gravitee.am.model.Acl) User(io.gravitee.am.identityprovider.api.User) NewRole(io.gravitee.am.service.model.NewRole) io.swagger.annotations(io.swagger.annotations) URI(java.net.URI) RoleService(io.gravitee.am.service.RoleService) Page(io.gravitee.am.model.common.Page) Context(javax.ws.rs.core.Context) 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) Comparator(java.util.Comparator) User(io.gravitee.am.identityprovider.api.User) DomainNotFoundException(io.gravitee.am.service.exception.DomainNotFoundException)

Aggregations

Role (io.gravitee.am.model.Role)6 NewRole (io.gravitee.am.service.model.NewRole)6 DefaultRole (io.gravitee.am.model.permissions.DefaultRole)4 UpdateRole (io.gravitee.am.service.model.UpdateRole)4 Test (org.junit.Test)4 TestObserver (io.reactivex.observers.TestObserver)3 User (io.gravitee.am.identityprovider.api.User)2 Acl (io.gravitee.am.model.Acl)2 Page (io.gravitee.am.model.common.Page)2 Event (io.gravitee.am.model.common.event.Event)2 Permission (io.gravitee.am.model.permissions.Permission)2 RoleService (io.gravitee.am.service.RoleService)2 Collectors (java.util.stream.Collectors)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 EventType (io.gravitee.am.common.audit.EventType)1 Action (io.gravitee.am.common.event.Action)1 Type (io.gravitee.am.common.event.Type)1 RandomString (io.gravitee.am.common.utils.RandomString)1 JerseySpringTest (io.gravitee.am.management.handlers.management.api.JerseySpringTest)1 AbstractResource (io.gravitee.am.management.handlers.management.api.resources.AbstractResource)1