Search in sources :

Example 26 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 ORGANIZATION_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("group") String group, @PathParam("member") String userId, @Suspended final AsyncResponse response) {
    final io.gravitee.am.identityprovider.api.User authenticatedUser = getAuthenticatedUser();
    checkPermission(ReferenceType.ORGANIZATION, organizationId, Permission.ORGANIZATION_GROUP, Acl.UPDATE).andThen(groupService.findById(ReferenceType.ORGANIZATION, organizationId, group).flatMap(group1 -> userService.findById(ReferenceType.ORGANIZATION, organizationId, userId).flatMap(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(ReferenceType.ORGANIZATION, organizationId, group, updateGroup, authenticatedUser);
    }))).subscribe(response::resume, response::resume);
}
Also used : UserService(io.gravitee.am.management.service.UserService) PathParam(javax.ws.rs.PathParam) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) AsyncResponse(javax.ws.rs.container.AsyncResponse) Permission(io.gravitee.am.model.permissions.Permission) Autowired(org.springframework.beans.factory.annotation.Autowired) MemberAlreadyExistsException(io.gravitee.am.service.exception.MemberAlreadyExistsException) AbstractResource(io.gravitee.am.management.handlers.management.api.resources.AbstractResource) ApiResponses(io.swagger.annotations.ApiResponses) UpdateGroup(io.gravitee.am.service.model.UpdateGroup) Single(io.reactivex.Single) Suspended(javax.ws.rs.container.Suspended) ArrayList(java.util.ArrayList) Acl(io.gravitee.am.model.Acl) MemberNotFoundException(io.gravitee.am.service.exception.MemberNotFoundException) ApiOperation(io.swagger.annotations.ApiOperation) List(java.util.List) MediaType(io.gravitee.common.http.MediaType) ApiResponse(io.swagger.annotations.ApiResponse) ReferenceType(io.gravitee.am.model.ReferenceType) GroupService(io.gravitee.am.service.GroupService) DELETE(javax.ws.rs.DELETE) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) PathParam(javax.ws.rs.PathParam) MemberNotFoundException(io.gravitee.am.service.exception.MemberNotFoundException) 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 27 with Permission

use of io.gravitee.am.model.permissions.Permission in project gravitee-access-management by gravitee-io.

the class DomainsResource method get.

@GET
@Path("_hrid/{hrid}")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Get a security domain by hrid", notes = "User must have the DOMAIN[READ] permission on the specified domain, environment or organization. " + "Domain will be filtered according to permissions (READ on DOMAIN_USER_ACCOUNT, DOMAIN_IDENTITY_PROVIDER, DOMAIN_FORM, DOMAIN_LOGIN_SETTINGS, " + "DOMAIN_DCR, DOMAIN_SCIM, DOMAIN_SETTINGS)")
@ApiResponses({ @ApiResponse(code = 200, message = "Domain", response = Domain.class), @ApiResponse(code = 500, message = "Internal server error") })
public void get(@PathParam("organizationId") String organizationId, @PathParam("environmentId") String environmentId, @PathParam("hrid") String hrid, @Suspended final AsyncResponse response) {
    final User authenticatedUser = getAuthenticatedUser();
    domainService.findByHrid(environmentId, hrid).flatMap(domain -> checkAnyPermission(authenticatedUser, organizationId, environmentId, domain.getId(), Permission.DOMAIN, Acl.READ).andThen(Single.defer(() -> findAllPermissions(authenticatedUser, organizationId, environmentId, domain.getId()).map(userPermissions -> filterDomainInfos(domain, userPermissions))))).subscribe(response::resume, response::resume);
}
Also used : Page(io.gravitee.am.model.common.Page) Permissions.of(io.gravitee.am.management.service.permissions.Permissions.of) ReporterServiceProxy(io.gravitee.am.management.service.ReporterServiceProxy) AsyncResponse(javax.ws.rs.container.AsyncResponse) Permission(io.gravitee.am.model.permissions.Permission) Autowired(org.springframework.beans.factory.annotation.Autowired) Domain(io.gravitee.am.model.Domain) NotNull(javax.validation.constraints.NotNull) Single(io.reactivex.Single) Suspended(javax.ws.rs.container.Suspended) Collectors(java.util.stream.Collectors) IdentityProviderManager(io.gravitee.am.management.service.IdentityProviderManager) NewDomain(io.gravitee.am.service.model.NewDomain) 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) Permissions.or(io.gravitee.am.management.service.permissions.Permissions.or) ReferenceType(io.gravitee.am.model.ReferenceType) io.swagger.annotations(io.swagger.annotations) URI(java.net.URI) User(io.gravitee.am.identityprovider.api.User)

Example 28 with Permission

use of io.gravitee.am.model.permissions.Permission in project gravitee-access-management by gravitee-io.

the class EmailsResource method create.

