use of org.apache.directory.fortress.core.FinderException 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.fortress.core.FinderException 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.fortress.core.FinderException 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.fortress.core.FinderException 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.fortress.core.FinderException in project directory-fortress-core by apache.
the class UserDAO method findUsers.
/**
* @param user
* @return
* @throws FinderException
*/
List<User> findUsers(User user) throws FinderException {
List<User> userList = new ArrayList<>();
LdapConnection ld = null;
String userRoot = getRootDn(user.getContextId(), GlobalIds.USER_ROOT);
try {
// String filter;
StringBuilder filterbuf = new StringBuilder();
if (StringUtils.isNotEmpty(user.getUserId())) {
// place a wild card after the input userId:
String searchVal = encodeSafeText(user.getUserId(), GlobalIds.USERID_LEN);
filterbuf.append(GlobalIds.FILTER_PREFIX);
filterbuf.append(Config.getInstance().getProperty(USER_OBJECT_CLASS));
filterbuf.append(")(");
filterbuf.append(SchemaConstants.UID_AT);
filterbuf.append("=");
filterbuf.append(searchVal);
filterbuf.append("*))");
} else if (StringUtils.isNotEmpty(user.getInternalId())) {
// internalUserId search
String searchVal = encodeSafeText(user.getInternalId(), GlobalIds.USERID_LEN);
// this is not a wildcard search. Must be exact match.
filterbuf.append(GlobalIds.FILTER_PREFIX);
filterbuf.append(Config.getInstance().getProperty(USER_OBJECT_CLASS));
filterbuf.append(")(");
filterbuf.append(GlobalIds.FT_IID);
filterbuf.append("=");
filterbuf.append(searchVal);
filterbuf.append("))");
} else {
// Beware - returns ALL users!!:"
filterbuf.append("(objectclass=");
filterbuf.append(Config.getInstance().getProperty(USER_OBJECT_CLASS));
filterbuf.append(")");
}
ld = getAdminConnection();
SearchCursor searchResults = search(ld, userRoot, SearchScope.ONELEVEL, filterbuf.toString(), defaultAtrs, false, GlobalIds.BATCH_SIZE);
long sequence = 0;
while (searchResults.next()) {
userList.add(unloadLdapEntry(searchResults.getEntry(), sequence++, user.getContextId()));
}
} catch (LdapException e) {
String warning = "findUsers userRoot [" + userRoot + "] caught LDAPException=" + e.getMessage();
throw new FinderException(GlobalErrIds.USER_SEARCH_FAILED, warning, e);
} catch (CursorException e) {
String warning = "findUsers userRoot [" + userRoot + "] caught LDAPException=" + e.getMessage();
throw new FinderException(GlobalErrIds.USER_SEARCH_FAILED, warning, e);
} finally {
closeAdminConnection(ld);
}
return userList;
}
Aggregations