Search in sources :

Example 31 with Group

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

the class GroupMgrConsole method addProperty.

void addProperty() {
    try {
        Group group = new Group();
        ReaderUtil.clearScreen();
        System.out.println("Enter group name:");
        group.setName(ReaderUtil.readLn());
        System.out.println("Enter property key:");
        String key = ReaderUtil.readLn();
        System.out.println("Enter property value:");
        String value = ReaderUtil.readLn();
        groupMgr.add(group, key, value);
        System.out.println("Add property to Group successful");
        System.out.println("ENTER to continue");
    } catch (SecurityException e) {
        LOG.error("addProperty caught SecurityException rc=" + e.getErrorId() + ", msg=" + e.getMessage(), e);
    }
    ReaderUtil.readChar();
}
Also used : Group(org.apache.directory.fortress.core.model.Group)

Example 32 with Group

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

the class GroupMgrConsole method delete.

/**
 * Description of the Method
 */
void delete() {
    try {
        ReaderUtil.clearScreen();
        System.out.println("Enter group name:");
        String name = ReaderUtil.readLn();
        Group group = new Group();
        group.setName(name);
        groupMgr.delete(group);
        System.out.println("Group successfully deleted");
        System.out.println("ENTER to continue");
    } catch (SecurityException e) {
        LOG.error("delete caught SecurityException rc=" + e.getErrorId() + ", msg=" + e.getMessage(), e);
    }
    ReaderUtil.readChar();
}
Also used : Group(org.apache.directory.fortress.core.model.Group)

Example 33 with Group

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

the class AdminMgrImpl method deleteRole.

/**
 * {@inheritDoc}
 */
@Override
@AdminPermissionOperation
public void deleteRole(Role role) throws SecurityException {
    String methodName = "deleteRole";
    assertContext(CLS_NM, methodName, role, GlobalErrIds.ROLE_NULL);
    setEntitySession(CLS_NM, methodName, role);
    int numChildren = RoleUtil.getInstance().numChildren(role.getName(), role.getContextId());
    if (numChildren > 0) {
        String error = methodName + " role [" + role.getName() + "] must remove [" + numChildren + "] descendants before deletion";
        LOG.error(error);
        throw new SecurityException(GlobalErrIds.HIER_DEL_FAILED_HAS_CHILD, error, null);
    }
    // Read the Role from LDAP:
    Role outRole = roleP.read(role);
    outRole.setContextId(role.getContextId());
    // deassign all groups assigned to this role first (because of schema's configGroup class constraints)
    List<Group> groups = groupP.roleGroups(outRole);
    for (Group group : groups) {
        group.setContextId(this.contextId);
        groupP.deassign(group, outRole.getDn());
    }
    // If user membership associated with role, remove the role object:
    if (Config.getInstance().isRoleOccupant()) {
        // this reads the role object itself:
        List<User> users = userP.getAssignedUsers(role);
        if (users != null) {
            for (User ue : users) {
                UserRole uRole = new UserRole(ue.getUserId(), role.getName());
                setAdminData(CLS_NM, methodName, uRole);
                deassignUser(uRole);
            }
        }
    } else {
        // search for all users assigned this role and deassign:
        List<String> userIds = userP.getAssignedUserIds(role);
        for (String userId : userIds) {
            UserRole uRole = new UserRole(userId, role.getName());
            setAdminData(CLS_NM, methodName, uRole);
            deassignUser(uRole);
        }
    }
    // Now remove the role association from all permissions:
    permP.remove(role);
    // remove all parent relationships from the role graph:
    Set<String> parents = RoleUtil.getInstance().getParents(role.getName(), this.contextId);
    if (parents != null) {
        for (String parent : parents) {
            RoleUtil.getInstance().updateHier(this.contextId, new Relationship(role.getName().toUpperCase(), parent.toUpperCase()), Hier.Op.REM);
        }
    }
    // Finally, delete the role object:
    roleP.delete(role);
}
Also used : AdminRole(org.apache.directory.fortress.core.model.AdminRole) Role(org.apache.directory.fortress.core.model.Role) UserRole(org.apache.directory.fortress.core.model.UserRole) Group(org.apache.directory.fortress.core.model.Group) User(org.apache.directory.fortress.core.model.User) UserRole(org.apache.directory.fortress.core.model.UserRole) Relationship(org.apache.directory.fortress.core.model.Relationship) SecurityException(org.apache.directory.fortress.core.SecurityException) RoleConstraint(org.apache.directory.fortress.core.model.RoleConstraint) AdminPermissionOperation(org.apache.directory.fortress.annotation.AdminPermissionOperation)

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