Search in sources :

Example 6 with NewMembership

use of io.gravitee.am.service.model.NewMembership 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;
}
Also used : NewMembership(io.gravitee.am.service.model.NewMembership) Membership(io.gravitee.am.model.Membership)

Example 7 with NewMembership

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

the class MembershipServiceTest method shouldAddDomainUserRole.

@Test
public void shouldAddDomainUserRole() {
    NewMembership membership = new NewMembership();
    membership.setMemberType(MemberType.USER);
    membership.setMemberId("user#1");
    DefaultUser principal = new DefaultUser("username");
    principal.setId("user#1");
    User user = new User();
    user.setReferenceId(ORGANIZATION_ID);
    user.setReferenceType(ReferenceType.ORGANIZATION);
    Role environmentUserRole = new Role();
    environmentUserRole.setId("role#1");
    when(membershipRepository.findByCriteria(eq(ReferenceType.DOMAIN), eq("domain#1"), any(MembershipCriteria.class))).thenReturn(Flowable.empty());
    when(roleService.findDefaultRole("orga#1", DefaultRole.DOMAIN_USER, ReferenceType.DOMAIN)).thenReturn(Maybe.just(environmentUserRole));
    when(membershipRepository.create(any())).thenReturn(Single.just(new Membership()));
    when(eventService.create(any())).thenReturn(Single.just(new Event()));
    when(membershipRepository.findByCriteria(eq(ReferenceType.ENVIRONMENT), eq("env#1"), any(MembershipCriteria.class))).thenReturn(Flowable.empty());
    when(roleService.findDefaultRole("orga#1", DefaultRole.ENVIRONMENT_USER, ReferenceType.ENVIRONMENT)).thenReturn(Maybe.just(environmentUserRole));
    TestObserver<Void> completable = membershipService.addDomainUserRoleIfNecessary("orga#1", "env#1", "domain#1", membership, principal).test();
    completable.awaitTerminalEvent();
    completable.assertNoErrors();
    completable.assertComplete();
}
Also used : SystemRole(io.gravitee.am.model.permissions.SystemRole) DefaultRole(io.gravitee.am.model.permissions.DefaultRole) DefaultUser(io.gravitee.am.identityprovider.api.DefaultUser) DefaultUser(io.gravitee.am.identityprovider.api.DefaultUser) NewMembership(io.gravitee.am.service.model.NewMembership) MembershipCriteria(io.gravitee.am.repository.management.api.search.MembershipCriteria) NewMembership(io.gravitee.am.service.model.NewMembership) Event(io.gravitee.am.model.common.event.Event) Test(org.junit.Test)

Example 8 with NewMembership

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

the class MembershipServiceTest method shouldAddEnvironmentUserRole.

@Test
public void shouldAddEnvironmentUserRole() {
    NewMembership membership = new NewMembership();
    membership.setMemberType(MemberType.USER);
    membership.setMemberId("user#1");
    DefaultUser principal = new DefaultUser("username");
    principal.setId("user#1");
    User user = new User();
    user.setReferenceId(ORGANIZATION_ID);
    user.setReferenceType(ReferenceType.ORGANIZATION);
    Role environmentUserRole = new Role();
    environmentUserRole.setId("role#1");
    when(membershipRepository.findByCriteria(eq(ReferenceType.ENVIRONMENT), eq("env#1"), any(MembershipCriteria.class))).thenReturn(Flowable.empty());
    when(roleService.findDefaultRole("orga#1", DefaultRole.ENVIRONMENT_USER, ReferenceType.ENVIRONMENT)).thenReturn(Maybe.just(environmentUserRole));
    when(membershipRepository.create(any())).thenReturn(Single.just(new Membership()));
    when(eventService.create(any())).thenReturn(Single.just(new Event()));
    TestObserver<Void> completable = membershipService.addEnvironmentUserRoleIfNecessary("orga#1", "env#1", membership, principal).test();
    completable.awaitTerminalEvent();
    completable.assertNoErrors();
    completable.assertComplete();
}
Also used : SystemRole(io.gravitee.am.model.permissions.SystemRole) DefaultRole(io.gravitee.am.model.permissions.DefaultRole) DefaultUser(io.gravitee.am.identityprovider.api.DefaultUser) DefaultUser(io.gravitee.am.identityprovider.api.DefaultUser) NewMembership(io.gravitee.am.service.model.NewMembership) MembershipCriteria(io.gravitee.am.repository.management.api.search.MembershipCriteria) NewMembership(io.gravitee.am.service.model.NewMembership) Event(io.gravitee.am.model.common.event.Event) Test(org.junit.Test)

Example 9 with NewMembership

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

the class MembershipServiceTest method shouldNotAddDomainUserRole_userAlreadyHasMembership.

@Test
public void shouldNotAddDomainUserRole_userAlreadyHasMembership() {
    NewMembership membership = new NewMembership();
    membership.setMemberType(MemberType.USER);
    membership.setMemberId("user#1");
    DefaultUser principal = new DefaultUser("username");
    principal.setId("user#1");
    User user = new User();
    user.setReferenceId(ORGANIZATION_ID);
    user.setReferenceType(ReferenceType.ORGANIZATION);
    Role environmentUserRole = new Role();
    environmentUserRole.setId("role#1");
    when(membershipRepository.findByCriteria(eq(ReferenceType.ENVIRONMENT), eq("env#1"), any(MembershipCriteria.class))).thenReturn(Flowable.just(new Membership()));
    when(membershipRepository.findByCriteria(eq(ReferenceType.DOMAIN), eq("domain#1"), any(MembershipCriteria.class))).thenReturn(Flowable.just(new Membership()));
    TestObserver<Void> completable = membershipService.addDomainUserRoleIfNecessary("orga#1", "env#1", "domain#1", membership, principal).test();
    completable.awaitTerminalEvent();
    completable.assertNoErrors();
    completable.assertComplete();
    verify(membershipRepository, times(0)).create(any());
    verifyZeroInteractions(auditService);
}
Also used : SystemRole(io.gravitee.am.model.permissions.SystemRole) DefaultRole(io.gravitee.am.model.permissions.DefaultRole) DefaultUser(io.gravitee.am.identityprovider.api.DefaultUser) DefaultUser(io.gravitee.am.identityprovider.api.DefaultUser) NewMembership(io.gravitee.am.service.model.NewMembership) MembershipCriteria(io.gravitee.am.repository.management.api.search.MembershipCriteria) NewMembership(io.gravitee.am.service.model.NewMembership) Test(org.junit.Test)

Example 10 with NewMembership

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

the class MembersResourceTest method shouldNotAddMember_invalidInput.

@Test
public void shouldNotAddMember_invalidInput() {
    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));
    // invalid input.
    NewMembership newMembership = new NewMembership();
    final Response response = target("organizations").path(organization.getId()).path("members").request().post(Entity.json(newMembership));
    assertEquals(HttpStatusCode.BAD_REQUEST_400, 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)

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