Exemple #1
0
        public static string[] GetAllowedResourceNames(string userId, IEnumerable <Resource> resources)
        {
            var rightsService = Discovery.GetRightsService();

            string[] allowedResources = new string[0];

            try
            {
                string[] resourceUris = resources.Select(r => String.Format(URI_RESOURCE_FORMAT, r.ResourceName)).ToArray();

                allowedResources = rightsService
                                   .GetAccessibleFrom(userId, resourceUris, URI_RIGHT_RESOURCE_EXECUTE)
                                   .Select(uri => uri.Name)
                                   .ToArray();

                rightsService.Close();
            }
            catch (Exception e)
            {
                rightsService.Abort();
                Log.Error("Exception on getting allowed resources from UserManagement for user " + userId + ": " + e.ToString());
            }

            if (IsRightsIgnored())
            {
                allowedResources = resources.Select(r => r.ResourceName).ToArray();
            }

            Log.Info(String.Format("Allowed resources for user '{0}': [{1}]", userId, String.Join(", ", allowedResources)));
            return(allowedResources);
        }
Exemple #2
0
        public static bool CanExecutePackage(string userId, string packageName)
        {
            var  rightsService    = Discovery.GetRightsService();
            bool isPackageAllowed = false;

            try
            {
                isPackageAllowed = rightsService.CanAccess(userId, String.Format(URI_PACKAGE_FORMAT, packageName), URI_RIGHT_PACKAGE_EXECUTE);
                rightsService.Close();
            }
            catch (Exception e)
            {
                rightsService.Abort();
                Log.Error("Exception on check from UserManagement if user " + userId + " can use package " + packageName + ": " + e.ToString());
            }

            if (IsRightsIgnored())
            {
                isPackageAllowed = true;
            }

            return(isPackageAllowed);
        }