I'm sorry for the poor explanation I gave.
Maybe some code will enlighten the issue:
public bool GetMulti(ITransaction containingTransaction, IEntityCollection collectionToFill, long maxNumberOfItemsToReturn, ISortExpression sortClauses, IEntityFactory entityFactoryToUse, IPredicateExpression filter, IEntity countryInstance, IEntity logoPictureInstance, IEntity mapPictureInstance, int pageNumber, int pageSize)
{
base.EntityFactoryToUse = entityFactoryToUse;
IEntityFields fieldsToReturn = EntityFieldsFactory.CreateEntityFieldsObject(CMS.DAL.EntityType.CustomerEntity);
IPredicateExpression selectFilter = CreateFilterUsingForeignKeys(countryInstance, logoPictureInstance, mapPictureInstance, fieldsToReturn);
if(filter!=null)
{
selectFilter.AddWithAnd(filter);
}
bool res = base.PerformGetMultiAction(containingTransaction, collectionToFill, maxNumberOfItemsToReturn, sortClauses, selectFilter, null, pageNumber, pageSize);
System.Collections.Generic.List<string> customers = CMS.DAL.Roles.GetCompaniesForUser();
IEntity[] backup = new IEntity[collectionToFill.Count];
collectionToFill.CopyTo(backup, 0);
foreach(IEntity item in backup)
if(item is CustomerEntity)
{
//check if customer is found in permitted collection. If not remove from result set
if(!customers.Contains(((CustomerEntity) item).Customer))
collectionToFill.Remove(item);
}
return res;
}
This doesn't work, but illustrates what I'm trying to do. Whenever the customercollection is fetched I want to eliminate the entities the user does NOT have access to.
Did this help any?
I case you wonder what that external method is:
public static List<string> GetCompaniesForUser(DirectoryEntry user)
{
//get group references
//we use the collection in order to
//batch the request for translation
IdentityReferenceCollection irc = ExpandTokenGroups(user).Translate(typeof(NTAccount));
List<string> items = new List<string>();
foreach (NTAccount account in irc)
{
if (account.Value.Contains(CMS.DAL.Roles.CompanyPrefix))
{
items.Add(account.Value.Substring(account.Value.LastIndexOf("\\") + 1).Replace(CompanyPrefix, ""));
}
}
return items;
}
public static List<string> GetCompaniesForUser()
{
//Get logged on user's AD entry
DirectoryEntry user = GetCurrentUserDirectoryEntry();
return GetCompaniesForUser(user);
}
private static string SidToHex(SecurityIdentifier sid)
{
int binLength = sid.BinaryLength;
byte[] bt = new byte[binLength];
sid.GetBinaryForm(bt, 0);
System.Text.StringBuilder retval = new System.Text.StringBuilder(binLength * 2, binLength * 2);
for (int cx = 0; cx < binLength; cx++)
retval.Append(bt[cx].ToString("X2"));
return retval.ToString();
}
//Sample Helper Function
private static IdentityReferenceCollection ExpandTokenGroups(
DirectoryEntry user)
{
user.RefreshCache(new string[] { "tokenGroups" });
IdentityReferenceCollection irc =
new IdentityReferenceCollection();
foreach (byte[] sidBytes in user.Properties["tokenGroups"])
{
irc.Add(new SecurityIdentifier(sidBytes, 0));
}
return irc;
}
thanks,
kjelli