use of io.gravitee.am.model.Membership in project gravitee-access-management by gravitee-io.
the class DomainNotificationServiceTest method shouldNotifyUserFromGroup.
@Test
public void shouldNotifyUserFromGroup() throws Exception {
final Membership member = new Membership();
member.setMemberType(MemberType.GROUP);
member.setMemberId("groupId");
when(membershipService.findByCriteria(eq(ReferenceType.DOMAIN), eq(DOMAIN_ID), any())).thenReturn(Flowable.just(member), Flowable.empty());
final List<User> tenUsers = IntStream.range(0, 10).mapToObj(x -> {
final User user = new User();
user.setId("" + x);
user.setEmail(x + "@acme.fr");
return user;
}).collect(Collectors.toList());
final User singleUser = new User();
singleUser.setId("single");
singleUser.setEmail("single@acme.fr");
when(groupService.findMembers(any(), any(), any(), anyInt(), anyInt())).thenReturn(Single.just(new Page<>(tenUsers, 0, 11)), Single.just(new Page<>(Arrays.asList(singleUser), 1, 11)));
when(emailService.getFinalEmail(any(), any(), any(), any(), any())).thenReturn(new Email());
cut.registerCertificateExpiration(certificate);
// wait subscription execution
Thread.sleep(1000);
verify(notifierService, times(11)).register(any(), any(), any());
verify(userService, never()).findById(any(), any(), any());
}
use of io.gravitee.am.model.Membership in project gravitee-access-management by gravitee-io.
the class OrganizationUserServiceTest method shouldDeleteUser_with_memberships.
@Test
public void shouldDeleteUser_with_memberships() {
String organization = "DEFAULT";
String userId = "user-id";
User user = new User();
user.setId(userId);
user.setSource("source-idp");
Membership m1 = mock(Membership.class);
when(m1.getId()).thenReturn("m1");
Membership m2 = mock(Membership.class);
when(m2.getId()).thenReturn("m2");
Membership m3 = mock(Membership.class);
when(m3.getId()).thenReturn("m3");
when(commonUserService.findById(any(), any(), any())).thenReturn(Single.just(user));
when(identityProviderManager.getUserProvider(any())).thenReturn(Maybe.empty());
when(commonUserService.delete(anyString())).thenReturn(Completable.complete());
when(membershipService.findByMember(any(), any())).thenReturn(Flowable.just(m1, m2, m3));
when(membershipService.delete(anyString())).thenReturn(Completable.complete());
organizationUserService.delete(ReferenceType.ORGANIZATION, organization, userId).test().assertComplete().assertNoErrors();
verify(commonUserService, times(1)).delete(any());
verify(membershipService, times(3)).delete(anyString());
}
use of io.gravitee.am.model.Membership in project gravitee-access-management by gravitee-io.
the class MembersResource method addOrUpdateMember.
@POST
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Add or update an organization member", notes = "User must have ORGANIZATION_MEMBER[READ] 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, @Valid @NotNull NewMembership newMembership, @Suspended final AsyncResponse response) {
final User authenticatedUser = getAuthenticatedUser();
final Membership membership = convert(newMembership);
membership.setReferenceId(organizationId);
membership.setReferenceType(ReferenceType.ORGANIZATION);
checkPermission(ReferenceType.ORGANIZATION, organizationId, Permission.ORGANIZATION_MEMBER, Acl.CREATE).andThen(organizationService.findById(organizationId).flatMap(organization -> membershipService.addOrUpdate(organizationId, membership, authenticatedUser)).map(membership1 -> Response.created(URI.create("/organizations/" + organizationId + "/members/" + membership1.getId())).entity(membership1).build())).subscribe(response::resume, response::resume);
}
use of io.gravitee.am.model.Membership in project gravitee-access-management by gravitee-io.
the class ApplicationMembersResource 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.model.Membership in project gravitee-access-management by gravitee-io.
the class MongoMembershipRepository method findByCriteria.
@Override
public Flowable<Membership> findByCriteria(ReferenceType referenceType, String referenceId, MembershipCriteria criteria) {
Bson eqReference = and(eq(FIELD_REFERENCE_TYPE, referenceType.name()), eq(FIELD_REFERENCE_ID, referenceId));
Bson eqGroupId = null;
Bson eqUserId = null;
if (criteria.getGroupIds().isPresent()) {
eqGroupId = and(eq(FIELD_MEMBER_TYPE, MemberType.GROUP.name()), in(FIELD_MEMBER_ID, criteria.getGroupIds().get()));
}
if (criteria.getUserId().isPresent()) {
eqUserId = and(eq(FIELD_MEMBER_TYPE, MemberType.USER.name()), eq(FIELD_MEMBER_ID, criteria.getUserId().get()));
}
if (criteria.getRoleId().isPresent()) {
eqUserId = eq(FIELD_ROLE, criteria.getRoleId().get());
}
return toBsonFilter(criteria.isLogicalOR(), eqGroupId, eqUserId).map(filter -> and(eqReference, filter)).switchIfEmpty(Single.just(eqReference)).flatMapPublisher(filter -> Flowable.fromPublisher(membershipsCollection.find(filter))).map(this::convert);
}
Aggregations