private List <ThemeMap> GetAllowedMapConfigurations() { string folder = String.Format("{0}App_Data", HostingEnvironment.ApplicationPhysicalPath); IEnumerable <string> files = Directory.EnumerateFiles(folder, "*.json"); List <ThemeMap> mapConfigurationsList = new List <ThemeMap>(); var activeUser = ""; var userGroups = new string[0]; if (ActiveDirectoryLookup.UseAdLookup()) // Should we use AD-lookup? { var adLookup = new ActiveDirectoryLookup(); activeUser = adLookup.GetActiveUser(); userGroups = adLookup.GetGroups(); } foreach (string mapConfigurationFile in files) { string fileName = Path.GetFileNameWithoutExtension(mapConfigurationFile); if (fileName != "layers") { var json = System.IO.File.ReadAllText(mapConfigurationFile); JToken mapConfiguration = JsonConvert.DeserializeObject <JToken>(json); if (HasActiveDropDownThemeMap(mapConfiguration, mapConfigurationFile)) { var visibleForGroups = GetOptionsObjectFromTool(mapConfiguration, "visibleForGroups", "layerswitcher"); var mapTitle = GetMapConfigurationTitle(mapConfiguration, mapConfigurationFile); if (!ActiveDirectoryLookup.UseAdLookup()) // Tillåt att man använder dropdownbox utan inloggning och validering mot AD { if (mapTitle == null) { _log.Warn("MapConfigurationFile " + mapConfigurationFile + ", map object is missing 'title'"); } mapConfigurationsList.Add(AddNewThemeMap(fileName, mapTitle == null ? fileName + ": Add title to this map" : mapTitle.ToString())); } else { if (visibleForGroups == null) { _log.Info("MapConfigurationFile " + mapConfigurationFile + ", Layerswitcher tool is missing 'visibleForGroups' (or it may be empty)"); } if (mapTitle == null) { _log.Info("MapConfigurationFile " + mapConfigurationFile + ", map object is missing 'title'"); } if (visibleForGroups != null && mapTitle != null) { if (visibleForGroups.First == null) { mapConfigurationsList.Add(AddNewThemeMap(fileName, mapTitle.ToString())); } if (activeUser.Length != 0 && visibleForGroups.First != null) { if (visibleForGroups.First.ToString() == "*") { mapConfigurationsList.Add(AddNewThemeMap(fileName, mapTitle.ToString())); } else { foreach (JToken group in visibleForGroups) { if (Array.Exists(userGroups, g => g.Equals(group.ToString()))) { // Kontrollera att denna kartdefinition inte redan lagts till if (!mapConfigurationsList.Exists(x => x.mapConfigurationName == fileName)) { mapConfigurationsList.Add(AddNewThemeMap(fileName, mapTitle.ToString())); } } } } } } } } } } return(mapConfigurationsList); }
public string GetConfig(string name) { try { _log.DebugFormat("Executing GetConfig, name='{0}'", name); Response.Expires = 0; Response.ExpiresAbsolute = DateTime.Now.AddDays(-1); Response.ContentType = "application/json; charset=utf-8"; Response.Headers.Add("Cache-Control", "private, no-cache"); if (name == null) { throw new HttpException(500, "File name is not present"); } if (name.ToLower() == "list") { return(List("all")); } if (name.ToLower() == "userspecificmaps") { return(UserSpecificMaps()); } if (name.ToLower() == "getusergroups") { return(GetUserGroups()); } if (name.ToLower() == "listimage") { return(ListImage()); } if (name.ToLower() == "listvideo") { return(ListVideo()); } if (name.ToLower() == "listaudio") { return(ListAudio()); } string file = String.Format("{0}App_Data\\{1}.json", HostingEnvironment.ApplicationPhysicalPath, name); if (System.IO.File.Exists(file)) { if (!ActiveDirectoryLookup.UseAdLookup()) // Only filter if AD is used { return(System.IO.File.ReadAllText(file)); } var adLookup = new ActiveDirectoryLookup(); var activeUser = adLookup.GetActiveUser(); var isRequestFromAdmin = true; if (Request.UrlReferrer != null && Request.UrlReferrer.ToString().IndexOf("/admin") == -1) { isRequestFromAdmin = false; } if (activeUser.Length != 0 && name != "layers" && !isRequestFromAdmin) { _log.DebugFormat("Filtering map configuration '{0}' for user '{1}'.", name, activeUser); JToken mapConfiguration = JsonConvert.DeserializeObject <JToken>(System.IO.File.ReadAllText(file)); var filteredMapConfiguration = FilterLayersByAD(adLookup, mapConfiguration); filteredMapConfiguration = FilterToolsByAD(adLookup, filteredMapConfiguration); var searchTool = filteredMapConfiguration.SelectToken("$.tools[?(@.type == 'search')]"); if (searchTool != null) { filteredMapConfiguration = FilterSearchLayersByAD(adLookup, filteredMapConfiguration); } var editTool = filteredMapConfiguration.SelectToken("$.tools[?(@.type == 'edit')]"); if (editTool != null) { filteredMapConfiguration = FilterEditLayersByAD(adLookup, filteredMapConfiguration); } var firTool = filteredMapConfiguration.SelectToken("$.tools[?(@.type == 'fir')]"); if (firTool != null) { filteredMapConfiguration = FilterFirToolByAD(adLookup, filteredMapConfiguration); } var kirTool = filteredMapConfiguration.SelectToken("$.tools[?(@.type == 'kir')]"); if (kirTool != null) { filteredMapConfiguration = FilterKirToolByAD(adLookup, filteredMapConfiguration); } return(filteredMapConfiguration.ToString()); } else { return(System.IO.File.ReadAllText(file)); } } else { throw new HttpException(404, "File not found"); } } catch (Exception e) { _log.FatalFormat("Can't get configuration file: {0}", e); throw e; } }