use of org.apache.directory.ldap.client.api.LdapConnection in project directory-fortress-core by apache.
the class ConfigDAO method remove.
/**
* @param name
* @throws org.apache.directory.fortress.core.RemoveException
*/
void remove(String name) throws RemoveException {
LdapConnection ld = null;
String dn = getDn(name);
LOG.info("remove dn [{}]", dn);
try {
ld = getAdminConnection();
delete(ld, dn);
} catch (LdapException e) {
String error = "remove dn [" + dn + "] LDAPException=" + e.getMessage();
throw new RemoveException(GlobalErrIds.FT_CONFIG_DELETE_FAILED, error, e);
} finally {
closeAdminConnection(ld);
}
}
use of org.apache.directory.ldap.client.api.LdapConnection in project directory-fortress-core by apache.
the class ConfigDAO method update.
/**
* @param name
* @param props
* @return
* @throws org.apache.directory.fortress.core.UpdateException
*/
Properties update(String name, Properties props) throws UpdateException {
LdapConnection ld = null;
String dn = getDn(name);
LOG.info("update dn [{}]", dn);
try {
List<Modification> mods = new ArrayList<Modification>();
if (PropUtil.isNotEmpty(props)) {
loadProperties(props, mods, GlobalIds.PROPS, true);
}
ld = getAdminConnection();
if (mods.size() > 0) {
ld = getAdminConnection();
modify(ld, dn, mods);
}
} catch (LdapException e) {
String error = "update dn [" + dn + "] caught LDAPException=" + e.getMessage();
throw new UpdateException(GlobalErrIds.FT_CONFIG_UPDATE_FAILED, error, e);
} finally {
closeAdminConnection(ld);
}
return props;
}
use of org.apache.directory.ldap.client.api.LdapConnection in project directory-fortress-core by apache.
the class ConfigDAO method create.
/**
* @param name
* @param props
* @return
* @throws org.apache.directory.fortress.core.CreateException
*/
Properties create(String name, Properties props) throws CreateException {
LdapConnection ld = null;
String dn = getDn(name);
LOG.info("create dn [{}]", dn);
try {
Entry myEntry = new DefaultEntry(dn);
myEntry.add(SchemaConstants.OBJECT_CLASS_AT, CONFIG_OBJ_CLASS);
ld = getAdminConnection();
myEntry.add(SchemaConstants.CN_AT, name);
loadProperties(props, myEntry, GlobalIds.PROPS);
add(ld, myEntry);
} catch (LdapEntryAlreadyExistsException e) {
String warning = "create config dn [" + dn + "] caught LdapEntryAlreadyExistsException=" + e.getMessage() + " msg=" + e.getMessage();
throw new CreateException(GlobalErrIds.FT_CONFIG_ALREADY_EXISTS, warning, e);
} catch (LdapException e) {
String error;
error = "create config dn [" + dn + "] caught LDAPException=" + e.getMessage();
LOG.error(error, e);
throw new CreateException(GlobalErrIds.FT_CONFIG_CREATE_FAILED, error, e);
} finally {
closeAdminConnection(ld);
}
return props;
}
use of org.apache.directory.ldap.client.api.LdapConnection in project directory-fortress-core by apache.
the class ConfigDAO method remove.
/**
* @param name
* @param props
* @return
* @throws org.apache.directory.fortress.core.UpdateException
*/
Properties remove(String name, Properties props) throws UpdateException {
LdapConnection ld = null;
String dn = getDn(name);
LOG.info("remove props dn [{}]", dn);
try {
List<Modification> mods = new ArrayList<Modification>();
if (PropUtil.isNotEmpty(props)) {
removeProperties(props, mods, GlobalIds.PROPS);
}
if (mods.size() > 0) {
ld = getAdminConnection();
modify(ld, dn, mods);
}
} catch (LdapException e) {
String error = "remove props dn [" + dn + "] caught LDAPException=" + e.getMessage();
throw new UpdateException(GlobalErrIds.FT_CONFIG_DELETE_PROPS_FAILED, error, e);
} finally {
closeAdminConnection(ld);
}
return props;
}
use of org.apache.directory.ldap.client.api.LdapConnection in project directory-fortress-core by apache.
the class GroupDAO method update.
/**
* @param group
* @return
* @throws org.apache.directory.fortress.core.CreateException
*/
Group update(Group group) throws FinderException, UpdateException {
LdapConnection ld = null;
String nodeDn = getDn(group.getName(), group.getContextId());
try {
LOG.debug("update group dn [{}]", nodeDn);
List<Modification> mods = new ArrayList<Modification>();
if (StringUtils.isNotEmpty(group.getDescription())) {
mods.add(new DefaultModification(ModificationOperation.REPLACE_ATTRIBUTE, SchemaConstants.DESCRIPTION_AT, group.getDescription()));
}
if (StringUtils.isNotEmpty(group.getProtocol())) {
mods.add(new DefaultModification(ModificationOperation.REPLACE_ATTRIBUTE, GROUP_PROTOCOL_ATTR_IMPL, group.getProtocol()));
}
loadAttrs(group.getMembers(), mods, SchemaConstants.MEMBER_AT);
loadProperties(group.getProperties(), mods, GROUP_PROPERTY_ATTR_IMPL, true, '=');
if (mods.size() > 0) {
ld = getAdminConnection();
modify(ld, nodeDn, mods, group);
}
} catch (LdapException e) {
String error = "update group node dn [" + nodeDn + "] caught LDAPException=" + e.getMessage();
throw new UpdateException(GlobalErrIds.GROUP_UPDATE_FAILED, error, e);
} finally {
closeAdminConnection(ld);
}
return get(group);
}
Aggregations