Search in sources :

Example 6 with PermissionAttribute

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

the class AdminMgrRestImpl method addPermissionAttributeToSet.

/**
 * {@inheritDoc}
 */
@Override
public PermissionAttribute addPermissionAttributeToSet(PermissionAttribute permAttribute, String attributeSetName) throws SecurityException {
    VUtil.assertNotNull(permAttribute, GlobalErrIds.PERM_ATTRIBUTE_SET_NULL, CLS_NM + ".addPermissionAttributeToSet");
    VUtil.assertNotNull(attributeSetName, GlobalErrIds.PERM_ATTRIBUTE_SET_NM_NULL, CLS_NM + ".addPermissionAttributeToSet");
    PermissionAttribute retAttr;
    FortRequest request = RestUtils.getRequest(this.contextId);
    request.setEntity(permAttribute);
    request.setValue(attributeSetName);
    if (this.adminSess != null) {
        request.setSession(adminSess);
    }
    String szRequest = RestUtils.marshal(request);
    String szResponse = RestUtils.getInstance().post(szRequest, HttpIds.PERM_ADD_PERM_ATTRIBUTE_TO_SET);
    FortResponse response = RestUtils.unmarshall(szResponse);
    if (response.getErrorCode() == 0) {
        retAttr = (PermissionAttribute) response.getEntity();
    } else {
        throw new SecurityException(response.getErrorCode(), response.getErrorMessage());
    }
    return retAttr;
}
Also used : FortResponse(org.apache.directory.fortress.core.model.FortResponse) PermissionAttribute(org.apache.directory.fortress.core.model.PermissionAttribute) SecurityException(org.apache.directory.fortress.core.SecurityException) FortRequest(org.apache.directory.fortress.core.model.FortRequest)

Example 7 with PermissionAttribute

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

the class PermDAO method findPermissionAttributes.

Set<PermissionAttribute> findPermissionAttributes(PermissionAttributeSet paSet) throws FinderException {
    Set<PermissionAttribute> paList = new HashSet<PermissionAttribute>();
    LdapConnection ld = null;
    String permRoot = getRootDn(paSet.getContextId());
    try {
        String paSetVal = encodeSafeText(paSet.getName(), GlobalIds.PERM_LEN);
        StringBuilder filterbuf = new StringBuilder();
        filterbuf.append(GlobalIds.FILTER_PREFIX);
        filterbuf.append(PERMISSION_ATTRIBUTE_OBJECT_CLASS_NAME);
        filterbuf.append(")(");
        filterbuf.append(GlobalIds.FT_PERMISSION_ATTRIBUTE_SET);
        filterbuf.append("=");
        filterbuf.append(paSetVal);
        filterbuf.append("))");
        ld = getAdminConnection();
        SearchCursor searchResults = search(ld, permRoot, SearchScope.SUBTREE, filterbuf.toString(), PERMISION_ATTRIBUTE_ATRS, false, GlobalIds.BATCH_SIZE);
        long sequence = 0;
        while (searchResults.next()) {
            paList.add(unloadPALdapEntry(searchResults.getEntry(), sequence++));
        }
    } catch (LdapException e) {
        String error = "findPermissionAttributes caught LdapException=" + e.getMessage();
        throw new FinderException(GlobalErrIds.PERM_SEARCH_FAILED, error, e);
    } catch (CursorException e) {
        String error = "findPermissionAttributes caught CursorException=" + e.getMessage();
        throw new FinderException(GlobalErrIds.PERM_SEARCH_FAILED, error, e);
    } finally {
        closeAdminConnection(ld);
    }
    return paList;
}
Also used : 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) PermissionAttribute(org.apache.directory.fortress.core.model.PermissionAttribute) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) HashSet(java.util.HashSet) LdapConnection(org.apache.directory.ldap.client.api.LdapConnection)

Example 8 with PermissionAttribute

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

the class PermDAO method createPermissionAttributeSet.

/**
 * @param entity
 * @return
 * @throws CreateException
 */
PermissionAttributeSet createPermissionAttributeSet(PermissionAttributeSet entity) throws CreateException {
    LdapConnection ld = null;
    String dn = getDn(entity, entity.getContextId());
    try {
        Entry entry = new DefaultEntry(dn);
        entry.add(SchemaConstants.OBJECT_CLASS_AT, PERM_ATTR_SET_OBJ_CLASS);
        entry.add(GlobalIds.FT_PERMISSION_ATTRIBUTE_SET, entity.getName());
        // this will generate a new random, unique id on this entity:
        entity.setInternalId();
        // create the internal id:
        entry.add(GlobalIds.FT_IID, entity.getInternalId());
        // description is optional:
        if (StringUtils.isNotEmpty(entity.getDescription())) {
            entry.add(SchemaConstants.DESCRIPTION_AT, entity.getDescription());
        }
        if (StringUtils.isNotEmpty(entity.getType())) {
            entry.add(GlobalIds.FT_PERMISSION_ATTRIBUTE_SET_TYPE, entity.getType());
        }
        // organizational name requires CN attribute:
        entry.add(SchemaConstants.CN_AT, entity.getName());
        // now add the new entry to directory:
        ld = getAdminConnection();
        add(ld, entry, entity);
        entity.setDn(dn);
    } catch (LdapException e) {
        String error = "createPermissionAttributeSet name [" + entity.getName() + "] caught LdapException=" + e.getMessage();
        throw new CreateException(GlobalErrIds.PERM_ADD_FAILED, error, e);
    } finally {
        closeAdminConnection(ld);
    }
    // add each ftPA
    for (PermissionAttribute pa : entity.getAttributes()) {
        pa.setContextId(entity.getContextId());
        this.createPermissionAttribute(pa, entity.getName());
    }
    return entity;
}
Also used : DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) Entry(org.apache.directory.api.ldap.model.entry.Entry) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) PermissionAttribute(org.apache.directory.fortress.core.model.PermissionAttribute) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) CreateException(org.apache.directory.fortress.core.CreateException) LdapConnection(org.apache.directory.ldap.client.api.LdapConnection)

Aggregations

PermissionAttribute (org.apache.directory.fortress.core.model.PermissionAttribute)8 SecurityException (org.apache.directory.fortress.core.SecurityException)3 HashSet (java.util.HashSet)2 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)2 FortRequest (org.apache.directory.fortress.core.model.FortRequest)2 FortResponse (org.apache.directory.fortress.core.model.FortResponse)2 LdapConnection (org.apache.directory.ldap.client.api.LdapConnection)2 CursorException (org.apache.directory.api.ldap.model.cursor.CursorException)1 SearchCursor (org.apache.directory.api.ldap.model.cursor.SearchCursor)1 DefaultEntry (org.apache.directory.api.ldap.model.entry.DefaultEntry)1 Entry (org.apache.directory.api.ldap.model.entry.Entry)1 CreateException (org.apache.directory.fortress.core.CreateException)1 FinderException (org.apache.directory.fortress.core.FinderException)1 ReviewMgr (org.apache.directory.fortress.core.ReviewMgr)1 ObjectFactory (org.apache.directory.fortress.core.model.ObjectFactory)1 PermissionAttributeSet (org.apache.directory.fortress.core.model.PermissionAttributeSet)1