private IConditionResult OnlySelfGetConditions(ISecurityItem securityItem) { DateTime now = DateTime.Now; ISecurityItemAuthorizationsResolver securityItemAuthorizationsResolver = _securityItemAuthorizationsResolverFactory.CreateResolver(securityItem); Dictionary < IConditionalAuthorization, IEnumerable < IAccessCondition >> result = new Dictionary<IConditionalAuthorization, IEnumerable<IAccessCondition>>(); foreach (IConditionalAuthorization conditionalAuthorization in securityItemAuthorizationsResolver.GetAuthorizations() .Where(a => a.SecurityIdentity.Equals(_securityIdentity)).OfType<IConditionalAuthorization>()) { if (conditionalAuthorization.LifeTime != null && !conditionalAuthorization.LifeTime.IsActive(now)) continue; result.Add(conditionalAuthorization,conditionalAuthorization.Conditions); } return new ConditionResult(result); }
private ICheckAccessResult OnlyCheckAccessSelf(ISecurityItem securityItem) { DateTime now = DateTime.Now; ISecurityItemAuthorizationsResolver securityItemAuthorizationsResolver = _securityItemAuthorizationsResolverFactory.CreateResolver(securityItem); List<IAccessAuthorization> affectedAuthorizations = new List<IAccessAuthorization>(); bool deniedFound = false; bool allowedFound = false; foreach (IAccessAuthorization accessAuthorization in securityItemAuthorizationsResolver.GetAuthorizations() .Where(a => a.SecurityIdentity.Equals(_securityIdentity)).OfType<IAccessAuthorization>()) { if(accessAuthorization.LifeTime != null && !accessAuthorization.LifeTime.IsActive(now)) continue; switch (accessAuthorization.AccessType) { case AccessType.Allow: if(!deniedFound) affectedAuthorizations.Add(accessAuthorization); allowedFound = true; break; case AccessType.Deny: if(allowedFound && !deniedFound) affectedAuthorizations.Clear(); affectedAuthorizations.Add(accessAuthorization); deniedFound = true; break; case AccessType.Neutral: break; default: throw new ArgumentOutOfRangeException(); } } if(deniedFound) return new CheckAccessResult(AccessType.Deny,affectedAuthorizations); if(allowedFound) return new CheckAccessResult(AccessType.Allow, affectedAuthorizations); return new CheckAccessResult(AccessType.Neutral,Enumerable.Empty<IAccessAuthorization>()); }