Search in sources :

Example 6 with Group

use of org.apache.directory.fortress.core.model.Group in project directory-fortress-core by apache.

the class GroupMgrRestImpl method roleGroups.

/**
 * {@inheritDoc}
 */
@Override
public List<Group> roleGroups(Role role) throws SecurityException {
    VUtil.assertNotNull(role, GlobalErrIds.ROLE_NULL, CLS_NM + ".roleGroups");
    List<Group> retGroups;
    FortRequest request = new FortRequest();
    request.setContextId(this.contextId);
    request.setEntity(role);
    if (this.adminSess != null) {
        request.setSession(adminSess);
    }
    String szRequest = RestUtils.marshal(request);
    String szResponse = RestUtils.getInstance().post(szRequest, HttpIds.GROUP_ASGNED);
    FortResponse response = RestUtils.unmarshall(szResponse);
    if (response.getErrorCode() == 0) {
        retGroups = response.getEntities();
    } else {
        throw new SecurityException(response.getErrorCode(), response.getErrorMessage());
    }
    return retGroups;
}
Also used : Group(org.apache.directory.fortress.core.model.Group) FortResponse(org.apache.directory.fortress.core.model.FortResponse) SecurityException(org.apache.directory.fortress.core.SecurityException) FortRequest(org.apache.directory.fortress.core.model.FortRequest)

Example 7 with Group

use of org.apache.directory.fortress.core.model.Group in project directory-fortress-core by apache.

the class GroupAntTest method testReadGroups.

@Test
public void testReadGroups() {
    // gather role input data:
    List<Addgroup> addgroups = fortressAntTask.getAddgroups();
    for (Addgroup addgroup : addgroups) {
        List<Group> groups = addgroup.getGroups();
        readGroups("READ-GRPS", groups);
    }
}
Also used : Group(org.apache.directory.fortress.core.model.Group) Addgroup(org.apache.directory.fortress.core.ant.Addgroup) Test(org.junit.Test)

Example 8 with Group

use of org.apache.directory.fortress.core.model.Group in project directory-fortress-core by apache.

the class GroupMgrImplTest method deassignUserMember.

private void deassignUserMember(String message, Group group, String[][] users) {
    LogUtil.logIt(message);
    try {
        groupMgr = GroupMgrFactory.createInstance(TestUtils.getContext());
        for (String[] userArray : users) {
            User user = UserTestData.getUser(userArray);
            groupMgr.deassign(group, user.getUserId());
        }
        LOG.debug("deassignUserMember group [" + group.getName() + "] successful");
        int countOfOldUsers = group.getMembers().size();
        // read from LDAP and get count of members after deassignment
        Group groupFromLdap = groupMgr.read(group);
        int actualAmountOfMembers = groupFromLdap.getMembers().size();
        assertEquals(CLS_NM + ".deassignUserMember failed members size check", countOfOldUsers, actualAmountOfMembers);
    } catch (SecurityException ex) {
        ex.printStackTrace();
        LOG.error("deassignUserMember: caught SecurityException rc=" + ex.getErrorId() + ", msg=" + ex.getMessage(), ex);
        fail(ex.getMessage());
    }
}
Also used : Group(org.apache.directory.fortress.core.model.Group) User(org.apache.directory.fortress.core.model.User) SecurityException(org.apache.directory.fortress.core.SecurityException)

Example 9 with Group

use of org.apache.directory.fortress.core.model.Group in project directory-fortress-core by apache.

the class GroupMgrImplTest method roleGroups.

private void roleGroups(String message, String[][] roles, List<Group> expectedGroups) {
    LogUtil.logIt(message);
    try {
        groupMgr = GroupMgrFactory.createInstance(TestUtils.getContext());
        for (String[] roleArray : roles) {
            Role role = RoleTestData.getRole(roleArray);
            List<Group> actualGroups = groupMgr.roleGroups(role);
            LOG.debug("roleGroups role [" + role.getName() + "] successful");
            assertNotNull(actualGroups);
            // The two list sizes better match or fail the test case.
            assertTrue(CLS_NM + "roleGroups list size test case", actualGroups.size() == expectedGroups.size());
            // For each actual group, check to see if it was in expected.  If not fail the test case.
            for (Group actualGroup : actualGroups) {
                assertTrue(CLS_NM + ".roleGroups actual group name [" + actualGroup.getName() + "] not found", expectedGroups.contains(actualGroup));
            // TODO : should compare members in expected groups to members in actual groups.
            }
        }
    } catch (SecurityException ex) {
        ex.printStackTrace();
        LOG.error("groupRoles: caught SecurityException rc=" + ex.getErrorId() + ", msg=" + ex.getMessage(), ex);
        fail(ex.getMessage());
    }
}
Also used : Role(org.apache.directory.fortress.core.model.Role) UserRole(org.apache.directory.fortress.core.model.UserRole) Group(org.apache.directory.fortress.core.model.Group) SecurityException(org.apache.directory.fortress.core.SecurityException)

Example 10 with Group

use of org.apache.directory.fortress.core.model.Group in project directory-fortress-core by apache.

the class GroupMgrImplTest method assignUserMember.

private void assignUserMember(String message, Group group, String[][] users) {
    LogUtil.logIt(message);
    try {
        groupMgr = GroupMgrFactory.createInstance(TestUtils.getContext());
        for (String[] userArray : users) {
            User user = UserTestData.getUser(userArray);
            groupMgr.assign(group, user.getUserId());
        }
        LOG.debug("assignUserMember group [" + group.getName() + "] successful");
        int countOfOldUsers = group.getMembers().size();
        int countOfNewUsers = users.length;
        // read from LDAP and get count of members
        Group groupFromLdap = groupMgr.read(group);
        int actualAmountOfMembers = groupFromLdap.getMembers().size();
        assertEquals(CLS_NM + ".assignUserMember failed members size check", countOfOldUsers + countOfNewUsers, actualAmountOfMembers);
    } catch (SecurityException ex) {
        ex.printStackTrace();
        LOG.error("assignUserMember: caught SecurityException rc=" + ex.getErrorId() + ", msg=" + ex.getMessage(), ex);
        fail(ex.getMessage());
    }
}
Also used : Group(org.apache.directory.fortress.core.model.Group) User(org.apache.directory.fortress.core.model.User) SecurityException(org.apache.directory.fortress.core.SecurityException)

Aggregations

Group (org.apache.directory.fortress.core.model.Group)33 SecurityException (org.apache.directory.fortress.core.SecurityException)19 FortRequest (org.apache.directory.fortress.core.model.FortRequest)7 FortResponse (org.apache.directory.fortress.core.model.FortResponse)7 Role (org.apache.directory.fortress.core.model.Role)5 UserRole (org.apache.directory.fortress.core.model.UserRole)4 Enumeration (java.util.Enumeration)3 User (org.apache.directory.fortress.core.model.User)3 GroupMgr (org.apache.directory.fortress.core.GroupMgr)2 Addgroup (org.apache.directory.fortress.core.ant.Addgroup)2 AdminRole (org.apache.directory.fortress.core.model.AdminRole)2 Test (org.junit.Test)2 AdminPermissionOperation (org.apache.directory.fortress.annotation.AdminPermissionOperation)1 PermObj (org.apache.directory.fortress.core.model.PermObj)1 Permission (org.apache.directory.fortress.core.model.Permission)1 Relationship (org.apache.directory.fortress.core.model.Relationship)1 RoleConstraint (org.apache.directory.fortress.core.model.RoleConstraint)1