예제 #1
0
        public static void Save(object arr)
        {
            int i = 0;
            IEnumerable <Role> iRoleList = RoleList.Where(r => r.Name != System.Configuration.ConfigurationManager.AppSettings["GroupAdmin"]);

            foreach (object[] item in (object[])arr)
            {
                int j = 0;
                foreach (bool subItem in item)
                {
                    if (subItem != AuthenticationList[i][j])
                    {
                        Role            role            = iRoleList.ElementAt(i);
                        TopicPermission topicPermission = TopicPermissionList[j];
                        if (subItem)
                        {
                            TopicAuthenticationManager.AddPermission(topicPermission, role);
                        }
                        else
                        {
                            TopicAuthenticationManager.RemovePermission(topicPermission, role);
                        }
                    }
                    j++;
                }
                i++;
            }
        }
예제 #2
0
        public static string GetFunctions(int fcatId)
        {
            FunctionList = FunctionCategoryList.Where(fc => fc.Id == fcatId).Single().FunctionList;
            int i = 0;

            AuthenticationList = new List <List <bool> >();
            foreach (Role r in RoleList)
            {
                if (r.Name == System.Configuration.ConfigurationManager.AppSettings["GroupAdmin"])
                {
                    continue;
                }
                AuthenticationList.Add(new List <bool>());
                foreach (Function f in FunctionList)
                {
                    AuthenticationList[i].Add(SystemAuthentication.FunctionAuthenticationList[Function.Parse(f.Id)].Contains(r));
                }
                i++;
            }
            IEnumerable <Role> iRoleList = RoleList.Where(r => r.Name != System.Configuration.ConfigurationManager.AppSettings["GroupAdmin"]);
            var result = new { FunctionList = FunctionList, RoleList = iRoleList, AuthenticationList = AuthenticationList };

            System.Web.Script.Serialization.JavaScriptSerializer js = new System.Web.Script.Serialization.JavaScriptSerializer();
            return(js.Serialize(result));
        }
예제 #3
0
        private IEnumerable <ManagedRole> UpdateRoles(IManagedTenant tenant, RoleList roles, ICollection <IEntity> entities)
        {
            using (Profiler.Measure("PlatformService.UpdateRoles:tenant"))
            {
                if (tenant == null)
                {
                    throw new ArgumentNullException("tenant");
                }

                var ids = roles == null?Enumerable.Empty <string>() : roles.Select(r => r.RemoteId.ToString());

                CastEntityHelper.Delete(tenant.Roles.Where(r => !ids.Contains(r.RemoteId)).Select(t => new EntityRef(t.Id)));

                if (roles == null)
                {
                    return(Enumerable.Empty <ManagedRole>());
                }

                var updatedEntities = roles.Where(r => r.RemoteId > 0).Select(r => UpdateRole(tenant, r, entities)).ToList();

                entities.AddRange(updatedEntities);

                return(updatedEntities);
            }
        }
예제 #4
0
        public static void Save(object arr)
        {
            int i = 0;
            IEnumerable <Role> iRoleList = RoleList.Where(r => r.Name != System.Configuration.ConfigurationManager.AppSettings["GroupAdmin"]);

            foreach (object[] item in (object[])arr)
            {
                int j = 0;
                foreach (bool subItem in item)
                {
                    if (subItem != AuthenticationList[i][j])
                    {
                        Role     role     = iRoleList.ElementAt(i);
                        Function function = FunctionList[j];
                        if (subItem)
                        {
                            SystemAuthentication.AddRoleForFunction(Function.Parse(function.Id), role);
                        }
                        else
                        {
                            SystemAuthentication.RemoveRoleForFunction(Function.Parse(function.Id), role);
                        }
                    }
                    j++;
                }
                i++;
            }
        }
예제 #5
0
        private IEnumerable <ManagedRole> UpdateRoles(IManagedUser user, RoleList roles, ICollection <IEntity> entities)
        {
            using (Profiler.Measure("PlatformService.UpdateRoles:user"))
            {
                if (user == null)
                {
                    throw new ArgumentNullException("user");
                }

                var ids = roles == null?Enumerable.Empty <string>() : roles.Select(r => r.RemoteId.ToString());

                var removeRoles = roles != null?user.Roles.Where(r => !ids.Contains(r.RemoteId)) : Enumerable.Empty <ManagedRole>();

                user.Roles.RemoveRange(removeRoles);

                if (roles == null)
                {
                    return(Enumerable.Empty <ManagedRole>());
                }

                var updatedEntities = roles.Where(r => r.RemoteId > 0).Select(r => UpdateRole(null, r, entities)).ToList();

                entities.AddRange(updatedEntities);

                return(updatedEntities);
            }
        }
