use of org.apache.directory.ldap.client.api.LdapConnection in project directory-fortress-core by apache.
the class PermDAO method findPermissionOperations.
List<Permission> findPermissionOperations(PermObj permObj) throws FinderException {
List<Permission> permList = new ArrayList<>();
LdapConnection ld = null;
String permRoot = getRootDn(permObj.isAdmin(), permObj.getContextId());
try {
String permObjVal = encodeSafeText(permObj.getObjName(), GlobalIds.PERM_LEN);
StringBuilder filterbuf = new StringBuilder();
filterbuf.append(GlobalIds.FILTER_PREFIX);
filterbuf.append(PERM_OP_OBJECT_CLASS_NAME);
filterbuf.append(")(");
filterbuf.append(GlobalIds.POBJ_NAME);
filterbuf.append("=");
filterbuf.append(permObjVal);
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++, permObj.isAdmin()));
}
} catch (LdapException e) {
String error = "findPermissions caught LdapException=" + e.getMessage();
throw new FinderException(GlobalErrIds.PERM_SEARCH_FAILED, error, e);
} catch (CursorException e) {
String error = "findPermissions caught CursorException=" + e.getMessage();
throw new FinderException(GlobalErrIds.PERM_SEARCH_FAILED, error, e);
} finally {
closeAdminConnection(ld);
}
return permList;
}
use of org.apache.directory.ldap.client.api.LdapConnection in project directory-fortress-core by apache.
the class PermDAO method revoke.
/**
* @param pOp
* @param role
* @throws org.apache.directory.fortress.core.UpdateException
*
* @throws org.apache.directory.fortress.core.FinderException
*/
void revoke(Permission pOp, Role role) throws UpdateException, FinderException {
LdapConnection ld = null;
String dn = getDn(pOp, pOp.getContextId());
try {
List<Modification> mods = new ArrayList<Modification>();
mods.add(new DefaultModification(ModificationOperation.REMOVE_ATTRIBUTE, ROLES, role.getName()));
ld = getAdminConnection();
modify(ld, dn, mods, pOp);
} catch (LdapNoSuchAttributeException e) {
String warning = "revoke perm object [" + pOp.getObjName() + "] operation [" + pOp.getOpName() + "] name [" + role.getName() + "] assignment does not exist.";
throw new FinderException(GlobalErrIds.PERM_ROLE_NOT_EXIST, warning);
} catch (LdapException e) {
String error = "revoke perm object [" + pOp.getObjName() + "] operation [" + pOp.getOpName() + "] name [" + role.getName() + "] caught LdapException=" + e.getMessage();
throw new UpdateException(GlobalErrIds.PERM_REVOKE_FAILED, error, e);
} finally {
closeAdminConnection(ld);
}
}
use of org.apache.directory.ldap.client.api.LdapConnection in project directory-fortress-core by apache.
the class PermDAO method getPermAttributeSet.
PermissionAttributeSet getPermAttributeSet(PermissionAttributeSet permAttributeSet) throws FinderException {
PermissionAttributeSet entity = null;
LdapConnection ld = null;
String dn = getDn(permAttributeSet, permAttributeSet.getContextId());
try {
ld = getAdminConnection();
Entry findEntry = read(ld, dn, PERMISION_ATTRIBUTE_SET_ATRS);
if (findEntry == null) {
String warning = "getPermAttributeSet no entry found dn [" + dn + "]";
throw new FinderException(GlobalErrIds.PERM_ATTRIBUTE_SET_NOT_FOUND, warning);
}
entity = unloadPASetLdapEntry(findEntry, 0);
// find permission attributes for this set
entity.setAttributes(this.findPermissionAttributes(entity));
} catch (LdapNoSuchObjectException e) {
String warning = "getPermAttributeSet COULD NOT FIND ENTRY for dn [" + dn + "]";
throw new FinderException(GlobalErrIds.PERM_ATTRIBUTE_SET_NOT_FOUND, warning);
} catch (LdapException e) {
String error = "getPermAttributeSet dn [" + dn + "] caught LdapException=" + e.getMessage();
throw new FinderException(GlobalErrIds.PERM_ATTRIBUTE_SET_NOT_FOUND, 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 PermDAO method findAnyPermissions.
/**
* Uses substring filters to allow any permission matching the passed in obj and op names.
*
* @param permission
* @return
* @throws org.apache.directory.fortress.core.FinderException
*/
List<Permission> findAnyPermissions(Permission permission) throws FinderException {
List<Permission> permList = new ArrayList<>();
LdapConnection ld = null;
String permRoot = getRootDn(permission.isAdmin(), permission.getContextId());
try {
String permObjVal = encodeSafeText(permission.getObjName(), GlobalIds.PERM_LEN);
String permOpVal = encodeSafeText(permission.getOpName(), GlobalIds.PERM_LEN);
StringBuilder filterbuf = new StringBuilder();
filterbuf.append(GlobalIds.FILTER_PREFIX);
filterbuf.append(PERM_OP_OBJECT_CLASS_NAME);
filterbuf.append(")(|");
if (permObjVal != null && permObjVal != "") {
filterbuf.append("(");
filterbuf.append(GlobalIds.POBJ_NAME);
filterbuf.append("=*");
filterbuf.append(permObjVal);
filterbuf.append("*)");
}
if (permOpVal != null && permOpVal != "") {
filterbuf.append("(");
filterbuf.append(GlobalIds.POP_NAME);
filterbuf.append("=*");
filterbuf.append(permOpVal);
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++, permission.isAdmin()));
}
} catch (LdapException e) {
String error = "findAnyPermissions caught LdapException=" + e.getMessage();
throw new FinderException(GlobalErrIds.PERM_SEARCH_FAILED, error, e);
} catch (CursorException e) {
String error = "findAnyPermissions caught CursorException=" + e.getMessage();
throw new FinderException(GlobalErrIds.PERM_SEARCH_FAILED, error, e);
} finally {
closeAdminConnection(ld);
}
return permList;
}
use of org.apache.directory.ldap.client.api.LdapConnection in project directory-fortress-core by apache.
the class PermDAO method deleteAttributeSet.
/**
* @param entity
* @throws RemoveException
*/
void deleteAttributeSet(PermissionAttributeSet entity) throws RemoveException {
LdapConnection ld = null;
String dn = getDn(entity, entity.getContextId());
try {
ld = getAdminConnection();
deleteRecursive(ld, dn, entity);
} catch (LdapException e) {
String error = "deleteAttributeSet name [" + entity.getName() + "]" + " caught LdapException=" + e.getMessage();
throw new RemoveException(GlobalErrIds.PERM_ATTRIBUTE_SET_DELETE_FAILED, error, e);
} catch (CursorException e) {
String error = "deleteAttributeSet name [" + entity.getName() + "] " + " caught LdapException=" + e.getMessage();
throw new RemoveException(GlobalErrIds.PERM_ATTRIBUTE_SET_DELETE_FAILED, error, e);
} finally {
closeAdminConnection(ld);
}
}
Aggregations