use of org.apache.directory.ldap.client.api.LdapConnection in project directory-fortress-core by apache.
the class GroupDAO method create.
/**
* @param group
* @throws org.apache.directory.fortress.core.CreateException
*/
Group create(Group group) throws CreateException {
LdapConnection ld = null;
String nodeDn = getDn(group.getName(), group.getContextId());
try {
LOG.debug("create group dn [{}]", nodeDn);
Entry myEntry = new DefaultEntry(nodeDn);
myEntry.add(SchemaConstants.OBJECT_CLASS_AT, GROUP_OBJ_CLASS);
myEntry.add(SchemaConstants.CN_AT, group.getName());
// protocol is required:
myEntry.add(GROUP_PROTOCOL_ATTR_IMPL, group.getProtocol());
// type is required:
myEntry.add(GlobalIds.TYPE, group.getType().toString());
loadAttrs(group.getMembers(), myEntry, SchemaConstants.MEMBER_AT);
loadProperties(group.getProperties(), myEntry, GROUP_PROPERTY_ATTR_IMPL, '=');
if (StringUtils.isNotEmpty(group.getDescription())) {
myEntry.add(SchemaConstants.DESCRIPTION_AT, group.getDescription());
}
ld = getAdminConnection();
add(ld, myEntry);
} catch (LdapException e) {
String error = "create group node dn [" + nodeDn + "] caught LDAPException=" + e.getMessage();
throw new CreateException(GlobalErrIds.GROUP_ADD_FAILED, error, e);
} finally {
closeAdminConnection(ld);
}
return group;
}
use of org.apache.directory.ldap.client.api.LdapConnection in project directory-fortress-core by apache.
the class GroupDAO method remove.
/**
* This method will remove group node from diretory.
*
* @param group
* @throws org.apache.directory.fortress.core.RemoveException
*/
Group remove(Group group) throws RemoveException {
LdapConnection ld = null;
String nodeDn = getDn(group.getName(), group.getContextId());
LOG.debug("remove group dn [{}]", nodeDn);
try {
ld = getAdminConnection();
delete(ld, nodeDn, group);
} catch (LdapException e) {
String error = "remove group node dn [" + nodeDn + "] caught LDAPException=" + e.getMessage();
throw new RemoveException(GlobalErrIds.GROUP_DELETE_FAILED, error, e);
} finally {
closeAdminConnection(ld);
}
return group;
}
use of org.apache.directory.ldap.client.api.LdapConnection in project directory-fortress-core by apache.
the class GroupDAO method deassign.
/**
* @param entity
* @param userDn
* @return
* @throws org.apache.directory.fortress.core.UpdateException
*/
Group deassign(Group entity, String userDn) throws FinderException, UpdateException {
LdapConnection ld = null;
String dn = getDn(entity.getName(), entity.getContextId());
LOG.debug("deassign group property dn [{}], member dn [{}]", dn, userDn);
try {
List<Modification> mods = new ArrayList<Modification>();
mods.add(new DefaultModification(ModificationOperation.REMOVE_ATTRIBUTE, SchemaConstants.MEMBER_AT, userDn));
ld = getAdminConnection();
modify(ld, dn, mods, entity);
} catch (LdapException e) {
String error = "deassign group name [" + entity.getName() + "] user dn [" + userDn + "] caught " + "LDAPException=" + e.getMessage();
throw new UpdateException(GlobalErrIds.GROUP_USER_DEASSIGN_FAILED, error, e);
} finally {
closeAdminConnection(ld);
}
return get(entity);
}
use of org.apache.directory.ldap.client.api.LdapConnection in project directory-fortress-core by apache.
the class OrgUnitDAO method findByKey.
/**
* @param entity
* @return
* @throws FinderException
*/
OrgUnit findByKey(OrgUnit entity) throws FinderException {
OrgUnit oe = null;
LdapConnection ld = null;
Dn dn = getDn(entity);
try {
ld = getAdminConnection();
Entry findEntry = read(ld, dn, ORGUNIT_ATRS);
if (findEntry == null) {
String warning = "findByKey orgUnit name [" + entity.getName() + "] type [" + entity.getType() + "] COULD NOT FIND ENTRY for dn [" + dn + "]";
int errCode;
if (entity.getType() == OrgUnit.Type.PERM) {
errCode = GlobalErrIds.ORG_NOT_FOUND_PERM;
} else {
errCode = GlobalErrIds.ORG_NOT_FOUND_USER;
}
throw new FinderException(errCode, warning);
}
oe = getEntityFromLdapEntry(findEntry, 0, entity.getContextId());
} catch (LdapNoSuchObjectException e) {
String warning = "findByKey orgUnit name [" + entity.getName() + "] type [" + entity.getType() + "] COULD NOT FIND ENTRY for dn [" + dn + "]";
int errCode;
if (entity.getType() == OrgUnit.Type.PERM) {
errCode = GlobalErrIds.ORG_NOT_FOUND_PERM;
} else {
errCode = GlobalErrIds.ORG_NOT_FOUND_USER;
}
throw new FinderException(errCode, warning);
} catch (LdapException e) {
String error = "findByKey orgUnitName [" + entity.getName() + "] type [" + entity.getType() + "] dn [" + dn + "] caught LdapException=" + e;
int errCode;
if (entity.getType() == OrgUnit.Type.PERM) {
errCode = GlobalErrIds.ORG_READ_FAILED_PERM;
} else {
errCode = GlobalErrIds.ORG_READ_FAILED_USER;
}
throw new FinderException(errCode, error, e);
} finally {
closeAdminConnection(ld);
}
return oe;
}
use of org.apache.directory.ldap.client.api.LdapConnection in project directory-fortress-core by apache.
the class OrganizationalUnitDAO method remove.
/**
* @param oe
* @throws org.apache.directory.fortress.core.RemoveException
*/
void remove(OrganizationalUnit oe) throws RemoveException {
LdapConnection ld = null;
String nodeDn = SchemaConstants.OU_AT + "=" + oe.getName() + ",";
if (StringUtils.isNotEmpty(oe.getParent())) {
nodeDn += SchemaConstants.OU_AT + "=" + oe.getParent() + ",";
}
nodeDn += getRootDn(oe.getContextId(), GlobalIds.SUFFIX);
LOG.info("remove container dn [{}]", nodeDn);
try {
ld = getAdminConnection();
deleteRecursive(ld, nodeDn);
} catch (CursorException e) {
String error = "remove container node dn [" + nodeDn + "] caught CursorException=" + e.getMessage();
throw new RemoveException(GlobalErrIds.CNTR_DELETE_FAILED, error, e);
} catch (LdapException e) {
String error = "remove container node dn [" + nodeDn + "] caught LDAPException=" + e.getMessage();
throw new RemoveException(GlobalErrIds.CNTR_DELETE_FAILED, error, e);
} finally {
closeAdminConnection(ld);
}
}
Aggregations