public AuthorizationService() { _store = ServiceLocator.GetInstance <IEntityStoreManager>().CreateStore("authorization"); _store.RegisterEntity <AuthorizationKeyStatusModel>(); _keys["/"] = new AuthorizationKeyImpl(this, null, "/", "Raiz", 0); SetStatus("user", "admin", "/", AuthorizationStatus.Grant); }
private AuthorizationKeyImpl GetKeyInternal(string basePath, bool throwException = false) { if (basePath == "") { basePath = "/"; } AuthorizationKeyImpl result = null; _keys.TryGetValue(NormalizePath(basePath), out result); if (result == null && throwException) { throw new InvalidOperationException("Authorization key not found: " + basePath); } return(result); }
public IAuthorizationKey CreateKey(string keyPath, string caption, int order = 0) { Assert.EmptyString(keyPath, "keyPath"); var path = keyPath.Split(new Char[] { '/' }, StringSplitOptions.RemoveEmptyEntries); var pathStr = "/"; AuthorizationKeyImpl parent = GetKeyInternal("/", true); for (var i = 0; i < path.Length; i++) { var part = path[i]; pathStr += part; var key = GetKeyInternal(pathStr); if (key == null) { key = i < path.Length - 1 ? new AuthorizationKeyImpl(this, parent, pathStr, part, 0) : new AuthorizationKeyImpl(this, parent, pathStr, caption, order); this._keys[key.AuthorizationKey] = key; } parent.AddItem(key); parent = key; } return(parent); }