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();
}
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();
}
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);
}
Aggregations