Search in sources :

Example 21 with Membership

use of io.gravitee.am.model.Membership 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 22 with Membership

use of io.gravitee.am.model.Membership 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 23 with Membership

use of io.gravitee.am.model.Membership 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 24 with Membership

use of io.gravitee.am.model.Membership 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

Membership (io.gravitee.am.model.Membership)24 Test (org.junit.Test)13 NewMembership (io.gravitee.am.service.model.NewMembership)10 ReferenceType (io.gravitee.am.model.ReferenceType)9 MemberType (io.gravitee.am.model.membership.MemberType)7 MembershipService (io.gravitee.am.service.MembershipService)7 Response (javax.ws.rs.core.Response)7 Single (io.reactivex.Single)6 List (java.util.List)6 User (io.gravitee.am.identityprovider.api.User)5 Organization (io.gravitee.am.model.Organization)5 User (io.gravitee.am.model.User)5 AbstractManagementTest (io.gravitee.am.repository.management.AbstractManagementTest)5 RoleService (io.gravitee.am.service.RoleService)5 Maybe (io.reactivex.Maybe)5 Autowired (org.springframework.beans.factory.annotation.Autowired)5 JerseySpringTest (io.gravitee.am.management.handlers.management.api.JerseySpringTest)4 DefaultRole (io.gravitee.am.model.permissions.DefaultRole)4 DomainService (io.gravitee.am.service.DomainService)4 URI (java.net.URI)4