private void Context_SavingChanges(object sender, EventArgs e) { if (_kernel.EnableGuards == false) { return; } ObjectContext objectContext = ((IObjectContextAdapter)_context).ObjectContext; var entries = objectContext.GetModifiedEntries(); foreach (var entry in entries) { if (entry == null) { continue; } var protectionContext = new SubmitProtectionContext() { Kernel = _kernel, EntityType = entry.Entity.GetType(), Entry = entry, LocalValues = objectContext.GetModifiedLocalValues(entry.Entity), OriginalValues = objectContext.GetModifiedOriginalValues(entry.Entity) }; _kernel.SubmitGuard.Protect(protectionContext); } }
/// <summary> /// Calls all registered submit policies in GuardianKernel /// </summary> /// <param name="context">The protection context.</param> /// <exception cref="AccessDeniedException"></exception> public void Protect(SubmitProtectionContext context) { foreach (var policy in context.Kernel.SubmitPolicies) { var result = policy.Check(context); if (result.IsSuccess == false) { // If one of policies fail, we don't need to apply another ones throw new AccessDeniedException(); } } }