예제 #6
0
        private void addRoleBy(int id)
        {
            object _lock = new object();

            if (RoleModelList != null)
            {
                Role roleFound = RoleModelList.Where(x => x.Role.ID == id).Select(x => x.Role).FirstOrDefault();
                lock (_lock)
                    if (roleFound != null)
                    {
                        if (RoleList == null)
                        {
                            RoleList = new List <Role>();
                        }

                        if (RoleList.Where(x => x.ID == roleFound.ID).Count() == 0)
                        {
                            RoleList.Add(roleFound);
                            RoleToAddList.Add(new RoleModel {
                                Role = roleFound
                            });
                        }
                        else
                        {
                            RoleList = RoleList.Where(x => x.ID != roleFound.ID).ToList();
                            RoleToRemoveList.Add(new RoleModel {
                                Role = roleFound
                            });
                        }
                    }
            }
        }
예제 #7
0
        public async Task <IActionResult> OnPost()
        {
            var user = await _userManager.FindByIdAsync(UserId);

            //await _userManager.RemoveFromRolesAsync(user, RoleList.Where(r => r.IsInRole == false).Select(r => r.Name));
            await _userManager.AddToRolesAsync(user, RoleList.Where(r => r.IsInRole == true).Select(r => r.Name));

            //await _userManager.UpdateAsync(user);
            return(RedirectToPage("./index"));
        }
예제 #8
0
        public static void RoleDelete(string[] arrId)
        {
            foreach (string id in arrId)
            {
                Guid idRole = new Guid(id);
                Role role   = RoleList.Where(u => u.Id == idRole).Single();
                RoleList.Remove(role);

                UserInRole roleOfUser = RoleOfUserList.Where(u => u.RoleId == idRole && u.UserId == Args.User.Id).Single();
                RoleOfUserList.Remove(roleOfUser);

                RoleNotOfUserCollection.Add(role);
                RoleNotOfUserList.Add(roleOfUser);
            }
        }
예제 #9
0
        private bool checkIfRoleAnonymous(int id)
        {
            object _lock = new object();

            if (RoleList != null)
            {
                Role roleFound = RoleList.Where(x => x.ID == id && x.Name == "Anonymous").FirstOrDefault();
                lock (_lock)
                    if (roleFound != null)
                    {
                        return(true);
                    }
            }
            return(false);
        }
예제 #10
0
        private bool getRoleBooleanByID(int id)
        {
            object _lock = new object();

            if (RoleList != null)
            {
                Role roleFound = RoleList.Where(x => x.ID == id).FirstOrDefault();
                lock (_lock)
                    if (roleFound != null)
                    {
                        return(true);
                    }
            }
            return(false);
        }
예제 #11
0
        private IEnumerable <string> ListVMRoles()
        {
            IEnumerable <string>      strs;
            Func <string, Deployment> func = null;

            using (OperationContextScope operationContextScope = new OperationContextScope((IContextChannel)base.Channel))
            {
                GetAzureVMCommand getAzureVMCommand = this;
                if (func == null)
                {
                    func = (string s) => base.Channel.GetDeployment(s, this.ServiceName, base.CurrentDeployment.Name);
                }
                Deployment         deployment = ((CmdletBase <IServiceManagement>)getAzureVMCommand).RetryCall <Deployment>(func);
                RoleList           roleList   = deployment.RoleList;
                IEnumerable <Role> roles      = roleList.Where <Role>((Role r) => r.RoleType == "PersistentVMRole");
                strs = roles.Select <Role, string>((Role r) => r.RoleName);
            }
            return(strs);
        }
예제 #12
0
        public static string GetData()
        {
            int i = 0;

            foreach (Role r in RoleList)
            {
                if (r.Name == System.Configuration.ConfigurationManager.AppSettings["GroupAdmin"])
                {
                    continue;
                }
                AuthenticationList.Add(new List <bool>());
                foreach (MenuMasterPermission tp in MenuMasterPermissionList)
                {
                    AuthenticationList[i].Add(MenuMasterAuthenticationManager.GetRolesForPermission(tp).Contains(r));
                }
                i++;
            }
            IEnumerable <Role> iRoleList = RoleList.Where(r => r.Name != System.Configuration.ConfigurationManager.AppSettings["GroupAdmin"]);
            var result = new { MenuMasterPermissionList = MenuMasterPermissionList, RoleList = iRoleList, AuthenticationList = AuthenticationList };

            System.Web.Script.Serialization.JavaScriptSerializer js = new System.Web.Script.Serialization.JavaScriptSerializer();
            return(js.Serialize(result));
        }
