use of org.apache.directory.ldap.client.api.LdapConnection in project directory-fortress-core by apache.
the class OrganizationalUnitDAO method create.
/**
* @param oe
* @throws org.apache.directory.fortress.core.CreateException
*/
void create(OrganizationalUnit oe) throws CreateException {
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());
try {
LOG.info("create container dn [{}]", nodeDn);
Entry myEntry = new DefaultEntry(nodeDn, SchemaConstants.OBJECT_CLASS, SchemaConstants.ORGANIZATIONAL_UNIT_OC, SchemaConstants.OU_AT, oe.getName(), SchemaConstants.DESCRIPTION_AT, oe.getDescription());
ld = getAdminConnection();
add(ld, myEntry);
} catch (LdapException e) {
String error = "create container node dn [" + nodeDn + "] caught LdapException=" + e;
throw new CreateException(GlobalErrIds.CNTR_CREATE_FAILED, error, e);
} finally {
closeAdminConnection(ld);
}
}
use of org.apache.directory.ldap.client.api.LdapConnection in project directory-fortress-core by apache.
the class SdDAO method getSD.
/**
* @param sdSet
* @return
* @throws FinderException
*/
SDSet getSD(SDSet sdSet) throws FinderException {
SDSet entity = null;
LdapConnection ld = null;
String dn = getDn(sdSet.getName(), sdSet.getContextId());
try {
ld = getAdminConnection();
Entry findEntry = read(ld, dn, SD_SET_ATRS);
if (findEntry == null) {
String warning = "getSD no entry found dn [" + dn + "]";
throw new FinderException(GlobalErrIds.SSD_NOT_FOUND, warning);
}
entity = unloadLdapEntry(findEntry, 0);
} catch (LdapNoSuchObjectException e) {
String warning = "getSD Obj COULD NOT FIND ENTRY for dn [" + dn + "]";
throw new FinderException(GlobalErrIds.SSD_NOT_FOUND, warning);
} catch (LdapException e) {
String error = "getSSD dn [" + dn + "] LEXCD=" + e;
int errCode;
if (sdSet.getType() == SDSet.SDType.DYNAMIC) {
errCode = GlobalErrIds.DSD_READ_FAILED;
} else {
errCode = GlobalErrIds.SSD_READ_FAILED;
}
throw new FinderException(errCode, error, e);
} finally {
closeAdminConnection(ld);
}
return entity;
}
use of org.apache.directory.ldap.client.api.LdapConnection in project directory-fortress-core by apache.
the class SdDAO method search.
/**
* Given an SSD name and type, find matching object in the directory.
* @param sdset requires name and type.
* @return List of matching SDSets.
* @throws org.apache.directory.fortress.core.FinderException
*/
List<SDSet> search(SDSet sdset) throws FinderException {
List<SDSet> sdList = new ArrayList<>();
LdapConnection ld = null;
String ssdRoot = getSdRoot(sdset.getContextId());
String objectClass = SSD_OBJECT_CLASS_NM;
if (sdset.getType() == SDSet.SDType.DYNAMIC) {
objectClass = DSD_OBJECT_CLASS_NM;
}
try {
String searchVal = encodeSafeText(sdset.getName(), GlobalIds.ROLE_LEN);
String filter = GlobalIds.FILTER_PREFIX + objectClass + ")(" + SD_SET_NM + "=" + searchVal + "*))";
ld = getAdminConnection();
SearchCursor searchResults = search(ld, ssdRoot, SearchScope.SUBTREE, filter, SD_SET_ATRS, false, GlobalIds.BATCH_SIZE);
long sequence = 0;
while (searchResults.next()) {
sdList.add(unloadLdapEntry(searchResults.getEntry(), sequence++));
}
} catch (LdapException e) {
String error = "search sdset name [" + sdset.getName() + "] type [" + sdset.getType() + "] caught LdapException=" + e.getMessage();
int errCode;
if (sdset.getType() == SDSet.SDType.DYNAMIC) {
errCode = GlobalErrIds.DSD_SEARCH_FAILED;
} else {
errCode = GlobalErrIds.SSD_SEARCH_FAILED;
}
throw new FinderException(errCode, error, e);
} catch (CursorException e) {
String error = "search sdset name [" + sdset.getName() + "] type [" + sdset.getType() + "] caught CursorException=" + e.getMessage();
int errCode;
if (sdset.getType() == SDSet.SDType.DYNAMIC) {
errCode = GlobalErrIds.DSD_SEARCH_FAILED;
} else {
errCode = GlobalErrIds.SSD_SEARCH_FAILED;
}
throw new FinderException(errCode, error, e);
} finally {
closeAdminConnection(ld);
}
return sdList;
}
use of org.apache.directory.ldap.client.api.LdapConnection in project directory-fortress-core by apache.
the class SdDAO method search.
/**
* @param role
* @return
* @throws org.apache.directory.fortress.core.FinderException
*/
List<SDSet> search(Role role, SDSet.SDType type) throws FinderException {
List<SDSet> sdList = new ArrayList<>();
LdapConnection ld = null;
String ssdRoot = getSdRoot(role.getContextId());
String objectClass = SSD_OBJECT_CLASS_NM;
if (type == SDSet.SDType.DYNAMIC) {
objectClass = DSD_OBJECT_CLASS_NM;
}
try {
String roleVal = encodeSafeText(role.getName(), GlobalIds.ROLE_LEN);
StringBuilder filterbuf = new StringBuilder();
filterbuf.append(GlobalIds.FILTER_PREFIX);
filterbuf.append(objectClass);
filterbuf.append(")(");
// Include any parents target role may have:
Set<String> roles = RoleUtil.getInstance().getAscendants(role.getName(), role.getContextId());
if (CollectionUtils.isNotEmpty(roles)) {
filterbuf.append("|(");
filterbuf.append(ROLES);
filterbuf.append("=");
filterbuf.append(roleVal);
filterbuf.append(")");
for (String uRole : roles) {
filterbuf.append("(");
filterbuf.append(ROLES);
filterbuf.append("=");
filterbuf.append(uRole);
filterbuf.append(")");
}
filterbuf.append(")");
} else {
filterbuf.append(ROLES);
filterbuf.append("=");
filterbuf.append(roleVal);
filterbuf.append(")");
}
filterbuf.append(")");
ld = getAdminConnection();
SearchCursor searchResults = search(ld, ssdRoot, SearchScope.SUBTREE, filterbuf.toString(), SD_SET_ATRS, false, GlobalIds.BATCH_SIZE);
long sequence = 0;
while (searchResults.next()) {
sdList.add(unloadLdapEntry(searchResults.getEntry(), sequence++));
}
} catch (LdapException e) {
String error = "search role [" + role.getName() + "] type [" + type + "] caught LdapException=" + e.getMessage();
int errCode;
if (type == SDSet.SDType.DYNAMIC) {
errCode = GlobalErrIds.DSD_SEARCH_FAILED;
} else {
errCode = GlobalErrIds.SSD_SEARCH_FAILED;
}
throw new FinderException(errCode, error, e);
} catch (CursorException e) {
String error = "search role [" + role.getName() + "] type [" + type + "] caught CursorException=" + e.getMessage();
int errCode;
if (type == SDSet.SDType.DYNAMIC) {
errCode = GlobalErrIds.DSD_SEARCH_FAILED;
} else {
errCode = GlobalErrIds.SSD_SEARCH_FAILED;
}
throw new FinderException(errCode, error, e);
} finally {
closeAdminConnection(ld);
}
return sdList;
}
use of org.apache.directory.ldap.client.api.LdapConnection in project directory-fortress-core by apache.
the class SuffixDAO method create.
/**
* @param se
* @throws org.apache.directory.fortress.core.CreateException
*/
void create(Suffix se) throws CreateException {
LdapConnection ld = null;
String nodeDn = getDn(se);
try {
LOG.info("create suffix dn [{}]", nodeDn);
Entry myEntry = new DefaultEntry(nodeDn);
myEntry.add(SchemaConstants.OBJECT_CLASS_AT, SUFFIX_OBJ_CLASS);
myEntry.add(SchemaConstants.DC_AT, se.getName());
myEntry.add(SchemaConstants.O_AT, se.getDescription());
ld = getAdminConnection();
add(ld, myEntry);
} catch (LdapException e) {
String error = "create container node dn [" + nodeDn + "] caught LDAPException=" + e.getMessage();
throw new CreateException(GlobalErrIds.SUFX_CREATE_FAILED, error, e);
} finally {
closeAdminConnection(ld);
}
}
Aggregations