async private Task <object> MapService2Json(IMapService mapService, IMapServiceSettings settings) { var status = settings?.Status ?? MapServiceStatus.Running; if (status == MapServiceStatus.Running) { if (!_mapServiceMananger.Instance.IsLoaded(mapService.Name, mapService.Folder)) { status = MapServiceStatus.Idle; } } bool hasErrors = await _logger.LogFileExists(mapService.Fullname, loggingMethod.error); return(new { name = mapService.Name, folder = mapService.Folder, status = status.ToString().ToLower(), hasSecurity = settings?.AccessRules != null && settings.AccessRules.Length > 0, runningSince = settings?.Status == MapServiceStatus.Running && mapService.RunningSinceUtc.HasValue ? mapService.RunningSinceUtc.Value.ToShortDateString() + " " + mapService.RunningSinceUtc.Value.ToLongTimeString() + " (UTC)" : String.Empty, hasErrors = hasErrors }); }
static public bool IsRunningOrIdle(this IMapServiceSettings settings) { if (settings == null) { return(false); } return(settings.Status == MapServiceStatus.Running || settings.Status == MapServiceStatus.Idle); }
private void CheckAccess(IServiceRequestContext context, IMapServiceSettings settings) { if (settings?.AccessRules == null || settings.AccessRules.Length == 0) // No Settings -> free service { return; } string userName = context.ServiceRequest?.Identity?.UserName; var accessRule = settings .AccessRules .Where(r => r.Username.Equals(userName, StringComparison.InvariantCultureIgnoreCase)) .FirstOrDefault(); // if user not found, use rules for anonymous if (accessRule == null) { accessRule = settings .AccessRules .Where(r => r.Username.Equals(Identity.AnonyomousUsername, StringComparison.InvariantCultureIgnoreCase)) .FirstOrDefault(); } if (accessRule == null || accessRule.ServiceTypes == null) { throw new TokenRequiredException("forbidden (user:"******")"); } if (!accessRule.ServiceTypes.Contains("_all") && !accessRule.ServiceTypes.Contains("_" + context.ServiceRequestInterpreter.IdentityName.ToLower())) { throw new NotAuthorizedException(context.ServiceRequestInterpreter.IdentityName + " interface forbidden (user: "******")"); } var accessTypes = context.ServiceRequestInterpreter.RequiredAccessTypes(context); foreach (AccessTypes accessType in Enum.GetValues(typeof(AccessTypes))) { if (accessType != AccessTypes.None && accessTypes.HasFlag(accessType)) { if (!accessRule.ServiceTypes.Contains(accessType.ToString().ToLower())) { throw new NotAuthorizedException("Forbidden: " + accessType.ToString() + " access required (user: "******")"); } } } }
private void CheckAccess(IIdentity identity, IServiceRequestInterpreter interpreter, IMapServiceSettings settings) { if (settings?.AccessRules == null || settings.AccessRules.Length == 0) // No Settings -> free service { return; } string userName = identity.UserName; var accessRule = settings .AccessRules .Where(r => r.Username.Equals(userName, StringComparison.InvariantCultureIgnoreCase)) .FirstOrDefault(); // if user not found, use rules for anonymous if (accessRule == null) { accessRule = settings .AccessRules .Where(r => r.Username.Equals(Identity.AnonyomousUsername, StringComparison.InvariantCultureIgnoreCase)) .FirstOrDefault(); } if (accessRule == null || accessRule.ServiceTypes == null) { throw new TokenRequiredException("forbidden (user:"******")"); } if (!accessRule.ServiceTypes.Contains("_all") && !accessRule.ServiceTypes.Contains("_" + interpreter.IdentityName.ToLower())) { throw new NotAuthorizedException(interpreter.IdentityName + " interface forbidden (user: "******")"); } }