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;
}
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;
}
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;
}
Aggregations