Search in sources :

Example 1 with GroupService

use of org.apache.syncope.common.rest.api.service.GroupService in project syncope by apache.

the class GroupITCase method selfRead.

@Test
public void selfRead() {
    UserTO userTO = userService.read("1417acbe-cbf6-4277-9372-e75e04f97000");
    assertNotNull(userTO);
    assertTrue(userTO.getMembership("37d15e4c-cdc1-460b-a591-8505c8133806").isPresent());
    assertFalse(userTO.getMembership("29f96485-729e-4d31-88a1-6fc60e4677f3").isPresent());
    GroupService groupService2 = clientFactory.create("rossini", ADMIN_PWD).getService(GroupService.class);
    try {
        groupService2.read("29f96485-729e-4d31-88a1-6fc60e4677f3");
        fail("This should not happen");
    } catch (SyncopeClientException e) {
        assertEquals(ClientExceptionType.DelegatedAdministration, e.getType());
    }
    List<GroupTO> groups = groupService2.own();
    assertNotNull(groups);
    assertTrue(groups.stream().anyMatch(group -> "37d15e4c-cdc1-460b-a591-8505c8133806".equals(group.getKey())));
}
Also used : StringPatchItem(org.apache.syncope.common.lib.patch.StringPatchItem) ProvisionTO(org.apache.syncope.common.lib.to.ProvisionTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) NamingException(javax.naming.NamingException) ProvisioningResult(org.apache.syncope.common.lib.to.ProvisioningResult) ConnObjectTO(org.apache.syncope.common.lib.to.ConnObjectTO) ResourceDeassociationAction(org.apache.syncope.common.lib.types.ResourceDeassociationAction) AnyTypeKind(org.apache.syncope.common.lib.types.AnyTypeKind) GroupPatch(org.apache.syncope.common.lib.patch.GroupPatch) SchedTaskTO(org.apache.syncope.common.lib.to.SchedTaskTO) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) AttrSchemaType(org.apache.syncope.common.lib.types.AttrSchemaType) Map(java.util.Map) PagedResult(org.apache.syncope.common.lib.to.PagedResult) ExecTO(org.apache.syncope.common.lib.to.ExecTO) BulkActionResult(org.apache.syncope.common.lib.to.BulkActionResult) MappingTO(org.apache.syncope.common.lib.to.MappingTO) SchemaType(org.apache.syncope.common.lib.types.SchemaType) UUID(java.util.UUID) GroupTO(org.apache.syncope.common.lib.to.GroupTO) GenericType(javax.ws.rs.core.GenericType) Test(org.junit.jupiter.api.Test) DerSchemaTO(org.apache.syncope.common.lib.to.DerSchemaTO) List(java.util.List) AttrPatch(org.apache.syncope.common.lib.patch.AttrPatch) TypeExtensionTO(org.apache.syncope.common.lib.to.TypeExtensionTO) Response(javax.ws.rs.core.Response) DeassociationPatch(org.apache.syncope.common.lib.patch.DeassociationPatch) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) AccessControlException(java.security.AccessControlException) NamingEnumeration(javax.naming.NamingEnumeration) TaskJob(org.apache.syncope.core.provisioning.java.job.TaskJob) SearchResult(javax.naming.directory.SearchResult) Assertions.fail(org.junit.jupiter.api.Assertions.fail) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) AnonymousAuthenticationHandler(org.apache.syncope.client.lib.AnonymousAuthenticationHandler) PropagationTaskExecStatus(org.apache.syncope.common.lib.types.PropagationTaskExecStatus) AttrTO(org.apache.syncope.common.lib.to.AttrTO) GroupService(org.apache.syncope.common.rest.api.service.GroupService) SyncopeService(org.apache.syncope.common.rest.api.service.SyncopeService) BulkMembersActionType(org.apache.syncope.common.lib.types.BulkMembersActionType) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) EntityTOUtils(org.apache.syncope.common.lib.EntityTOUtils) AnyObjectPatch(org.apache.syncope.common.lib.patch.AnyObjectPatch) SerializationUtils(org.apache.commons.lang3.SerializationUtils) SearchControls(javax.naming.directory.SearchControls) PlainSchemaTO(org.apache.syncope.common.lib.to.PlainSchemaTO) AssociationPatch(org.apache.syncope.common.lib.patch.AssociationPatch) ItemTO(org.apache.syncope.common.lib.to.ItemTO) PropagationStatus(org.apache.syncope.common.lib.to.PropagationStatus) ClientExceptionType(org.apache.syncope.common.lib.types.ClientExceptionType) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) AbstractITCase(org.apache.syncope.fit.AbstractITCase) AnyQuery(org.apache.syncope.common.rest.api.beans.AnyQuery) MembershipTO(org.apache.syncope.common.lib.to.MembershipTO) AnyTypeClassTO(org.apache.syncope.common.lib.to.AnyTypeClassTO) SyncopeConstants(org.apache.syncope.common.lib.SyncopeConstants) ForbiddenException(javax.ws.rs.ForbiddenException) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) ResourceAssociationAction(org.apache.syncope.common.lib.types.ResourceAssociationAction) DirContext(javax.naming.directory.DirContext) AnyTypeTO(org.apache.syncope.common.lib.to.AnyTypeTO) MappingPurpose(org.apache.syncope.common.lib.types.MappingPurpose) ConnectorCapability(org.apache.syncope.common.lib.types.ConnectorCapability) PatchOperation(org.apache.syncope.common.lib.types.PatchOperation) StringReplacePatchItem(org.apache.syncope.common.lib.patch.StringReplacePatchItem) ConnInstanceTO(org.apache.syncope.common.lib.to.ConnInstanceTO) SyncopeClient(org.apache.syncope.client.lib.SyncopeClient) UserTO(org.apache.syncope.common.lib.to.UserTO) Collections(java.util.Collections) AnyOperations(org.apache.syncope.common.lib.AnyOperations) AnyObjectTO(org.apache.syncope.common.lib.to.AnyObjectTO) TaskType(org.apache.syncope.common.lib.types.TaskType) UserTO(org.apache.syncope.common.lib.to.UserTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) GroupService(org.apache.syncope.common.rest.api.service.GroupService) GroupTO(org.apache.syncope.common.lib.to.GroupTO) Test(org.junit.jupiter.api.Test)

