Search in sources :

Example 11 with NewMembership

use of io.gravitee.am.service.model.NewMembership in project gravitee-access-management by gravitee-io.

the class MembersResourceTest method shouldAddMember.

@Test
public void shouldAddMember() {
    Organization organization = new Organization();
    organization.setId(Organization.DEFAULT);
    Membership membership = new Membership();
    membership.setId("membership-1");
    doReturn(Single.just(organization)).when(organizationService).findById(organization.getId());
    doReturn(Single.just(membership)).when(membershipService).addOrUpdate(eq(organization.getId()), any(Membership.class), any(io.gravitee.am.identityprovider.api.User.class));
    NewMembership newMembership = new NewMembership();
    newMembership.setMemberId("member#1");
    newMembership.setMemberType(MemberType.USER);
    newMembership.setRole("role#1");
    final Response response = target("organizations").path(organization.getId()).path("members").request().post(Entity.json(newMembership));
    assertEquals(HttpStatusCode.CREATED_201, response.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) Organization(io.gravitee.am.model.Organization) NewMembership(io.gravitee.am.service.model.NewMembership) Membership(io.gravitee.am.model.Membership) NewMembership(io.gravitee.am.service.model.NewMembership) Test(org.junit.Test) JerseySpringTest(io.gravitee.am.management.handlers.management.api.JerseySpringTest)

Example 12 with NewMembership

use of io.gravitee.am.service.model.NewMembership in project gravitee-access-management by gravitee-io.

the class MembersResource method addOrUpdateMember.

@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Add or update an security domain member", notes = "User must have the DOMAIN_MEMBER[CREATE] permission on the specified domain " + "or DOMAIN_MEMBER[CREATE] permission on the specified environment " + "or DOMAIN_MEMBER[CREATE] permission on the specified organization")
@ApiResponses({ @ApiResponse(code = 201, message = "Member has been added or updated successfully"), @ApiResponse(code = 400, message = "Membership parameter is not valid"), @ApiResponse(code = 500, message = "Internal server error") })
public void addOrUpdateMember(@PathParam("organizationId") String organizationId, @PathParam("environmentId") String environmentId, @PathParam("domain") String domain, @Valid @NotNull NewMembership newMembership, @Suspended final AsyncResponse response) {
    final User authenticatedUser = getAuthenticatedUser();
    final Membership membership = convert(newMembership);
    membership.setDomain(domain);
    membership.setReferenceId(domain);
    membership.setReferenceType(ReferenceType.DOMAIN);
    checkAnyPermission(organizationId, environmentId, domain, Permission.DOMAIN_MEMBER, Acl.CREATE).andThen(domainService.findById(domain).switchIfEmpty(Maybe.error(new DomainNotFoundException(domain))).flatMapSingle(domain1 -> membershipService.addOrUpdate(organizationId, membership, authenticatedUser)).flatMap(membership1 -> membershipService.addEnvironmentUserRoleIfNecessary(organizationId, environmentId, newMembership, authenticatedUser).andThen(Single.just(Response.created(URI.create("/organizations/" + organizationId + "/environments/" + environmentId + "/domains/" + domain + "/members/" + membership1.getId())).entity(membership1).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) MembershipListItem(io.gravitee.am.management.handlers.management.api.model.MembershipListItem) AbstractResource(io.gravitee.am.management.handlers.management.api.resources.AbstractResource) ApiResponses(io.swagger.annotations.ApiResponses) Single(io.reactivex.Single) Valid(javax.validation.Valid) Acl(io.gravitee.am.model.Acl) ApiOperation(io.swagger.annotations.ApiOperation) User(io.gravitee.am.identityprovider.api.User) NewMembership(io.gravitee.am.service.model.NewMembership) ReferenceType(io.gravitee.am.model.ReferenceType) URI(java.net.URI) MembershipService(io.gravitee.am.service.MembershipService) Context(javax.ws.rs.core.Context) AsyncResponse(javax.ws.rs.container.AsyncResponse) Membership(io.gravitee.am.model.Membership) DomainNotFoundException(io.gravitee.am.service.exception.DomainNotFoundException) NotNull(javax.validation.constraints.NotNull) Suspended(javax.ws.rs.container.Suspended) List(java.util.List) 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) NewMembership(io.gravitee.am.service.model.NewMembership) Membership(io.gravitee.am.model.Membership) DomainNotFoundException(io.gravitee.am.service.exception.DomainNotFoundException) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 13 with NewMembership

use of io.gravitee.am.service.model.NewMembership in project gravitee-access-management by gravitee-io.

the class MembersResource method convert.

private Membership convert(NewMembership newMembership) {
    Membership membership = new Membership();
    membership.setMemberId(newMembership.getMemberId());
    membership.setMemberType(newMembership.getMemberType());
    membership.setRoleId(newMembership.getRole());
    return membership;
}
Also used : NewMembership(io.gravitee.am.service.model.NewMembership) Membership(io.gravitee.am.model.Membership)

Example 14 with NewMembership

use of io.gravitee.am.service.model.NewMembership in project gravitee-access-management by gravitee-io.

the class MembersResource method convert.

private Membership convert(NewMembership newMembership) {
    Membership membership = new Membership();
    membership.setMemberId(newMembership.getMemberId());
    membership.setMemberType(newMembership.getMemberType());
    membership.setRoleId(newMembership.getRole());
    return membership;
}
Also used : NewMembership(io.gravitee.am.service.model.NewMembership) Membership(io.gravitee.am.model.Membership)

Aggregations

NewMembership (io.gravitee.am.service.model.NewMembership)14 Membership (io.gravitee.am.model.Membership)8 Test (org.junit.Test)7 MembershipCriteria (io.gravitee.am.repository.management.api.search.MembershipCriteria)6 Response (javax.ws.rs.core.Response)6 DefaultRole (io.gravitee.am.model.permissions.DefaultRole)5 DefaultUser (io.gravitee.am.identityprovider.api.DefaultUser)4 SystemRole (io.gravitee.am.model.permissions.SystemRole)4 User (io.gravitee.am.identityprovider.api.User)3 JerseySpringTest (io.gravitee.am.management.handlers.management.api.JerseySpringTest)3 MembershipListItem (io.gravitee.am.management.handlers.management.api.model.MembershipListItem)3 AbstractResource (io.gravitee.am.management.handlers.management.api.resources.AbstractResource)3 Acl (io.gravitee.am.model.Acl)3 ReferenceType (io.gravitee.am.model.ReferenceType)3 Permission (io.gravitee.am.model.permissions.Permission)3 MembershipService (io.gravitee.am.service.MembershipService)3 MediaType (io.gravitee.common.http.MediaType)3 ApiOperation (io.swagger.annotations.ApiOperation)3 ApiResponse (io.swagger.annotations.ApiResponse)3 ApiResponses (io.swagger.annotations.ApiResponses)3