use of org.apache.directory.fortress.core.FinderException in project directory-fortress-core by apache.
the class PermDAO method getPerm.
/**
* @param permObj
* @return
* @throws org.apache.directory.fortress.core.FinderException
*/
PermObj getPerm(PermObj permObj) throws FinderException {
PermObj entity = null;
LdapConnection ld = null;
String dn = GlobalIds.POBJ_NAME + "=" + permObj.getObjName() + "," + getRootDn(permObj.isAdmin(), permObj.getContextId());
try {
ld = getAdminConnection();
Entry findEntry = read(ld, dn, PERMISION_OBJ_ATRS);
if (findEntry == null) {
String warning = "getPerm Obj no entry found dn [" + dn + "]";
throw new FinderException(GlobalErrIds.PERM_OBJ_NOT_FOUND, warning);
}
entity = unloadPobjLdapEntry(findEntry, 0, permObj.isAdmin());
} catch (LdapNoSuchObjectException e) {
String warning = "getPerm Obj COULD NOT FIND ENTRY for dn [" + dn + "]";
throw new FinderException(GlobalErrIds.PERM_OBJ_NOT_FOUND, warning);
} catch (LdapException e) {
String error = "getPerm Obj dn [" + dn + "] caught LdapException=" + e.getMessage();
throw new FinderException(GlobalErrIds.PERM_READ_OBJ_FAILED, error, e);
} finally {
closeAdminConnection(ld);
}
return entity;
}
use of org.apache.directory.fortress.core.FinderException in project directory-fortress-core by apache.
the class PermDAO method getPerm.
/**
* @param permission
* @return
* @throws org.apache.directory.fortress.core.FinderException
*/
Permission getPerm(Permission permission) throws FinderException {
Permission entity = null;
LdapConnection ld = null;
String dn = getOpRdn(permission.getOpName(), permission.getObjId()) + "," + GlobalIds.POBJ_NAME + "=" + permission.getObjName() + "," + getRootDn(permission.isAdmin(), permission.getContextId());
try {
ld = getAdminConnection();
Entry findEntry = read(ld, dn, PERMISSION_OP_ATRS);
if (findEntry == null) {
String warning = "getPerm no entry found dn [" + dn + "]";
throw new FinderException(GlobalErrIds.PERM_OP_NOT_FOUND, warning);
}
entity = unloadPopLdapEntry(findEntry, 0, permission.isAdmin());
} catch (LdapNoSuchObjectException e) {
String warning = "getPerm Op COULD NOT FIND ENTRY for dn [" + dn + "]";
throw new FinderException(GlobalErrIds.PERM_OP_NOT_FOUND, warning);
} catch (LdapException e) {
String error = "getUser [" + dn + "] caught LdapException=" + e.getMessage();
throw new FinderException(GlobalErrIds.PERM_READ_OP_FAILED, error, e);
} finally {
closeAdminConnection(ld);
}
return entity;
}
use of org.apache.directory.fortress.core.FinderException in project directory-fortress-core by apache.
the class PermDAO method findPermissions.
/**
* @param session
* @return
* @throws org.apache.directory.fortress.core.FinderException
*/
List<Permission> findPermissions(Session session, boolean isAdmin) throws FinderException {
List<Permission> permList = new ArrayList<>();
LdapConnection ld = null;
String permRoot = getRootDn(isAdmin, session.getContextId());
try {
StringBuilder filterbuf = new StringBuilder();
filterbuf.append(GlobalIds.FILTER_PREFIX);
filterbuf.append(PERM_OP_OBJECT_CLASS_NAME);
filterbuf.append(")(|");
if (!session.isGroupSession()) {
filterbuf.append("(");
filterbuf.append(USERS);
filterbuf.append("=");
filterbuf.append(session.getUserId());
filterbuf.append(")");
}
Set<String> roles;
if (isAdmin) {
roles = AdminRoleUtil.getInheritedRoles(session.getAdminRoles(), session.getContextId());
} else {
roles = RoleUtil.getInstance().getInheritedRoles(session.getRoles(), session.getContextId());
}
if (CollectionUtils.isNotEmpty(roles)) {
for (String uRole : roles) {
filterbuf.append("(");
filterbuf.append(ROLES);
filterbuf.append("=");
filterbuf.append(uRole);
filterbuf.append(")");
}
}
filterbuf.append("))");
ld = getAdminConnection();
SearchCursor searchResults = search(ld, permRoot, SearchScope.SUBTREE, filterbuf.toString(), PERMISSION_OP_ATRS, false, GlobalIds.BATCH_SIZE);
long sequence = 0;
while (searchResults.next()) {
permList.add(unloadPopLdapEntry(searchResults.getEntry(), sequence++, isAdmin));
}
} catch (LdapException e) {
String error = "findPermissions user [" + session.getUserId() + "] caught LdapException in PermDAO.findPermissions=" + e.getMessage();
throw new FinderException(GlobalErrIds.PERM_SESS_SEARCH_FAILED, error, e);
} catch (CursorException e) {
String error = "findPermissions user [" + session.getUserId() + "] caught CursorException in PermDAO.findPermissions=" + e.getMessage();
throw new FinderException(GlobalErrIds.PERM_SESS_SEARCH_FAILED, error, e);
} finally {
closeAdminConnection(ld);
}
return permList;
}
use of org.apache.directory.fortress.core.FinderException in project directory-fortress-core by apache.
the class PermP method remove.
/**
* Remove the Admin Role assignment attribute from all Admin permssions. This method is called by DelAdminMgrImpl
* when the AdminRole is being deleted.
*
* @param role contains the name of AdminRole targeted for attribute removal.
* @throws SecurityException in the event of DAO search error.
*/
void remove(AdminRole role) throws SecurityException {
List<Permission> list;
try {
list = search(role);
for (Permission perm : list) {
perm.setAdmin(true);
revoke(perm, role);
}
} catch (FinderException fe) {
String error = "remove admin role [" + role.getName() + "] caught FinderException=" + fe;
throw new SecurityException(GlobalErrIds.PERM_BULK_ADMINROLE_REVOKE_FAILED, error, fe);
}
}
use of org.apache.directory.fortress.core.FinderException in project directory-fortress-core by apache.
the class PolicyDAO method getPolicy.
/**
* @param policy
* @return
* @throws org.apache.directory.fortress.core.FinderException
*/
PwPolicy getPolicy(PwPolicy policy) throws FinderException {
PwPolicy entity = null;
LdapConnection ld = null;
String dn = getDn(policy);
try {
ld = getAdminConnection();
Entry findEntry = read(ld, dn, PASSWORD_POLICY_ATRS);
entity = unloadLdapEntry(findEntry, 0);
} catch (LdapNoSuchObjectException e) {
String warning = "getPolicy Obj COULD NOT FIND ENTRY for dn [" + dn + "]";
throw new FinderException(GlobalErrIds.PSWD_NOT_FOUND, warning);
} catch (LdapException e) {
String error = "getPolicy name [" + policy.getName() + "] caught LdapException=" + e.getMessage();
throw new FinderException(GlobalErrIds.PSWD_READ_FAILED, error, e);
} finally {
closeAdminConnection(ld);
}
return entity;
}
Aggregations