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());
}
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);
}
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;
}
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;
}
Aggregations