Example 2 with GroupService

use of org.apache.syncope.common.rest.api.service.GroupService in project syncope by apache.

the class GroupITCase method anonymous.

@Test
public void anonymous() {
    GroupService unauthenticated = clientFactory.create().getService(GroupService.class);
    try {
        unauthenticated.search(new AnyQuery.Builder().realm("/even").build());
        fail("This should not happen");
    } catch (AccessControlException e) {
        assertNotNull(e);
    }
    SyncopeClient anonymous = clientFactory.create(new AnonymousAuthenticationHandler(ANONYMOUS_UNAME, ANONYMOUS_KEY));
    try {
        anonymous.getService(GroupService.class).search(new AnyQuery.Builder().realm("/even").build());
        fail("This should not happen");
    } catch (ForbiddenException e) {
        assertNotNull(e);
    }
    assertFalse(anonymous.getService(SyncopeService.class).searchAssignableGroups("/even", null, 1, 100).getResult().isEmpty());
}
Also used : ForbiddenException(javax.ws.rs.ForbiddenException) AccessControlException(java.security.AccessControlException) AnonymousAuthenticationHandler(org.apache.syncope.client.lib.AnonymousAuthenticationHandler) AnyQuery(org.apache.syncope.common.rest.api.beans.AnyQuery) GroupService(org.apache.syncope.common.rest.api.service.GroupService) SyncopeClient(org.apache.syncope.client.lib.SyncopeClient) Test(org.junit.jupiter.api.Test)

Example 3 with GroupService

use of org.apache.syncope.common.rest.api.service.GroupService in project syncope by apache.

the class RESTITCase method noContent.

@Test
public void noContent() throws IOException {
    SyncopeClient noContentclient = clientFactory.create(ADMIN_UNAME, ADMIN_PWD);
    GroupService noContentService = noContentclient.prefer(noContentclient.getService(GroupService.class), Preference.RETURN_NO_CONTENT);
    GroupTO group = GroupITCase.getSampleTO("noContent");
    Response response = noContentService.create(group);
    assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatus());
    assertEquals(Preference.RETURN_NO_CONTENT.toString(), response.getHeaderString(RESTHeaders.PREFERENCE_APPLIED));
    assertEquals(StringUtils.EMPTY, IOUtils.toString((InputStream) response.getEntity(), StandardCharsets.UTF_8));
    group = getObject(response.getLocation(), GroupService.class, GroupTO.class);
    assertNotNull(group);
    GroupPatch groupPatch = new GroupPatch();
    groupPatch.setKey(group.getKey());
    groupPatch.getPlainAttrs().add(attrAddReplacePatch("badge", "xxxxxxxxxx"));
    response = noContentService.update(groupPatch);
    assertEquals(Response.Status.NO_CONTENT.getStatusCode(), response.getStatus());
    assertEquals(Preference.RETURN_NO_CONTENT.toString(), response.getHeaderString(RESTHeaders.PREFERENCE_APPLIED));
    assertEquals(StringUtils.EMPTY, IOUtils.toString((InputStream) response.getEntity(), StandardCharsets.UTF_8));
    response = noContentService.delete(group.getKey());
    assertEquals(Response.Status.NO_CONTENT.getStatusCode(), response.getStatus());
    assertEquals(Preference.RETURN_NO_CONTENT.toString(), response.getHeaderString(RESTHeaders.PREFERENCE_APPLIED));
    assertEquals(StringUtils.EMPTY, IOUtils.toString((InputStream) response.getEntity(), StandardCharsets.UTF_8));
}
Also used : Response(javax.ws.rs.core.Response) InputStream(java.io.InputStream) GroupService(org.apache.syncope.common.rest.api.service.GroupService) SyncopeClient(org.apache.syncope.client.lib.SyncopeClient) GroupPatch(org.apache.syncope.common.lib.patch.GroupPatch) GroupTO(org.apache.syncope.common.lib.to.GroupTO) Test(org.junit.jupiter.api.Test)

