Search in sources :

Example 1 with Group

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

the class CommandLineInterpreter method processGroupCommand.

/**
 * @param commands
 * @param options
 */
private void processGroupCommand(Set<String> commands, Options options) {
    String command;
    try {
        if (commands.contains(ADD_GROUP)) {
            command = ADD_GROUP;
            LOG.info(command);
            Group group = options.getGroup();
            groupMgr.add(group);
        } else if (commands.contains(UPDATE_GROUP)) {
            command = UPDATE_GROUP;
            LOG.info(command);
            Group group = options.getGroup();
            groupMgr.update(group);
        } else if (commands.contains(DELETE_GROUP)) {
            command = DELETE_GROUP;
            LOG.info(command);
            Group group = options.getGroup();
            groupMgr.delete(group);
        } else if (commands.contains(READ_GROUP)) {
            command = READ_GROUP;
            LOG.info(command);
            Group group = options.getGroup();
            Group outGroup = groupMgr.read(group);
            printGroup(outGroup);
        } else if (commands.contains(FIND_GROUP)) {
            command = FIND_GROUP;
            LOG.info(command);
            Group inGroup = options.getGroup();
            List<Group> groups = groupMgr.find(inGroup);
            if (CollectionUtils.isNotEmpty(groups)) {
                for (Group outGroup : groups) {
                    printGroup(outGroup);
                }
            }
        } else if (commands.contains(ASSIGN_GROUP)) {
            command = ASSIGN_GROUP;
            LOG.info(command);
            Group group = options.getGroup();
            if (CollectionUtils.isNotEmpty(group.getMembers())) {
                for (String member : group.getMembers()) {
                    groupMgr.assign(group, member);
                }
            }
        } else if (commands.contains(DEASSIGN_GROUP)) {
            command = DEASSIGN_GROUP;
            LOG.info(command);
            Group group = options.getGroup();
            if (CollectionUtils.isNotEmpty(group.getMembers())) {
                for (String member : group.getMembers()) {
                    groupMgr.deassign(group, member);
                }
            }
        } else if (commands.contains(ADD_GROUP_PROP)) {
            command = ADD_GROUP_PROP;
            LOG.info(command);
            Group group = options.getGroup();
            if (PropUtil.isNotEmpty(group.getProperties())) {
                for (Enumeration<?> e = group.getProperties().propertyNames(); e.hasMoreElements(); ) {
                    String key = (String) e.nextElement();
                    String val = group.getProperty(key);
                    groupMgr.add(group, key, val);
                }
            }
        } else if (commands.contains(DELETE_GROUP_PROP)) {
            command = DELETE_GROUP_PROP;
            LOG.info(command);
            Group group = options.getGroup();
            if (PropUtil.isNotEmpty(group.getProperties())) {
                for (Enumeration<?> e = group.getProperties().propertyNames(); e.hasMoreElements(); ) {
                    String key = (String) e.nextElement();
                    String val = group.getProperty(key);
                    groupMgr.delete(group, key, val);
                }
            }
        } else {
            LOG.warn("unknown group operation detected");
            return;
        }
        LOG.info("command:{} was successful", command);
    } catch (SecurityException se) {
        String error = "processGroupCommand caught SecurityException=" + se + ", return code=" + se.getErrorId();
        LOG.error(error);
    }
}
Also used : Group(org.apache.directory.fortress.core.model.Group) Enumeration(java.util.Enumeration) SecurityException(org.apache.directory.fortress.core.SecurityException)

Example 2 with Group

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

the class Options method getGroup.

/**
 */
public Group getGroup() {
    Group group = new Group();
    group.setName(getName());
    group.setDescription(getDescription());
    group.setProtocol(getProtocol());
    updateAssigns(group);
    updateProperties(group);
    return group;
}
Also used : Group(org.apache.directory.fortress.core.model.Group)

Example 3 with Group

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

the class FortressAntTask method addGroupProperties.

/**
 * @throws BuildException An error occurred while building
 */
private void addGroupProperties() {
    if (addgroupproperties == null) {
        return;
    }
    // Loop through the entityclass elements
    for (Addgroupproperty addgroupproperty : addgroupproperties) {
        List<Group> groups = addgroupproperty.getGroups();
        for (Group group : groups) {
            if (PropUtil.isNotEmpty(group.getProperties())) {
                for (Enumeration<?> e = group.getProperties().propertyNames(); e.hasMoreElements(); ) {
                    // This LDAP attr is stored as a name-value pair separated by a ':'.
                    String key = (String) e.nextElement();
                    String val = group.getProperties().getProperty(key);
                    try {
                        groupMgr.add(group, key, val);
                    } catch (SecurityException se) {
                        LOG.warn("addGroupProperties tenant={} name [{}], key [{}], value [{}] caught SecurityException={}", getTenant(), group.getName(), key, val, se);
                    }
                }
            } else {
                LOG.info("addGroupProperties tenant={} name={}, no properties found", getTenant(), group.getName());
            }
        }
    }
}
Also used : Group(org.apache.directory.fortress.core.model.Group) SecurityException(org.apache.directory.fortress.core.SecurityException)

Example 4 with Group

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

the class GroupMgrRestImpl method read.

/**
 * {@inheritDoc}
 */
@Override
public Group read(Group group) throws SecurityException {
    VUtil.assertNotNull(group, GlobalErrIds.GROUP_NULL, CLS_NM + ".read");
    Group retGroup;
    FortRequest request = new FortRequest();
    request.setContextId(this.contextId);
    request.setEntity(group);
    if (this.adminSess != null) {
        request.setSession(adminSess);
    }
    String szRequest = RestUtils.marshal(request);
    String szResponse = RestUtils.getInstance().post(szRequest, HttpIds.GROUP_READ);
    FortResponse response = RestUtils.unmarshall(szResponse);
    if (response.getErrorCode() == 0) {
        retGroup = (Group) response.getEntity();
    } else {
        throw new SecurityException(response.getErrorCode(), response.getErrorMessage());
    }
    return retGroup;
}
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 5 with Group

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

the class GroupMgrRestImpl method add.

/**
 * {@inheritDoc}
 */
@Override
public Group add(Group group) throws SecurityException {
    VUtil.assertNotNull(group, GlobalErrIds.GROUP_NULL, CLS_NM + ".add");
    Group retGroup;
    FortRequest request = RestUtils.getRequest(this.contextId);
    request.setEntity(group);
    if (this.adminSess != null) {
        request.setSession(adminSess);
    }
    String szRequest = RestUtils.marshal(request);
    String szResponse = RestUtils.getInstance().post(szRequest, HttpIds.GROUP_ADD);
    FortResponse response = RestUtils.unmarshall(szResponse);
    if (response.getErrorCode() == 0) {
        retGroup = (Group) response.getEntity();
    } else {
        throw new org.apache.directory.fortress.core.SecurityException(response.getErrorCode(), response.getErrorMessage());
    }
    return retGroup;
}
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)

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