@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Create a email", notes = "User must have the DOMAIN_EMAIL_TEMPLATE[CREATE] permission on the specified domain " + "or DOMAIN_EMAIL_TEMPLATE[CREATE] permission on the specified environment " + "or DOMAIN_EMAIL_TEMPLATE[CREATE] permission on the specified organization")
@ApiResponses({ @ApiResponse(code = 201, message = "Email 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 = "email", required = true) @Valid @NotNull final NewEmail newEmail, @Suspended final AsyncResponse response) {
    final User authenticatedUser = getAuthenticatedUser();
    checkAnyPermission(organizationId, environmentId, domain, Permission.DOMAIN_EMAIL_TEMPLATE, Acl.CREATE).andThen(domainService.findById(domain).switchIfEmpty(Maybe.error(new DomainNotFoundException(domain))).flatMapSingle(__ -> emailTemplateService.create(domain, newEmail, authenticatedUser)).map(email -> Response.created(URI.create("/organizations/" + organizationId + "/environments/" + environmentId + "/domains/" + domain + "/emails/" + email.getId())).entity(email).build())).subscribe(response::resume, response::resume);
}
Also used : Context(javax.ws.rs.core.Context) AsyncResponse(javax.ws.rs.container.AsyncResponse) Permission(io.gravitee.am.model.permissions.Permission) EmailTemplateService(io.gravitee.am.service.EmailTemplateService) 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) Suspended(javax.ws.rs.container.Suspended) Valid(javax.validation.Valid) Acl(io.gravitee.am.model.Acl) NewEmail(io.gravitee.am.service.model.NewEmail) 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) Template(io.gravitee.am.model.Template) ResourceContext(javax.ws.rs.container.ResourceContext) io.swagger.annotations(io.swagger.annotations) URI(java.net.URI) Email(io.gravitee.am.model.Email) User(io.gravitee.am.identityprovider.api.User) DomainNotFoundException(io.gravitee.am.service.exception.DomainNotFoundException)

Example 29 with Permission

use of io.gravitee.am.model.permissions.Permission in project gravitee-access-management by gravitee-io.

the class ExtensionGrantsResource method create.

@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Create a extension grant", notes = "User must have the DOMAIN_EXTENSION_GRANT[CREATE] permission on the specified domain " + "or DOMAIN_EXTENSION_GRANT[CREATE] permission on the specified environment " + "or DOMAIN_EXTENSION_GRANT[CREATE] permission on the specified organization")
@ApiResponses({ @ApiResponse(code = 201, message = "Extension grant 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 = "extension grant", required = true) @Valid @NotNull final NewExtensionGrant newExtensionGrant, @Suspended final AsyncResponse response) {
    final User authenticatedUser = getAuthenticatedUser();
    checkAnyPermission(organizationId, environmentId, domain, Permission.DOMAIN_EXTENSION_GRANT, Acl.CREATE).andThen(domainService.findById(domain).switchIfEmpty(Maybe.error(new DomainNotFoundException(domain))).flatMapSingle(irrelevant -> extensionGrantService.create(domain, newExtensionGrant, authenticatedUser).map(extensionGrant -> Response.created(URI.create("/organizations/" + organizationId + "/environments/" + environmentId + "/domains/" + domain + "/extensionGrants/" + extensionGrant.getId())).entity(extensionGrant).build()))).subscribe(response::resume, response::resume);
}
Also used : Context(javax.ws.rs.core.Context) AsyncResponse(javax.ws.rs.container.AsyncResponse) ExtensionGrant(io.gravitee.am.model.ExtensionGrant) 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) Suspended(javax.ws.rs.container.Suspended) Valid(javax.validation.Valid) Acl(io.gravitee.am.model.Acl) ExtensionGrantService(io.gravitee.am.service.ExtensionGrantService) NewExtensionGrant(io.gravitee.am.service.model.NewExtensionGrant) 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) User(io.gravitee.am.identityprovider.api.User) DomainNotFoundException(io.gravitee.am.service.exception.DomainNotFoundException)

Example 30 with Permission

use of io.gravitee.am.model.permissions.Permission in project gravitee-access-management by gravitee-io.

the class ScopesResource method create.

@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Create a scope", notes = "User must have the DOMAIN_SCOPE[CREATE] permission on the specified domain " + "or DOMAIN_SCOPE[CREATE] permission on the specified environment " + "or DOMAIN_SCOPE[CREATE] permission on the specified organization")
@ApiResponses({ @ApiResponse(code = 201, message = "Scope 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 = "scope", required = true) @Valid @NotNull final NewScope newScope, @Suspended final AsyncResponse response) {
    final User authenticatedUser = getAuthenticatedUser();
    checkAnyPermission(organizationId, environmentId, domain, Permission.DOMAIN_SCOPE, Acl.CREATE).andThen(domainService.findById(domain).switchIfEmpty(Maybe.error(new DomainNotFoundException(domain))).flatMapSingle(irrelevant -> scopeService.create(domain, newScope, authenticatedUser).map(scope -> Response.created(URI.create("/organizations/" + organizationId + "/environments/" + environmentId + "/domains/" + domain + "/scopes/" + scope.getId())).entity(scope).build()))).subscribe(response::resume, response::resume);
}
Also used : 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) NewScope(io.gravitee.am.service.model.NewScope) Valid(javax.validation.Valid) Acl(io.gravitee.am.model.Acl) User(io.gravitee.am.identityprovider.api.User) ScopeService(io.gravitee.am.service.ScopeService) ReferenceType(io.gravitee.am.model.ReferenceType) Observable(io.reactivex.Observable) io.swagger.annotations(io.swagger.annotations) URI(java.net.URI) Scope(io.gravitee.am.model.oauth2.Scope) 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

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