コード例 #1
0
        /// <summary>
        /// OnInitializeCollection fires on the initialization of any NHibernate collection proxy.
        /// If security is enabled and the collection contains secured entities, the collection
        /// will be modified such that it will only contain entities that the current security user
        /// is allowed to see.
        /// </summary>
        /// <param name="event"></param>
        public void OnInitializeCollection(InitializeCollectionEvent @event)
        {
            // Skip processing if there is nothing to do
            if (null == @event.Collection || @event.Collection.Empty || [email protected]())
            {
                return;
            }

            // As data access library implementer, I know that secured child entities are all contained in
            // generic lists (i.e. not Set or Map)
            var collectionType = @event.Collection.GetType();
            if (collectionType.IsGenericType)
            {
                var gtype = collectionType.GetGenericArguments().First(); // This breaks on Dictionary
                if (gtype.IsSecurable())
                {

                    var entityName = @event.Session.GetFilterParameterValue("EntityNameFilter.EntityName") as string;
                    // After checking NHibernate source, the persistent list and bag collections all implement the
                    // non-generic ILIst definition.
                    var values = (System.Collections.IList)@event.Collection.GetValue();
                    var securables = values.Cast<ISecurable>(); // This should be safe due to implementation check above
                    //
                    var keepers = securables.ToList().FindAll(x => x.IsLoadableFor(entityName));
                    values.Clear();
                    keepers.ForEach(x => values.Add(x));
                }

            }
        }
コード例 #2
0
			public override void OnInitializeCollection(InitializeCollectionEvent @event)
			{
				base.OnInitializeCollection(@event);
				AddEvent(@event, this);
			}
コード例 #3
0
 public void OnInitializeCollection(InitializeCollectionEvent @event)
 {
     log.Debug("OnInitializeCollection :" + @event);
 }