use of io.gravitee.am.model.Membership in project gravitee-access-management by gravitee-io.
the class MongoMembershipRepository method convert.
private Membership convert(MembershipMongo membershipMongo) {
Membership membership = new Membership();
membership.setId(membershipMongo.getId());
membership.setDomain(membershipMongo.getDomain());
membership.setMemberId(membershipMongo.getMemberId());
membership.setMemberType(MemberType.valueOf(membershipMongo.getMemberType()));
membership.setReferenceId(membershipMongo.getReferenceId());
membership.setReferenceType(ReferenceType.valueOf(membershipMongo.getReferenceType()));
membership.setRoleId(membershipMongo.getRole());
membership.setCreatedAt(membershipMongo.getCreatedAt());
membership.setUpdatedAt(membershipMongo.getUpdatedAt());
return membership;
}
use of io.gravitee.am.model.Membership in project gravitee-access-management by gravitee-io.
the class ApplicationServiceImpl method create0.
private Single<Application> create0(String domain, Application application, User principal) {
// created and updated date
application.setCreatedAt(new Date());
application.setUpdatedAt(application.getCreatedAt());
// check uniqueness
return checkApplicationUniqueness(domain, application).andThen(validateApplicationMetadata(application)).flatMap(this::setDefaultCertificate).flatMap(applicationRepository::create).flatMap(application1 -> {
if (principal == null || principal.getAdditionalInformation() == null || StringUtils.isEmpty(principal.getAdditionalInformation().get(Claims.organization))) {
// There is no principal or we can not find the organization the user is attached to. Can't assign role.
return Single.just(application1);
}
return roleService.findSystemRole(SystemRole.APPLICATION_PRIMARY_OWNER, ReferenceType.APPLICATION).switchIfEmpty(Single.error(new InvalidRoleException("Cannot assign owner to the application, owner role does not exist"))).flatMap(role -> {
Membership membership = new Membership();
membership.setDomain(application1.getDomain());
membership.setMemberId(principal.getId());
membership.setMemberType(MemberType.USER);
membership.setReferenceId(application1.getId());
membership.setReferenceType(ReferenceType.APPLICATION);
membership.setRoleId(role.getId());
return membershipService.addOrUpdate((String) principal.getAdditionalInformation().get(Claims.organization), membership).map(__ -> domain);
});
}).flatMap(application1 -> {
Event event = new Event(Type.APPLICATION, new Payload(application.getId(), ReferenceType.DOMAIN, application.getDomain(), Action.CREATE));
return eventService.create(event).flatMap(domain1 -> Single.just(application));
}).doOnSuccess(application1 -> auditService.report(AuditBuilder.builder(ApplicationAuditBuilder.class).principal(principal).type(EventType.APPLICATION_CREATED).application(application1))).doOnError(throwable -> auditService.report(AuditBuilder.builder(ApplicationAuditBuilder.class).principal(principal).type(EventType.APPLICATION_CREATED).throwable(throwable)));
}
use of io.gravitee.am.model.Membership in project gravitee-access-management by gravitee-io.
the class MembershipRepositoryTest method testFindByReferenceAndMember.
@Test
public void testFindByReferenceAndMember() {
Membership membership = new Membership();
membership.setRoleId("role#1");
membership.setReferenceType(ReferenceType.ORGANIZATION);
membership.setReferenceId(ORGANIZATION_ID);
membership.setMemberType(MemberType.USER);
membership.setMemberId("user#1");
Membership createdMembership = membershipRepository.create(membership).blockingGet();
TestObserver<Membership> obs = membershipRepository.findByReferenceAndMember(ReferenceType.ORGANIZATION, ORGANIZATION_ID, membership.getMemberType(), membership.getMemberId()).test();
obs.awaitTerminalEvent();
obs.assertComplete();
obs.assertValue(m -> m.getId().equals(createdMembership.getId()));
}
use of io.gravitee.am.model.Membership in project gravitee-access-management by gravitee-io.
the class MembershipRepositoryTest method testFindById.
@Test
public void testFindById() {
Membership membership = new Membership();
membership.setRoleId("role#1");
membership.setReferenceType(ReferenceType.ORGANIZATION);
membership.setReferenceId(ORGANIZATION_ID);
membership.setMemberType(MemberType.USER);
membership.setMemberId("user#1");
Membership createdMembership = membershipRepository.create(membership).blockingGet();
TestObserver<Membership> obs = membershipRepository.findById(createdMembership.getId()).test();
obs.awaitTerminalEvent();
obs.assertComplete();
obs.assertValue(m -> m.getId().equals(createdMembership.getId()) && m.getRoleId().equals(membership.getRoleId()) && m.getReferenceType() == membership.getReferenceType() && m.getReferenceId().equals(membership.getReferenceId()) && m.getMemberType() == membership.getMemberType() && m.getMemberId().equals(membership.getMemberId()));
}
use of io.gravitee.am.model.Membership in project gravitee-access-management by gravitee-io.
the class MembershipRepositoryTest method testFindByMember.
@Test
public void testFindByMember() {
Membership membership = new Membership();
membership.setRoleId("role#1");
membership.setReferenceType(ReferenceType.ORGANIZATION);
membership.setReferenceId(ORGANIZATION_ID);
membership.setMemberType(MemberType.USER);
membership.setMemberId("user#1");
Membership createdMembership = membershipRepository.create(membership).blockingGet();
TestObserver<List<Membership>> obs = membershipRepository.findByMember("user#1", MemberType.USER).toList().test();
obs.awaitTerminalEvent();
obs.assertComplete();
obs.assertValue(m -> m.size() == 1 && m.get(0).getMemberId().equals(createdMembership.getMemberId()));
}
Aggregations