private synchronized boolean attach(String dn, Object res) throws OperationFailedException
{
if (isRoot) {
throw new OperationFailedException("Attach operation isn't allowed for synthetic root tribe!");
}
PooledConnection connImpl = null;
DirContext ctx = null;
try {
connImpl = realm.getConnection();
ctx = (DirContext)connImpl.getConnection();
//check that this tribe isn't a member of the tribe being attached
if (res instanceof LDAPTribe) {
LDAPTribe parentCand = (LDAPTribe)res;
String parentFail = parentCand.containsName(ctx, parentCand.fetchMembers(ctx), this.dn);
if (parentFail != null) {
throw new OperationFailedException("Loops not allowed, '"+dn+"' is parent of of '"+this.dn+"'");
}
}
Attribute currMembers = fetchMembers(ctx);
String failer = containsName(ctx, currMembers, dn);
if (failer == null) {
currMembers.add(dn);
Attributes attrs = new BasicAttributes();
attrs.put(currMembers);
ctx.modifyAttributes(this.dn, DirContext.REPLACE_ATTRIBUTE, attrs);
return true;
}
} catch (Exception e) {
throw new OperationFailedException(e);
} finally {
LDAPRealm.cleanupContext(connImpl);
}
return false;