public static void Start(SchemaBuilder sb) { if (sb.NotDefined(MethodInfo.GetCurrentMethod())) { AuthLogic.AssertStarted(sb); OperationLogic.AssertStarted(sb); OperationLogic.AllowOperation += OperationLogic_AllowOperation; cache = new AuthCache <RuleOperationEntity, OperationAllowedRule, OperationSymbol, OperationSymbol, OperationAllowed>(sb, s => s, s => s, merger: new OperationMerger(), invalidateWithTypes: true, coercer: OperationCoercer.Instance); AuthLogic.ExportToXml += exportAll => cache.ExportXml("Operations", "Operation", s => s.Key, b => b.ToString(), exportAll ? OperationLogic.RegisteredOperations.ToList() : null); AuthLogic.ImportFromXml += (x, roles, replacements) => { string replacementKey = "AuthRules:" + typeof(OperationSymbol).Name; replacements.AskForReplacements( x.Element("Operations").Elements("Role").SelectMany(r => r.Elements("Operation")).Select(p => p.Attribute("Resource").Value).ToHashSet(), SymbolLogic <OperationSymbol> .AllUniqueKeys(), replacementKey); return(cache.ImportXml(x, "Operations", "Operation", roles, s => SymbolLogic <OperationSymbol> .TryToSymbol(replacements.Apply(replacementKey, s)), EnumExtensions.ToEnum <OperationAllowed>)); }; } }
private static MList <RuleTypeConditionEmbedded> Conditions(XElement xr, Replacements replacements) { return((from xc in xr.Elements("Condition") let cn = SymbolLogic <TypeConditionSymbol> .TryToSymbol(replacements.Apply(typeConditionReplacementKey, xc.Attribute("Name").Value)) where cn != null select new RuleTypeConditionEmbedded { Condition = cn, Allowed = xc.Attribute("Allowed").Value.ToEnum <TypeAllowed>() }).ToMList()); }
public static void Start(SchemaBuilder sb) { if (sb.NotDefined(MethodInfo.GetCurrentMethod())) { AuthLogic.AssertStarted(sb); sb.Include <PermissionSymbol>(); SymbolLogic <PermissionSymbol> .Start(sb, () => RegisteredPermission.ToHashSet()); sb.Include <RulePermissionEntity>() .WithUniqueIndex(rt => new { rt.Resource, rt.Role }); cache = new AuthCache <RulePermissionEntity, PermissionAllowedRule, PermissionSymbol, PermissionSymbol, bool>(sb, toKey: p => p, toEntity: p => p, isEquals: (p1, p2) => p1 == p2, merger: new PermissionMerger(), invalidateWithTypes: false); sb.Schema.EntityEvents <RoleEntity>().PreUnsafeDelete += query => { Database.Query <RulePermissionEntity>().Where(r => query.Contains(r.Role.Entity)).UnsafeDelete(); return(null); }; RegisterPermissions(BasicPermission.AdminRules, BasicPermission.AutomaticUpgradeOfProperties, BasicPermission.AutomaticUpgradeOfOperations, BasicPermission.AutomaticUpgradeOfQueries); AuthLogic.ExportToXml += exportAll => cache.ExportXml("Permissions", "Permission", a => a.Key, b => b.ToString(), exportAll ? PermissionAuthLogic.RegisteredPermission.ToList() : null); AuthLogic.ImportFromXml += (x, roles, replacements) => { string replacementKey = "AuthRules:" + typeof(PermissionSymbol).Name; replacements.AskForReplacements( x.Element("Permissions").Elements("Role").SelectMany(r => r.Elements("Permission")).Select(p => p.Attribute("Resource").Value).ToHashSet(), SymbolLogic <PermissionSymbol> .Symbols.Select(s => s.Key).ToHashSet(), replacementKey); return(cache.ImportXml(x, "Permissions", "Permission", roles, s => SymbolLogic <PermissionSymbol> .TryToSymbol(replacements.Apply(replacementKey, s)), bool.Parse)); }; sb.Schema.Table <PermissionSymbol>().PreDeleteSqlSync += new Func <Entity, SqlPreCommand>(AuthCache_PreDeleteSqlSync); } }
public static void Start(SchemaBuilder sb, DynamicQueryManager dqm) { if (sb.NotDefined(MethodInfo.GetCurrentMethod())) { AuthLogic.AssertStarted(sb); sb.Include <PermissionSymbol>(); SymbolLogic <PermissionSymbol> .Start(sb, dqm, () => RegisteredPermission.ToHashSet()); cache = new AuthCache <RulePermissionEntity, PermissionAllowedRule, PermissionSymbol, PermissionSymbol, bool>(sb, s => s, s => s, merger: new PermissionMerger(), invalidateWithTypes: false); RegisterPermissions(BasicPermission.AdminRules, BasicPermission.AutomaticUpgradeOfProperties, BasicPermission.AutomaticUpgradeOfOperations, BasicPermission.AutomaticUpgradeOfQueries); AuthLogic.ExportToXml += exportAll => cache.ExportXml("Permissions", "Permission", a => a.Key, b => b.ToString(), exportAll ? PermissionAuthLogic.RegisteredPermission.ToList() : null); AuthLogic.ImportFromXml += (x, roles, replacements) => { string replacementKey = "AuthRules:" + typeof(PermissionSymbol).Name; replacements.AskForReplacements( x.Element("Permissions").Elements("Role").SelectMany(r => r.Elements("Permission")).Select(p => p.Attribute("Resource").Value).ToHashSet(), SymbolLogic <PermissionSymbol> .Symbols.Select(s => s.Key).ToHashSet(), replacementKey); return(cache.ImportXml(x, "Permissions", "Permission", roles, s => SymbolLogic <PermissionSymbol> .TryToSymbol(replacements.Apply(replacementKey, s)), bool.Parse)); }; } }
public PermissionSymbol?TryPermission(string permissionKey) { return(SymbolLogic <PermissionSymbol> .TryToSymbol(permissionKey)); }
public static WikiLink LinkParser(string content) { Match m = HelpLogic.HelpLinkRegex.Match(content); if (m.Success) { string letter = m.Groups["letter"].ToString(); string link = m.Groups["link"].ToString(); string text = m.Groups["text"].ToString(); switch (letter) { case WikiFormat.EntityLink: Type t = TypeLogic.TryGetType(link); return(new WikiLink( HelpUrls.EntityUrl(t), text.HasText() ? text : t.NiceName())); case WikiFormat.Hyperlink: return(new WikiLink(link, text)); case WikiFormat.OperationLink: OperationSymbol operation = SymbolLogic <OperationSymbol> .TryToSymbol(link); List <Type> types = OperationLogic.FindTypes(operation).Where(TypeLogic.TypeToEntity.ContainsKey).ToList(); if (types.Count == 1) { return(new WikiLink( HelpUrls.OperationUrl(types[0], operation), text.HasText() ? text : operation.NiceToString())); } else { return(new MultiWikiLink(operation.NiceToString()) { Links = types.Select(currentType => new WikiLink( HelpUrls.OperationUrl(currentType, operation), currentType.NiceName(), operation.NiceToString())).ToList() }); } case WikiFormat.PropertyLink: PropertyRoute route = PropertyRoute.Parse(TypeLogic.TryGetType(link.Before('.')), link.After('.')); while (route.PropertyRouteType == PropertyRouteType.LiteEntity || route.PropertyRouteType == PropertyRouteType.Mixin || route.PropertyRouteType == PropertyRouteType.MListItems) { route = route.Parent; } return(new WikiLink(HelpUrls.PropertyUrl(route), route.PropertyInfo.NiceName())); case WikiFormat.QueryLink: object o = QueryLogic.TryToQueryName(link); if (o as Enum != null) { Enum query = (Enum)o; return(new WikiLink( HelpUrls.QueryUrl(query), text.HasText() ? text : QueryUtils.GetNiceName(query))); } else { Type query = (Type)o; return(new WikiLink( HelpUrls.QueryUrl(query), text.HasText() ? text : QueryUtils.GetNiceName(query))); } case WikiFormat.NamespaceLink: NamespaceHelp nameSpace = HelpLogic.GetNamespaceHelp(link); return(new WikiLink( HelpUrls.NamespaceUrl(link), text.HasText() ? text : link, nameSpace != null ? "" : "unavailable")); case WikiFormat.AppendixLink: AppendixHelp appendix = HelpLogic.GetAppendixHelp(link); return(new WikiLink( HelpUrls.AppendixUrl(link), text.HasText() ? text : link, appendix != null ? "" : "unavailable")); } } return(null); }