Example 4 with GroupService

use of org.apache.syncope.common.rest.api.service.GroupService in project syncope by apache.

the class GroupITCase method updateAsGroupOwner.

@Test
public void updateAsGroupOwner() {
    // 1. read group as admin
    GroupTO groupTO = groupService.read("ebf97068-aa4b-4a85-9f01-680e8c4cf227");
    // issue SYNCOPE-15
    assertNotNull(groupTO.getCreationDate());
    assertNotNull(groupTO.getLastChangeDate());
    assertEquals("admin", groupTO.getCreator());
    assertEquals("admin", groupTO.getLastModifier());
    // 2. prepare update
    GroupPatch groupPatch = new GroupPatch();
    groupPatch.setKey(groupTO.getKey());
    groupPatch.setName(new StringReplacePatchItem.Builder().value("Director").build());
    // 3. try to update as verdi, not owner of group 6 - fail
    GroupService groupService2 = clientFactory.create("verdi", ADMIN_PWD).getService(GroupService.class);
    try {
        groupService2.update(groupPatch);
        fail("This should not happen");
    } catch (ForbiddenException e) {
        assertNotNull(e);
    }
    // 4. update as puccini, owner of group 6 - success
    GroupService groupService3 = clientFactory.create("puccini", ADMIN_PWD).getService(GroupService.class);
    groupTO = groupService3.update(groupPatch).readEntity(new GenericType<ProvisioningResult<GroupTO>>() {
    }).getEntity();
    assertEquals("Director", groupTO.getName());
    // issue SYNCOPE-15
    assertNotNull(groupTO.getCreationDate());
    assertNotNull(groupTO.getLastChangeDate());
    assertEquals("admin", groupTO.getCreator());
    assertEquals("puccini", groupTO.getLastModifier());
    assertTrue(groupTO.getCreationDate().before(groupTO.getLastChangeDate()));
}
Also used : ForbiddenException(javax.ws.rs.ForbiddenException) StringReplacePatchItem(org.apache.syncope.common.lib.patch.StringReplacePatchItem) ProvisioningResult(org.apache.syncope.common.lib.to.ProvisioningResult) GroupService(org.apache.syncope.common.rest.api.service.GroupService) GroupPatch(org.apache.syncope.common.lib.patch.GroupPatch) GroupTO(org.apache.syncope.common.lib.to.GroupTO) Test(org.junit.jupiter.api.Test)

Example 5 with GroupService

use of org.apache.syncope.common.rest.api.service.GroupService in project syncope by apache.

the class DynRealmITCase method delegatedAdmin.

