public AuthorizationService(IAuthorizationInitializer[] authorizationInitializers) { _rootLocation = new AuthorizationLocation(); AuthorizationRule allowRule = new AuthorizationRule { Action = AuthorizationRuleAction.Allow }; allowRule.Users.Add("*"); _rootLocation.Rules.Add(allowRule); foreach (IAuthorizationInitializer initializer in authorizationInitializers) initializer.Initialize(this); }
public void AddRule(string locationPath, IList<string> allowUsers, IList<string> allowRoles, IList<string> denyUsers, IList<string> denyRoles) { AuthorizationLocation location = new AuthorizationLocation { Path = locationPath }; AuthorizationRule allowRule = new AuthorizationRule { Action = AuthorizationRuleAction.Allow }; if (allowUsers != null) allowRule.Users.AddRange(allowUsers); if (allowRoles != null) allowRule.Roles.AddRange(allowRoles); location.Rules.Add(allowRule); AuthorizationRule denyRule = new AuthorizationRule { Action = AuthorizationRuleAction.Deny }; if (denyUsers != null) denyRule.Users.AddRange(denyUsers); if (denyRoles != null) denyRule.Roles.AddRange(denyRoles); location.Rules.Add(denyRule); _rootLocation.ChildLocations.Add(location); }