/// <summary> /// See interface docs. /// </summary> /// <param name="pathFromRoot"></param> /// <param name="access"></param> public void SetRestrictedPath(string pathFromRoot, Access access) { pathFromRoot = (pathFromRoot ?? "").Trim().ToLower(); if (!pathFromRoot.StartsWith("/")) { pathFromRoot = String.Format("/{0}", pathFromRoot); } if (!pathFromRoot.EndsWith("/")) { pathFromRoot = String.Format("{0}/", pathFromRoot); } var removeEntry = access == null || access.DefaultAccess == DefaultAccess.Unrestricted; using (_RestrictedPathSpinLock.AcquireLock()) { var restrictedPath = _RestrictedPaths.FirstOrDefault(r => r.NormalisedPath == pathFromRoot); if (removeEntry) { if (restrictedPath != null) { _RestrictedPaths.Remove(restrictedPath); } } else { if (restrictedPath != null) { restrictedPath.Filter.Initialise(access); } else { var filter = Factory.Singleton.Resolve <IAccessFilter>(); filter.Initialise(access); restrictedPath = new RestrictedPath() { NormalisedPath = pathFromRoot, Filter = filter, }; _RestrictedPaths.Add(restrictedPath); } } } }
/// <summary> /// See interface docs. /// </summary> /// <param name="pathAndFile"></param> /// <param name="ipAddress"></param> /// <returns></returns> public bool IsPathAccessible(string pathAndFile, IPAddress ipAddress) { var result = true; var normalisedPathAndFile = RestrictedPath.NormalisePath(pathAndFile); var restrictedPaths = _RestrictedPaths; for (var i = 0; i < restrictedPaths.Count; ++i) { var restrictedPath = restrictedPaths[i]; if (normalisedPathAndFile.StartsWith(restrictedPath.NormalisedPath)) { result = restrictedPath.AccessFilter.Allow(ipAddress); break; } } return(result); }
/// <summary> /// See interface docs. /// </summary> /// <param name="pathFromRoot"></param> /// <param name="access"></param> public void SetRestrictedPath(string pathFromRoot, Access access) { pathFromRoot = UriHelper.NormalisePathFromRoot(pathFromRoot); lock (_SyncLock) { var restrictedPaths = CollectionHelper.ShallowCopy(_RestrictedPaths); var restrictedPathsMap = CollectionHelper.ShallowCopy(_RestrictedPathsMap); RestrictedPath restrictedPath; var hasEntry = restrictedPathsMap.TryGetValue(pathFromRoot, out restrictedPath); var removeEntry = access == null || access.DefaultAccess == DefaultAccess.Unrestricted; if (removeEntry && hasEntry) { restrictedPaths.Remove(restrictedPath); restrictedPathsMap.Remove(pathFromRoot); } else if (!removeEntry) { var newRestrictedPath = new RestrictedPath(pathFromRoot, access); if (!hasEntry) { restrictedPaths.Add(newRestrictedPath); restrictedPathsMap.Add(pathFromRoot, newRestrictedPath); } else { restrictedPaths.Remove(restrictedPath); restrictedPaths.Add(newRestrictedPath); restrictedPathsMap[pathFromRoot] = newRestrictedPath; } } _RestrictedPaths = restrictedPaths; _RestrictedPathsMap = restrictedPathsMap; } }