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