Exemplo n.º 1
0
 private static bool HasReadRights(QlikQrsHub qrsHub, ManagedTask task)
 {
     try
     {
         logger.Debug($"Search for read right of user {task.Session.User}");
         var parameter   = CreateAuditMatrixParameters(task.Session.User);
         var contentData = Encoding.UTF8.GetBytes(parameter.ToString());
         var data        = new ContentData()
         {
             ContentType = "application/json",
             FileData    = contentData,
         };
         var matrixResponse = qrsHub.SendRequestAsync("systemrule/security/audit/matrix", HttpMethod.Post, data).Result;
         var responseObject = JObject.Parse(matrixResponse);
         var matrix         = responseObject["matrix"]?.FirstOrDefault(m => m["resourceId"]?.ToString() == task.Session.AppId) ?? null;
         if (matrix != null)
         {
             var privileges = responseObject["resources"][matrix["resourceId"]?.ToObject <string>()]["privileges"].ToList() ?? new List <JToken>();
             var canAppRead = privileges?.FirstOrDefault(p => p?.ToObject <string>() == "read") ?? null;
             if (canAppRead != null)
             {
                 return(true);
             }
         }
         return(false);
     }
     catch (Exception ex)
     {
         logger.Error(ex, "The read rights of the user could not found.");
         return(false);
     }
 }
Exemplo n.º 2
0
        public DomainUser GetAppOwner(QlikQrsHub qrsHub, string appId)
        {
            DomainUser resultUser = null;

            try
            {
                var qrsResult = qrsHub.SendRequestAsync($"app/{appId}", HttpMethod.Get).Result;
                logger.Trace($"appResult:{qrsResult}");
                if (qrsResult == null)
                {
                    throw new Exception($"The result of the QRS request 'app/{appId}' of is null.");
                }
                dynamic jObject       = JObject.Parse(qrsResult);
                string  userDirectory = jObject?.owner?.userDirectory ?? null;
                string  userId        = jObject?.owner?.userId ?? null;
                if (!String.IsNullOrEmpty(userDirectory) && !String.IsNullOrEmpty(userId))
                {
                    resultUser = new DomainUser($"{userDirectory}\\{userId}");
                    logger.Debug($"Found app owner: {resultUser}");
                }
                else
                {
                    logger.Error($"No user directory {userDirectory} or user id {userId} found.");
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex, $"The owner of the app {appId} could not found.");
            }
            return(resultUser);
        }
Exemplo n.º 3
0
 public static bool ValidateSession(SessionInfo sessionInfo)
 {
     try
     {
         var qrsHub = new QlikQrsHub(sessionInfo.ConnectUri, sessionInfo.Cookie);
         var result = qrsHub.SendRequestAsync("about", HttpMethod.Get).Result;
         if (String.IsNullOrEmpty(result))
         {
             return(false);
         }
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Exemplo n.º 4
0
 private static DateTime?GetLastReloadTime(Uri serverUri, Cookie cookie, string appId)
 {
     try
     {
         var qrshub    = new QlikQrsHub(serverUri, cookie);
         var qrsResult = qrshub.SendRequestAsync($"app/{appId}", HttpMethod.Get).Result;
         logger.Trace($"appResult:{qrsResult}");
         dynamic  jObject    = JObject.Parse(qrsResult);
         DateTime reloadTime = jObject?.lastReloadTime.ToObject <DateTime>() ?? null;
         return(reloadTime);
     }
     catch (Exception ex)
     {
         logger.Error(ex, "The last reload time could not found.");
         return(null);
     }
 }
Exemplo n.º 5
0
 private static int GetTaskStatus(Uri serverUri, Cookie cookie, string appId)
 {
     try
     {
         var qrshub    = new QlikQrsHub(serverUri, cookie);
         var qrsResult = qrshub.SendRequestAsync($"task/full", HttpMethod.Get).Result;
         logger.Trace($"taskResult:{qrsResult}");
         dynamic tasks = JArray.Parse(qrsResult);
         foreach (var task in tasks)
         {
             if (task.app.id == appId)
             {
                 return(task.operational.lastExecutionResult.status);
             }
         }
         return(0);
     }
     catch (Exception ex)
     {
         logger.Error(ex, "The last reload time could not found.");
         return(0);
     }
 }