예제 #13
0
        public async Task <IActionResult> OnPostAsync(string userid)
        {
            var user = await _userManager.FindByIdAsync(userid);

            var role_user = await _userManager.GetRolesAsync(user);

            try
            {
                var result = await _userManager.RemoveFromRolesAsync(user, role_user);

                if (!result.Succeeded)
                {
                    ModelState.AddModelError("", "Cannot remove user existing role");
                    return(new RedirectToPageResult("Error"));
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
            }

            try
            {
                var result = await _userManager.AddToRolesAsync(user, RoleList.Where(x => x.IsSelected).Select(y => y.RoleName));

                if (!result.Succeeded)
                {
                    ModelState.AddModelError("", "Cannot add selected roles to user");
                    return(new RedirectToPageResult("Error"));
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
            }
            return(new RedirectToPageResult("EditUsers", new { ID = userid }));
        }
예제 #14
0
        public void GetRoleProcess()
        {
            RoleList                  roleList;
            RoleInstanceList          roleInstanceList;
            Func <Role, bool>         func  = null;
            Func <RoleInstance, bool> func1 = null;

            this.GetCurrentDeployment();
            if (this.currentDeployment != null)
            {
                SwitchParameter instanceDetails = this.InstanceDetails;
                if (instanceDetails.IsPresent)
                {
                    Collection <RoleInstanceContext> roleInstanceContexts = new Collection <RoleInstanceContext>();
                    if (!string.IsNullOrEmpty(this.RoleName))
                    {
                        RoleInstanceList roleInstanceList1 = this.currentDeployment.RoleInstanceList;
                        if (func1 == null)
                        {
                            func1 = (RoleInstance r) => r.RoleName.Equals(this.RoleName, StringComparison.OrdinalIgnoreCase);
                        }
                        roleInstanceList = new RoleInstanceList(roleInstanceList1.Where <RoleInstance>(func1));
                    }
                    else
                    {
                        roleInstanceList = this.currentDeployment.RoleInstanceList;
                    }
                    foreach (RoleInstance roleInstance in roleInstanceList)
                    {
                        RoleInstanceContext roleInstanceContext = new RoleInstanceContext();
                        roleInstanceContext.ServiceName = this.ServiceName;
                        roleInstanceContext.set_OperationId(this.getDeploymentOperation.OperationTrackingId);
                        roleInstanceContext.set_OperationDescription(base.CommandRuntime.ToString());
                        roleInstanceContext.set_OperationStatus(this.getDeploymentOperation.Status);
                        roleInstanceContext.InstanceErrorCode     = roleInstance.InstanceErrorCode;
                        roleInstanceContext.InstanceFaultDomain   = roleInstance.InstanceFaultDomain;
                        roleInstanceContext.InstanceName          = roleInstance.InstanceName;
                        roleInstanceContext.InstanceSize          = roleInstance.InstanceSize;
                        roleInstanceContext.InstanceStateDetails  = roleInstance.InstanceStateDetails;
                        roleInstanceContext.InstanceStatus        = roleInstance.InstanceStatus;
                        roleInstanceContext.InstanceUpgradeDomain = roleInstance.InstanceUpgradeDomain;
                        roleInstanceContext.RoleName          = roleInstance.RoleName;
                        roleInstanceContext.DeploymentID      = this.currentDeployment.PrivateID;
                        roleInstanceContext.InstanceEndpoints = roleInstance.InstanceEndpoints;
                        RoleInstanceContext roleInstanceContext1 = roleInstanceContext;
                        roleInstanceContexts.Add(roleInstanceContext1);
                    }
                    base.WriteObject(roleInstanceContexts, true);
                }
                else
                {
                    Collection <RoleContext> roleContexts = new Collection <RoleContext>();
                    if (!string.IsNullOrEmpty(this.RoleName))
                    {
                        RoleList roleList1 = this.currentDeployment.RoleList;
                        if (func == null)
                        {
                            func = (Role r) => r.RoleName.Equals(this.RoleName, StringComparison.OrdinalIgnoreCase);
                        }
                        roleList = new RoleList(roleList1.Where <Role>(func));
                    }
                    else
                    {
                        roleList = this.currentDeployment.RoleList;
                    }
                    List <Role> .Enumerator enumerator = roleList.GetEnumerator();
                    try
                    {
                        Func <RoleInstance, bool> func2 = null;
                        while (enumerator.MoveNext())
                        {
                            Role             current           = enumerator.Current;
                            RoleContext      roleContext       = new RoleContext();
                            RoleContext      roleContext1      = roleContext;
                            RoleInstanceList roleInstanceList2 = this.currentDeployment.RoleInstanceList;
                            if (func2 == null)
                            {
                                func2 = (RoleInstance ri) => ri.RoleName.Equals(current.RoleName, StringComparison.OrdinalIgnoreCase);
                            }
                            roleContext1.InstanceCount = roleInstanceList2.Where <RoleInstance>(func2).Count <RoleInstance>();
                            roleContext.RoleName       = current.RoleName;
                            roleContext.set_OperationDescription(base.CommandRuntime.ToString());
                            roleContext.set_OperationStatus(this.getDeploymentOperation.Status);
                            roleContext.set_OperationId(this.getDeploymentOperation.OperationTrackingId);
                            roleContext.ServiceName  = this.ServiceName;
                            roleContext.DeploymentID = this.currentDeployment.PrivateID;
                            RoleContext roleContext2 = roleContext;
                            roleContexts.Add(roleContext2);
                        }
                    }
                    finally
                    {
                        enumerator.Dispose();
                    }
                    base.WriteObject(roleContexts, true);
                    return;
                }
            }
        }
예제 #15
0
        public static void RoleEdit(string id)
        {
            Guid idRole = new Guid(id);

            PSCDialog.DataShare = new RoleArgs(RoleList.Where(a => a.Id == idRole).Single(), true);
        }
예제 #16
0
        public IEnumerable <PersistentVMRoleContext> GetVirtualMachineProcess()
        {
            RoleList roleList;

            GetAzureVMCommand.GetAzureVMCommand   variable = null;
            IEnumerable <PersistentVMRoleContext> persistentVMRoleContexts;
            Func <Role, bool> func = null;

            if (string.IsNullOrEmpty(this.ServiceName) || base.CurrentDeployment != null)
            {
                using (OperationContextScope operationContextScope = new OperationContextScope((IContextChannel)base.Channel))
                {
                    try
                    {
                        List <PersistentVMRoleContext> persistentVMRoleContexts1 = new List <PersistentVMRoleContext>();
                        if (!string.IsNullOrEmpty(this.ServiceName))
                        {
                            if (!string.IsNullOrEmpty(this.Name))
                            {
                                RoleList roleList1 = base.CurrentDeployment.RoleList;
                                if (func == null)
                                {
                                    func = (Role r) => r.RoleName.Equals(this.Name, StringComparison.InvariantCultureIgnoreCase);
                                }
                                roleList = new RoleList(roleList1.Where <Role>(func));
                            }
                            else
                            {
                                roleList = base.CurrentDeployment.RoleList;
                            }
                            for (int i = 0; i < roleList.Count; i++)
                            {
                                string empty = string.Empty;
                                try
                                {
                                    empty = roleList[i].RoleName;
                                    PersistentVMRole        item = (PersistentVMRole)roleList[i];
                                    PersistentVMRoleContext persistentVMRoleContext = new PersistentVMRoleContext();
                                    if (base.CurrentDeployment != null)
                                    {
                                        persistentVMRoleContext.DNSName = base.CurrentDeployment.Url.AbsoluteUri;
                                    }
                                    persistentVMRoleContext.ServiceName            = this.ServiceName;
                                    persistentVMRoleContext.Name                   = item.RoleName;
                                    persistentVMRoleContext.DeploymentName         = base.CurrentDeployment.Name;
                                    persistentVMRoleContext.VM                     = new PersistentVM();
                                    persistentVMRoleContext.VM.AvailabilitySetName = item.AvailabilitySetName;
                                    persistentVMRoleContext.AvailabilitySetName    = item.AvailabilitySetName;
                                    persistentVMRoleContext.Label                  = item.Label;
                                    persistentVMRoleContext.VM.ConfigurationSets   = item.ConfigurationSets;
                                    persistentVMRoleContext.VM.ConfigurationSets.OfType <NetworkConfigurationSet>().SingleOrDefault <NetworkConfigurationSet>();
                                    persistentVMRoleContext.VM.DataVirtualHardDisks = item.DataVirtualHardDisks;
                                    persistentVMRoleContext.VM.Label             = item.Label;
                                    persistentVMRoleContext.VM.OSVirtualHardDisk = item.OSVirtualHardDisk;
                                    persistentVMRoleContext.VM.RoleName          = item.RoleName;
                                    persistentVMRoleContext.Name                 = item.RoleName;
                                    persistentVMRoleContext.VM.RoleSize          = item.RoleSize;
                                    persistentVMRoleContext.InstanceSize         = item.RoleSize;
                                    persistentVMRoleContext.VM.RoleType          = item.RoleType;
                                    persistentVMRoleContext.InstanceStatus       = base.CurrentDeployment.RoleInstanceList.Where <RoleInstance>((RoleInstance r) => r.RoleName == item.RoleName).First <RoleInstance>().InstanceStatus;
                                    persistentVMRoleContext.IpAddress            = base.CurrentDeployment.RoleInstanceList.Where <RoleInstance>((RoleInstance r) => r.RoleName == this.vm.RoleName).First <RoleInstance>().IpAddress;
                                    persistentVMRoleContext.InstanceStateDetails = base.CurrentDeployment.RoleInstanceList.Where <RoleInstance>((RoleInstance r) => r.RoleName == item.RoleName).First <RoleInstance>().InstanceStateDetails;
                                    persistentVMRoleContext.PowerState           = base.CurrentDeployment.RoleInstanceList.Where <RoleInstance>((RoleInstance r) => r.RoleName == item.RoleName).First <RoleInstance>().PowerState;
                                    persistentVMRoleContext.InstanceErrorCode    = base.CurrentDeployment.RoleInstanceList.Where <RoleInstance>((RoleInstance r) => r.RoleName == item.RoleName).First <RoleInstance>().InstanceErrorCode;
                                    persistentVMRoleContext.InstanceName         = base.CurrentDeployment.RoleInstanceList.Where <RoleInstance>((RoleInstance r) => r.RoleName == item.RoleName).First <RoleInstance>().InstanceName;
                                    int?instanceFaultDomain = base.CurrentDeployment.RoleInstanceList.Where <RoleInstance>((RoleInstance r) => r.RoleName == item.RoleName).First <RoleInstance>().InstanceFaultDomain;
                                    int value = instanceFaultDomain.Value;
                                    persistentVMRoleContext.InstanceFaultDomain = value.ToString();
                                    int?instanceUpgradeDomain = base.CurrentDeployment.RoleInstanceList.Where <RoleInstance>((RoleInstance r) => r.RoleName == item.RoleName).First <RoleInstance>().InstanceUpgradeDomain;
                                    int num = instanceUpgradeDomain.Value;
                                    persistentVMRoleContext.InstanceUpgradeDomain = num.ToString();
                                    persistentVMRoleContext.set_OperationDescription(base.CommandRuntime.ToString());
                                    persistentVMRoleContext.set_OperationId(base.GetDeploymentOperation.OperationTrackingId);
                                    persistentVMRoleContext.set_OperationStatus(base.GetDeploymentOperation.Status);
                                    persistentVMRoleContexts1.Add(persistentVMRoleContext);
                                }
                                catch (Exception exception)
                                {
                                    base.WriteObject(string.Format("Could not read properties for virtual machine: {0}. It may still be provisioning.", empty));
                                }
                            }
                            if (!string.IsNullOrEmpty(this.Name) && persistentVMRoleContexts1 != null && persistentVMRoleContexts1.Count > 0)
                            {
                                this.SaveRoleState(persistentVMRoleContexts1[0].VM);
                            }
                            persistentVMRoleContexts = persistentVMRoleContexts1;
                            return(persistentVMRoleContexts);
                        }
                        else
                        {
                            this.ListAllVMs();
                            persistentVMRoleContexts = null;
                            return(persistentVMRoleContexts);
                        }
                    }
                    catch (CommunicationException communicationException1)
                    {
                        CommunicationException communicationException = communicationException1;
                        if (communicationException as EndpointNotFoundException == null || base.IsVerbose())
                        {
                            this.WriteErrorDetails(communicationException);
                        }
                        else
                        {
                            persistentVMRoleContexts = null;
                            return(persistentVMRoleContexts);
                        }
                    }
                    persistentVMRoleContexts = null;
                }
                return(persistentVMRoleContexts);
            }
            else
            {
                return(null);
            }
        }