@Test
public void delegatedAdmin() {
    DynRealmTO dynRealm = null;
    RoleTO role = null;
    try {
        // 1. create dynamic realm for all users and groups having resource-ldap assigned
        dynRealm = new DynRealmTO();
        dynRealm.setKey("LDAPLovers" + getUUIDString());
        dynRealm.getDynMembershipConds().put(AnyTypeKind.USER.name(), "$resources==resource-ldap");
        dynRealm.getDynMembershipConds().put(AnyTypeKind.GROUP.name(), "$resources==resource-ldap");
        Response response = dynRealmService.create(dynRealm);
        dynRealm = getObject(response.getLocation(), DynRealmService.class, DynRealmTO.class);
        assertNotNull(dynRealm);
        // 2. create role for such dynamic realm
        role = new RoleTO();
        role.setKey("Administer LDAP" + getUUIDString());
        role.getEntitlements().add(StandardEntitlement.USER_SEARCH);
        role.getEntitlements().add(StandardEntitlement.USER_READ);
        role.getEntitlements().add(StandardEntitlement.USER_UPDATE);
        role.getEntitlements().add(StandardEntitlement.GROUP_READ);
        role.getEntitlements().add(StandardEntitlement.GROUP_UPDATE);
        role.getDynRealms().add(dynRealm.getKey());
        role = createRole(role);
        assertNotNull(role);
        // 3. create new user and assign the new role
        UserTO dynRealmAdmin = UserITCase.getUniqueSampleTO("dynRealmAdmin@apache.org");
        dynRealmAdmin.setPassword("password123");
        dynRealmAdmin.getRoles().add(role.getKey());
        dynRealmAdmin = createUser(dynRealmAdmin).getEntity();
        assertNotNull(dynRealmAdmin);
        // 4. create new user and group, assign resource-ldap
        UserTO user = UserITCase.getUniqueSampleTO("dynRealmUser@apache.org");
        user.setRealm("/even/two");
        user.getResources().clear();
        user.getResources().add(RESOURCE_NAME_LDAP);
        user = createUser(user).getEntity();
        assertNotNull(user);
        final String userKey = user.getKey();
        GroupTO group = GroupITCase.getSampleTO("dynRealmGroup");
        group.setRealm("/odd");
        group.getResources().clear();
        group.getResources().add(RESOURCE_NAME_LDAP);
        group = createGroup(group).getEntity();
        assertNotNull(group);
        final String groupKey = group.getKey();
        if (ElasticsearchDetector.isElasticSearchEnabled(syncopeService)) {
            try {
                Thread.sleep(2000);
            } catch (InterruptedException ex) {
            // ignore
            }
        }
        // 5. verify that the new user and group are found when searching by dynamic realm
        PagedResult<UserTO> matchingUsers = userService.search(new AnyQuery.Builder().realm("/").fiql(SyncopeClient.getUserSearchConditionBuilder().inDynRealms(dynRealm.getKey()).query()).build());
        assertTrue(matchingUsers.getResult().stream().anyMatch(object -> object.getKey().equals(userKey)));
        PagedResult<GroupTO> matchingGroups = groupService.search(new AnyQuery.Builder().realm("/").fiql(SyncopeClient.getGroupSearchConditionBuilder().inDynRealms(dynRealm.getKey()).query()).build());
        assertTrue(matchingGroups.getResult().stream().anyMatch(object -> object.getKey().equals(groupKey)));
        // 6. prepare to act as delegated admin
        SyncopeClient delegatedClient = clientFactory.create(dynRealmAdmin.getUsername(), "password123");
        UserService delegatedUserService = delegatedClient.getService(UserService.class);
        GroupService delegatedGroupService = delegatedClient.getService(GroupService.class);
        // 7. verify delegated administration
        // USER_READ
        assertNotNull(delegatedUserService.read(userKey));
        // GROUP_READ
        assertNotNull(delegatedGroupService.read(groupKey));
        // USER_SEARCH
        matchingUsers = delegatedUserService.search(new AnyQuery.Builder().realm("/").build());
        assertTrue(matchingUsers.getResult().stream().anyMatch(object -> object.getKey().equals(userKey)));
        // USER_UPDATE
        UserPatch userPatch = new UserPatch();
        userPatch.setKey(userKey);
        userPatch.getResources().add(new StringPatchItem.Builder().value(RESOURCE_NAME_LDAP).operation(PatchOperation.DELETE).build());
        // this will fail because unassigning resource-ldap would result in removing the user from the dynamic realm
        try {
            delegatedUserService.update(userPatch);
            fail("This should not happen");
        } catch (SyncopeClientException e) {
            assertEquals(ClientExceptionType.DelegatedAdministration, e.getType());
        }
        // this will succeed instead
        userPatch.getResources().clear();
        userPatch.getResources().add(new StringPatchItem.Builder().value(RESOURCE_NAME_NOPROPAGATION).build());
        user = delegatedUserService.update(userPatch).readEntity(new GenericType<ProvisioningResult<UserTO>>() {
        }).getEntity();
        assertNotNull(user);
        assertTrue(user.getResources().contains(RESOURCE_NAME_NOPROPAGATION));
        // GROUP_UPDATE
        GroupPatch groupPatch = new GroupPatch();
        groupPatch.setKey(groupKey);
        groupPatch.getPlainAttrs().add(new AttrPatch.Builder().attrTO(attrTO("icon", "modified")).build());
        group = delegatedGroupService.update(groupPatch).readEntity(new GenericType<ProvisioningResult<GroupTO>>() {
        }).getEntity();
        assertNotNull(group);
        assertEquals("modified", group.getPlainAttr("icon").get().getValues().get(0));
    } finally {
        if (role != null) {
            roleService.delete(role.getKey());
        }
        if (dynRealm != null) {
            dynRealmService.delete(dynRealm.getKey());
        }
    }
}
Also used : Assertions.fail(org.junit.jupiter.api.Assertions.fail) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) StringPatchItem(org.apache.syncope.common.lib.patch.StringPatchItem) StandardEntitlement(org.apache.syncope.common.lib.types.StandardEntitlement) DynRealmTO(org.apache.syncope.common.lib.to.DynRealmTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) ElasticsearchDetector(org.apache.syncope.fit.ElasticsearchDetector) UserService(org.apache.syncope.common.rest.api.service.UserService) GroupService(org.apache.syncope.common.rest.api.service.GroupService) Assertions.assertNotEquals(org.junit.jupiter.api.Assertions.assertNotEquals) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) ProvisioningResult(org.apache.syncope.common.lib.to.ProvisioningResult) DynRealmService(org.apache.syncope.common.rest.api.service.DynRealmService) AnyTypeKind(org.apache.syncope.common.lib.types.AnyTypeKind) GroupPatch(org.apache.syncope.common.lib.patch.GroupPatch) RoleTO(org.apache.syncope.common.lib.to.RoleTO) ClientExceptionType(org.apache.syncope.common.lib.types.ClientExceptionType) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) AbstractITCase(org.apache.syncope.fit.AbstractITCase) AnyQuery(org.apache.syncope.common.rest.api.beans.AnyQuery) PagedResult(org.apache.syncope.common.lib.to.PagedResult) GroupTO(org.apache.syncope.common.lib.to.GroupTO) GenericType(javax.ws.rs.core.GenericType) Test(org.junit.jupiter.api.Test) AttrPatch(org.apache.syncope.common.lib.patch.AttrPatch) Response(javax.ws.rs.core.Response) PatchOperation(org.apache.syncope.common.lib.types.PatchOperation) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) SyncopeClient(org.apache.syncope.client.lib.SyncopeClient) UserTO(org.apache.syncope.common.lib.to.UserTO) DynRealmService(org.apache.syncope.common.rest.api.service.DynRealmService) DynRealmTO(org.apache.syncope.common.lib.to.DynRealmTO) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) GroupPatch(org.apache.syncope.common.lib.patch.GroupPatch) UserService(org.apache.syncope.common.rest.api.service.UserService) ProvisioningResult(org.apache.syncope.common.lib.to.ProvisioningResult) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) RoleTO(org.apache.syncope.common.lib.to.RoleTO) GroupService(org.apache.syncope.common.rest.api.service.GroupService) SyncopeClient(org.apache.syncope.client.lib.SyncopeClient) AttrPatch(org.apache.syncope.common.lib.patch.AttrPatch) GroupTO(org.apache.syncope.common.lib.to.GroupTO) Response(javax.ws.rs.core.Response) UserTO(org.apache.syncope.common.lib.to.UserTO) StringPatchItem(org.apache.syncope.common.lib.patch.StringPatchItem) Test(org.junit.jupiter.api.Test)

Aggregations

GroupService (org.apache.syncope.common.rest.api.service.GroupService)5 Test (org.junit.jupiter.api.Test)5 SyncopeClient (org.apache.syncope.client.lib.SyncopeClient)4 GroupPatch (org.apache.syncope.common.lib.patch.GroupPatch)4 GroupTO (org.apache.syncope.common.lib.to.GroupTO)4 ForbiddenException (javax.ws.rs.ForbiddenException)3 Response (javax.ws.rs.core.Response)3 AnyQuery (org.apache.syncope.common.rest.api.beans.AnyQuery)3 AccessControlException (java.security.AccessControlException)2 GenericType (javax.ws.rs.core.GenericType)2 AnonymousAuthenticationHandler (org.apache.syncope.client.lib.AnonymousAuthenticationHandler)2 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)2 AttrPatch (org.apache.syncope.common.lib.patch.AttrPatch)2 StringPatchItem (org.apache.syncope.common.lib.patch.StringPatchItem)2 StringReplacePatchItem (org.apache.syncope.common.lib.patch.StringReplacePatchItem)2 ProvisioningResult (org.apache.syncope.common.lib.to.ProvisioningResult)2 InputStream (java.io.InputStream)1 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1