Search in sources :

Example 51 with SDSet

use of org.apache.directory.fortress.core.model.SDSet in project directory-fortress-core by apache.

the class SdDAO method search.

/**
 * @param roles
 * @param sdSet
 * @return
 * @throws org.apache.directory.fortress.core.FinderException
 */
Set<SDSet> search(Set<String> roles, SDSet sdSet) throws FinderException {
    Set<SDSet> sdList = new HashSet<>();
    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 {
        if (CollectionUtils.isNotEmpty(roles)) {
            StringBuilder filterbuf = new StringBuilder();
            filterbuf.append(GlobalIds.FILTER_PREFIX);
            filterbuf.append(objectClass);
            filterbuf.append(")(|");
            for (String rle : roles) {
                filterbuf.append("(");
                filterbuf.append(ROLES);
                filterbuf.append("=");
                filterbuf.append(rle);
                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 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 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;
}
Also used : SDSet(org.apache.directory.fortress.core.model.SDSet) FinderException(org.apache.directory.fortress.core.FinderException) CursorException(org.apache.directory.api.ldap.model.cursor.CursorException) SearchCursor(org.apache.directory.api.ldap.model.cursor.SearchCursor) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) HashSet(java.util.HashSet) LdapConnection(org.apache.directory.ldap.client.api.LdapConnection)

Example 52 with SDSet

use of org.apache.directory.fortress.core.model.SDSet in project directory-fortress-core by apache.

the class SdDAO method unloadLdapEntry.

/**
 * @param le
 * @return
 * @throws LdapInvalidAttributeValueException
 * @throws LdapException
 */
private SDSet unloadLdapEntry(Entry le, long sequence) throws LdapInvalidAttributeValueException {
    SDSet entity = new ObjectFactory().createSDset();
    entity.setSequenceId(sequence);
    entity.setId(getAttribute(le, GlobalIds.FT_IID));
    entity.setName(getAttribute(le, SD_SET_NM));
    entity.setDescription(getAttribute(le, SchemaConstants.DESCRIPTION_AT));
    entity.setMembers(getAttributeSet(le, ROLES));
    String szCard = getAttribute(le, SD_SET_CARDINALITY);
    entity.setCardinality(Integer.valueOf(szCard));
    return entity;
}
Also used : SDSet(org.apache.directory.fortress.core.model.SDSet) ObjectFactory(org.apache.directory.fortress.core.model.ObjectFactory)

Example 53 with SDSet

use of org.apache.directory.fortress.core.model.SDSet in project directory-fortress-core by apache.

the class SdP method read.

/**
 * Return a fully populated SDSet entity for a given STATIC or DYNAMIC SDSet name.  If matching record not found a
 * SecurityException will be thrown.
 *
 * @param entity contains full SDSet name used for STATIC or DYNAMIC data sets in directory.
 * @return SDSet entity containing all attributes associated with ou in directory.
 * @throws SecurityException in the event SDSet not found or DAO search error.
 */
SDSet read(SDSet entity) throws SecurityException {
    SDSet sde;
    // The assumption is this method is called from ReviewMgr.ssdRoleSetRoles or ReviewMgr.dsdRoleSetRoles.
    // If called from ReviewMgr, the object class type will be passed in:
    SDSet.SDType type = entity.getType();
    sde = sdDao.getSD(entity);
    // Load the previously saved type onto the return entity:
    sde.setType(type);
    return sde;
}
Also used : SDSet(org.apache.directory.fortress.core.model.SDSet)

Example 54 with SDSet

use of org.apache.directory.fortress.core.model.SDSet in project directory-fortress-core by apache.

the class AdminMgrImpl method deleteSsdRoleMember.

/**
 * {@inheritDoc}
 */
@Override
@AdminPermissionOperation
public SDSet deleteSsdRoleMember(SDSet ssdSet, Role role) throws SecurityException {
    String methodName = "deleteSsdRoleMember";
    assertContext(CLS_NM, methodName, ssdSet, GlobalErrIds.SSD_NULL);
    assertContext(CLS_NM, methodName, role, GlobalErrIds.ROLE_NULL);
    setEntitySession(CLS_NM, methodName, ssdSet);
    SDSet entity = sdP.read(ssdSet);
    entity.setContextId(this.contextId);
    entity.delMember(role.getName());
    // when removing last role member a placeholder must be left in data set:
    if (entity.getMembers().isEmpty()) {
        entity.addMember(GlobalIds.NONE);
    }
    setAdminData(CLS_NM, methodName, entity);
    SDSet ssdOut = sdP.update(entity);
    // remove any references to the old SSD from cache:
    clearSSDCache(role);
    return ssdOut;
}
Also used : SDSet(org.apache.directory.fortress.core.model.SDSet) AdminPermissionOperation(org.apache.directory.fortress.annotation.AdminPermissionOperation)

Example 55 with SDSet

use of org.apache.directory.fortress.core.model.SDSet in project directory-fortress-core by apache.

the class AdminMgrImpl method addSsdRoleMember.

/**
 * {@inheritDoc}
 */
@Override
@AdminPermissionOperation
public SDSet addSsdRoleMember(SDSet ssdSet, Role role) throws SecurityException {
    String methodName = "addSsdRoleMember";
    assertContext(CLS_NM, methodName, ssdSet, GlobalErrIds.SSD_NULL);
    assertContext(CLS_NM, methodName, role, GlobalErrIds.ROLE_NULL);
    setEntitySession(CLS_NM, methodName, ssdSet);
    SDSet entity = sdP.read(ssdSet);
    entity.setContextId(this.contextId);
    entity.addMember(role.getName());
    setAdminData(CLS_NM, methodName, entity);
    SDSet ssdOut = sdP.update(entity);
    // remove any references to the old SSD from cache:
    clearSSDCache(role);
    return ssdOut;
}
Also used : SDSet(org.apache.directory.fortress.core.model.SDSet) AdminPermissionOperation(org.apache.directory.fortress.annotation.AdminPermissionOperation)

Aggregations

SDSet (org.apache.directory.fortress.core.model.SDSet)58 SecurityException (org.apache.directory.fortress.core.SecurityException)37 FortRequest (org.apache.directory.fortress.core.model.FortRequest)20 FortResponse (org.apache.directory.fortress.core.model.FortResponse)20 AdminMgr (org.apache.directory.fortress.core.AdminMgr)12 UserRole (org.apache.directory.fortress.core.model.UserRole)12 AdminPermissionOperation (org.apache.directory.fortress.annotation.AdminPermissionOperation)8 ReviewMgr (org.apache.directory.fortress.core.ReviewMgr)8 Role (org.apache.directory.fortress.core.model.Role)7 User (org.apache.directory.fortress.core.model.User)5 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)4 FinderException (org.apache.directory.fortress.core.FinderException)4 RoleConstraint (org.apache.directory.fortress.core.model.RoleConstraint)4 LdapConnection (org.apache.directory.ldap.client.api.LdapConnection)4 CursorException (org.apache.directory.api.ldap.model.cursor.CursorException)3 SearchCursor (org.apache.directory.api.ldap.model.cursor.SearchCursor)3 Constraint (org.apache.directory.fortress.core.model.Constraint)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 AccessMgr (org.apache.directory.fortress.core.AccessMgr)2