Ejemplo n.º 1
0
        private void SetRole(RoleDescription existingRole)
        {
            //this.Role.AssignUnassignRole
            //this.Role.CanCreateRoot
            //this.Role.CanCreateUsers
            //this.Role.CanManageSubRoles
            this.Role.ChildRoles = existingRole.ChildRoles.Select(r => r.Id).ToList();
            //this.Role.DataEntities
            //this.Role.DataEntityPermission
            this.Role.Id     = existingRole.Id;
            this.Role.IsRoot = existingRole.IsRoot;
            this.Role.Name   = existingRole.Name;
            this.Role.Users  = existingRole.Users.Select(u => u.Id).ToList();

            this.textBoxName.Text = existingRole.Name.GetString();
            this.checkBoxCanAssignUnassignRole.Checked = existingRole.AssignUnassignRole;
            this.checkBoxCanManageSubroles.Checked     = existingRole.CanManageSubRoles;
            this.checkBoxCanCreateRootRoles.Checked    = existingRole.CanCreateRoot;
            this.checkBoxCanCreateUsers.Checked        = existingRole.CanCreateUsers;

            switch (existingRole.DataEntityPermission)
            {
            case DataEntityPermission.ReadContent:
                this.radioButtonPermissionReadonly.Checked = true;
                break;

            case DataEntityPermission.ModifyContent:
                this.radioButtonPermissionModify.Checked = true;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Ejemplo n.º 2
0
        // Handle hashes for everything but the managers / service owners isCertified and the
        // risk rating. The isCertified stuff gets reset everytime a new cycle happens and
        // risk rating is calculated from threat and likelihood ratings so we can ignore those
        public override int GetHashCode()
        {
            int hashUserId       = UserId == null ? 0 : UserId.GetHashCode();
            int hashUserFullName = UserFullName == null ? 0 : UserFullName.GetHashCode();

            int hashRoleId           = RoleId == null ? 0 : RoleId.GetHashCode();
            int hashRoleName         = RoleName == null ? 0 : RoleName.GetHashCode();
            int hashRoleDescription  = RoleDescription == null ? 0 : RoleDescription.GetHashCode();
            int hashRoleOwner_RoleId = RoleOwner_RoleId == null ? 0 : RoleOwner_RoleId.GetHashCode();

            int hashLastCertifiedBy   = LastCertifiedBy == null ? 0 : LastCertifiedBy.GetHashCode();
            int hashLastCertifiedDate = LastCertifiedDate == null ? 0 : LastCertifiedDate.GetHashCode();

            // Calculate the hash code for the object.
            return(hashUserId ^
                   hashUserFullName ^

                   hashRoleId ^
                   hashRoleName ^
                   hashRoleDescription ^
                   hashRoleOwner_RoleId ^

                   hashLastCertifiedBy ^
                   hashLastCertifiedDate);
        }
 /// <inheritdoc/>
 public override int GetHashCode()
 => Role.GetHashCode() ^
 Name.GetHashCode() ^
 Value.GetHashCode() ^
 Description.GetHashCode() ^
 KeyShortcuts.GetHashCode() ^
 RoleDescription.GetHashCode() ^
 ValueText.GetHashCode() ^
 AutoComplete.GetHashCode() ^
 HasPopup.GetHashCode() ^
 Orientation.GetHashCode() ^
 Disabled.GetHashCode() ^
 Expanded.GetHashCode() ^
 Focused.GetHashCode() ^
 Modal.GetHashCode() ^
 Multiline.GetHashCode() ^
 Multiselectable.GetHashCode() ^
 Readonly.GetHashCode() ^
 Required.GetHashCode() ^
 Selected.GetHashCode() ^
 Pressed.GetHashCode() ^
 Checked.GetHashCode() ^
 Level.GetHashCode() ^
 ValueMin.GetHashCode() ^
 ValueMax.GetHashCode() ^
 Children.GetHashCode();
Ejemplo n.º 4
0
        // The following methods support the delta reports
        public bool Equals([AllowNull] UserRoleAllDTO other)
        {
            // Check whether the compared object is null.
            if (other is null)
            {
                return(false);
            }

            // Check whether the compared object references the same data.
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            // Check whether the objects’ properties are equal.
            return(UserId.Equals(other.UserId) &&
                   UserFullName.Equals(other.UserFullName) &&

                   RoleId.Equals(other.RoleId) &&
                   RoleName.Equals(other.RoleName) &&
                   RoleDescription.Equals(other.RoleDescription) &&
                   RoleOwner_RoleId.Equals(other.RoleOwner_RoleId) &&

                   LastCertifiedBy.Equals(other.LastCertifiedBy) &&
                   LastCertifiedDate.Equals(other.LastCertifiedDate));
        }
Ejemplo n.º 5
0
        private void buttonUpdateSubRole_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.treeViewRoles.SelectedNode != null &&
                    this.treeViewRoles.SelectedNode.Tag is RoleDescription &&
                    this.treeViewRoles.SelectedNode.Parent != null)
                {
                    RoleDescription selectedRole = (RoleDescription)this.treeViewRoles.SelectedNode.Tag;

                    RoleDescription parentRole = (RoleDescription)this.treeViewRoles.SelectedNode.Parent.Tag;

                    CustomizeRoleDialog dialog = new CustomizeRoleDialog(selectedRole, "Update the role " + selectedRole.Name.GetString());
                    DialogResult        result = dialog.ShowDialog();

                    if (result == DialogResult.OK)
                    {
                        IPreService preProxy = GetPreProxy();
                        dialog.Role.Name = preProxy.Encrypt(this.keyPair.Public, dialog.Role.Name);


                        IGatewayService proxy = GetServiceProxy();
                        proxy.UpdateSubRole(this.myId, parentRole.Id, dialog.Role);

                        buttonRefreshRolesAndUsers_Click(this, EventArgs.Empty);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: " + ex.Message);
                Logger.LogError("Error updating sub-role user", ex);
            }
        }
Ejemplo n.º 6
0
        private void buttonAddUserToRole_Click(object sender, EventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(this.textBoxNewUserName.Text))
                {
                    MessageBox.Show("You must enter a username");
                    return;
                }

                Guid userId = GuidCreator.CreateGuidFromString(this.textBoxNewUserName.Text);

                if (this.treeViewRoles.SelectedNode != null &&
                    this.treeViewRoles.SelectedNode.Tag is RoleDescription)
                {
                    RoleDescription selectedRole = (RoleDescription)this.treeViewRoles.SelectedNode.Tag;

                    DialogResult result = MessageBox.Show("Are you sure you wan't to grant the role " + selectedRole.Name.GetString() + " to the user " + this.textBoxNewUserName.Text + "?", "Role assignment confirmation", MessageBoxButtons.YesNo);

                    if (result == DialogResult.Yes)
                    {
                        IGatewayService proxy = GetServiceProxy();
                        proxy.AssignRoleToUser(this.myId, selectedRole.Id, userId);

                        buttonRefreshRolesAndUsers_Click(this, EventArgs.Empty);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: " + ex.Message);
                Logger.LogError("Error updating sub-role user", ex);
            }
        }
Ejemplo n.º 7
0
        private void buttonRemoveUserFromRole_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.treeViewRoles.SelectedNode != null &&
                    this.treeViewRoles.SelectedNode.Tag is UserDescription &&
                    this.treeViewRoles.SelectedNode.Parent != null)
                {
                    UserDescription selectedUser = (UserDescription)this.treeViewRoles.SelectedNode.Tag;
                    RoleDescription parentRole   = (RoleDescription)this.treeViewRoles.SelectedNode.Parent.Tag;

                    DialogResult result = MessageBox.Show("Are you sure you wan't remove the user " + selectedUser.Name.GetString() + " from the role " + parentRole.Name.GetString() + "?", "Role un-assignment confirmation", MessageBoxButtons.YesNo);

                    if (result == DialogResult.Yes)
                    {
                        IGatewayService proxy = GetServiceProxy();
                        proxy.RemoveRoleFromUser(this.myId, parentRole.Id, selectedUser.Id);

                        buttonRefreshRolesAndUsers_Click(this, EventArgs.Empty);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: " + ex.Message);
                Logger.LogError("Error updating sub-role user", ex);
            }
        }
Ejemplo n.º 8
0
 public CustomizeRoleDialog(RoleDescription existingRole, string text)
     : this(text)
 {
     SetRole(existingRole);
     this.buttonCreateSubRole.Text = "Update sub-role";
     this.Text = "Update existing sub-role";
     this.checkBoxMakeThisRootRole.Enabled = false;
 }
        // The following methods support the delta reports

        // Handle equals for everything but the managers / service owners isCertified and the
        // risk rating. The isCertified stuff gets reset everytime a new cycle happens and
        // risk rating is calculated from threat and likelihood ratings so we can ignore those
        public bool Equals([AllowNull] RoleServicePrivAllDTO other)
        {
            // Check whether the compared object is null.
            if (other is null)
            {
                return(false);
            }

            // Check whether the compared object references the same data.
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            // Check whether the objects’ properties are equal.
            // Role stuff
            return(RolePrivId.Equals(other.RolePrivId) &&
                   RoleId.Equals(other.RoleId) &&
                   RoleName.Equals(other.RoleName) &&
                   RoleDescription.Equals(other.RoleDescription) &&
                   RoleOwner_RoleId.Equals(other.RoleOwner_RoleId) &&

                   // Manager stuff
                   RoleOwner_PrivId.Equals(other.RoleOwner_PrivId) &&
                   RoleOwner_PermissionGroup.Equals(other.RoleOwner_PermissionGroup) &&
                   RoleOwner_ServicePrivSummary.Equals(other.RoleOwner_ServicePrivSummary) &&
                   RoleOwner_CredentialStorageMethod.Equals(other.RoleOwner_CredentialStorageMethod) &&
                   RoleOwner_ServiceId.Equals(other.RoleOwner_ServiceId) &&
                   RoleOwner_ServiceName.Equals(other.RoleOwner_ServiceName) &&
                   RoleOwner_ServiceDescription.Equals(other.RoleOwner_ServiceDescription) &&

                   RoleOwner_RoleAccessJustification.Equals(other.RoleOwner_RoleAccessJustification) &&
                   RoleOwner_RemovalImpact.Equals(other.RoleOwner_RemovalImpact) &&
                   RoleOwner_IsRevoked.Equals(other.RoleOwner_IsRevoked) &&
                   RoleOwner_DateCertified.Equals(other.RoleOwner_DateCertified));/* &&
                                                                                   *
                                                                                   * // Service Owner Stuff
                                                                                   * ServiceOwner_PrivId.Equals(other.ServiceOwner_PrivId) &&
                                                                                   * ServiceOwner_PermissionGroup.Equals(other.ServiceOwner_PermissionGroup) &&
                                                                                   * ServiceOwner_ServicePrivSummary.Equals(other.ServiceOwner_ServicePrivSummary) &&
                                                                                   * ServiceOwner_CredentialStorageMethod.Equals(other.ServiceOwner_CredentialStorageMethod) &&
                                                                                   * ServiceOwner_ServiceId.Equals(other.ServiceOwner_ServiceId) &&
                                                                                   * ServiceOwner_ServiceName.Equals(other.ServiceOwner_ServiceName) &&
                                                                                   * ServiceOwner_ServiceDescription.Equals(other.ServiceOwner_ServiceDescription) &&
                                                                                   *
                                                                                   * ServiceOwner_RoleAccessJustification.Equals(other.ServiceOwner_RoleAccessJustification) &&
                                                                                   * ServiceOwner_RemovalImpact.Equals(other.ServiceOwner_RemovalImpact) &&
                                                                                   * ServiceOwner_IsRevoked.Equals(other.ServiceOwner_IsRevoked) &&
                                                                                   * ServiceOwner_DateCertified.Equals(other.ServiceOwner_DateCertified) &&
                                                                                   *
                                                                                   * // Risk stuff
                                                                                   * RiskImpact.Equals(other.RiskImpact) &&
                                                                                   * RiskLikelihood.Equals(other.RiskLikelihood) &&
                                                                                   * RiskNotes.Equals(other.RiskNotes) &&
                                                                                   * RiskAssessmentDate.Equals(other.RiskAssessmentDate);*/
        }
Ejemplo n.º 10
0
        public async Task RunBotAsync()
        {
            DateTimeOffset testTimeLocal = DateTimeOffset.Now;

            //Define Socket Client. Cache required to log messages
            _client = new DiscordSocketClient(new DiscordSocketConfig
            {
                //chang eback to .Info when finished debuggin
                LogLevel            = LogSeverity.Error,
                MessageCacheSize    = 500,
                AlwaysDownloadUsers = true,
            });

            _commands = new CommandService();

            _services = new ServiceCollection()
                        .AddSingleton(_client)
                        .AddSingleton(_commands)
                        .BuildServiceProvider();

            //Bot token, do not reveal
            //get token from file (DO NOT PUT THIS FILE ON REPO)
            string botToken = getToken();

            //Event subscriptions
            _client.Log              += Log;
            _client.UserJoined       += AnnounceUserJoined;
            _client.UserLeft         += AnnounceUserLeft;
            _client.UserBanned       += UserBanned;
            _client.UserUpdated      += UserUpdated;
            _client.MessageDeleted   += MessageDeleted;
            _client.MessageUpdated   += MessageUpdated;
            _client.ReactionAdded    += ReactionAdded;
            _client.ReactionRemoved  += ReactionRemoved;
            _client.Ready            += startThreads; //start threads once we're ready (connected to servers and all that, so we can start threads relying on channels)
            _client.ChannelDestroyed += channelDestroyed;

            foxboat.Services.ReliabilityService service = new foxboat.Services.ReliabilityService(_client);


            //initialise roll descriptions
            RoleDescription.init();


            await RegisterCommandsAsync();

            await _client.LoginAsync(TokenType.Bot, botToken);

            await _client.StartAsync();



            await Task.Delay(-1);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Returns true if Employee instances are equal
        /// </summary>
        /// <param name="other">Instance of Employee to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(Employee other)
        {
            if (ReferenceEquals(null, other))
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                ((
                     Id == other.Id ||
                     Id != null &&
                     Id.Equals(other.Id)
                     ) &&
                 (
                     Name == other.Name ||
                     Name != null &&
                     Name.Equals(other.Name)
                 ) &&
                 (
                     ContractTypeName == other.ContractTypeName ||
                     ContractTypeName != null &&
                     ContractTypeName.Equals(other.ContractTypeName)
                 ) &&
                 (
                     RoleId == other.RoleId ||
                     RoleId != null &&
                     RoleId.Equals(other.RoleId)
                 ) &&
                 (
                     RoleName == other.RoleName ||
                     RoleName != null &&
                     RoleName.Equals(other.RoleName)
                 ) &&
                 (
                     RoleDescription == other.RoleDescription ||
                     RoleDescription != null &&
                     RoleDescription.Equals(other.RoleDescription)
                 ) &&
                 (
                     HourlySalary == other.HourlySalary ||
                     HourlySalary != null &&
                     HourlySalary.Equals(other.HourlySalary)
                 ) &&
                 (
                     MonthlySalary == other.MonthlySalary ||
                     MonthlySalary != null &&
                     MonthlySalary.Equals(other.MonthlySalary)
                 ));
        }
        /// <summary>
        /// Returns true if PersonWithWearable instances are equal
        /// </summary>
        /// <param name="other">Instance of PersonWithWearable to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(PersonWithWearable other)
        {
            if (ReferenceEquals(null, other))
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                ((
                     PersonId == other.PersonId ||
                     PersonId != null &&
                     PersonId.Equals(other.PersonId)
                     ) &&
                 (
                     Name == other.Name ||
                     Name != null &&
                     Name.Equals(other.Name)
                 ) &&
                 (
                     Status == other.Status ||
                     Status != null &&
                     Status.Equals(other.Status)
                 ) &&
                 (
                     Role == other.Role ||
                     Role != null &&
                     Role.Equals(other.Role)
                 ) &&
                 (
                     RoleDescription == other.RoleDescription ||
                     RoleDescription != null &&
                     RoleDescription.Equals(other.RoleDescription)
                 ) &&
                 (
                     Lat == other.Lat ||
                     Lat != null &&
                     Lat.Equals(other.Lat)
                 ) &&
                 (
                     Lon == other.Lon ||
                     Lon != null &&
                     Lon.Equals(other.Lon)
                 ) &&
                 (
                     Timestamp == other.Timestamp ||
                     Timestamp != null &&
                     Timestamp.Equals(other.Timestamp)
                 ));
        }
Ejemplo n.º 13
0
        private void ShowRoleDetail(RoleDescription role)
        {
            SetDetailMode(true);

            this.labelDetailId.Text             = role.Id.ToString();
            this.labelDetailName.Text           = role.Name.GetString();
            this.labelDetailCreateUsers.Text    = role.CanCreateUsers.ToString();
            this.labelDetailPermission.Text     = Enum.GetName(typeof(DataEntityPermission), role.DataEntityPermission);
            this.labelDetailRootRoles.Text      = role.CanCreateRoot.ToString();
            this.labelDetailSubRoles.Text       = role.CanManageSubRoles.ToString();
            this.labelDetailIsRootRole.Text     = role.IsRoot.ToString();
            this.labelDetailsCanBeAssigned.Text = role.AssignUnassignRole.ToString();
        }
        private RoleRM CreateRole(Commands.V1.Role.Create cmd)
        {
            if (_repository.RoleExists(cmd.RoleName))
            {
                throw new InvalidOperationException($"Role with name {cmd.RoleName} already exists");
            }

            Role role = Role.Create(_roles++, RoleName.Create(cmd.RoleName), RoleDescription.Create(cmd.RoleDescription),
                                    cmd.IsActive);

            _repository.AddRole(role);

            return(Conversions.GetRoleRM(role));
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Returns true if Person instances are equal
        /// </summary>
        /// <param name="other">Instance of Person to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(Person other)
        {
            if (ReferenceEquals(null, other))
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                ((
                     Id == other.Id ||
                     Id != null &&
                     Id.Equals(other.Id)
                     ) &&
                 (
                     FullName == other.FullName ||
                     FullName != null &&
                     FullName.Equals(other.FullName)
                 ) &&
                 (
                     Phone == other.Phone ||
                     Phone != null &&
                     Phone.Equals(other.Phone)
                 ) &&
                 (
                     Email == other.Email ||
                     Email != null &&
                     Email.Equals(other.Email)
                 ) &&
                 (
                     Role == other.Role ||
                     Role != null &&
                     Role.Equals(other.Role)
                 ) &&
                 (
                     RoleDescription == other.RoleDescription ||
                     RoleDescription != null &&
                     RoleDescription.Equals(other.RoleDescription)
                 ) &&
                 (
                     Active == other.Active ||
                     Active != null &&
                     Active.Equals(other.Active)
                 ));
        }
Ejemplo n.º 16
0
        private void buttonCreateSubRole_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.treeViewRoles.SelectedNode != null &&
                    this.treeViewRoles.SelectedNode.Tag is RoleDescription)
                {
                    RoleDescription selectedRole = (RoleDescription)this.treeViewRoles.SelectedNode.Tag;

                    IGatewayService    proxy        = GetServiceProxy();
                    IList <DataEntity> dataEntities = proxy.GetDataEntitiesForRole(this.myId, selectedRole.Id);

                    DecryptDataEntities(dataEntities);

                    CustomizeRoleDialog dialog = new CustomizeRoleDialog("Create new subrole from " + selectedRole.Name.GetString());
                    dialog.SetDataEntities(dataEntities);

                    DialogResult result = dialog.ShowDialog();

                    if (result == DialogResult.OK)
                    {
                        Role newRole = dialog.Role;
                        newRole.Id = Guid.NewGuid();

                        IPreService preProxy = GetPreProxy();
                        newRole.Name = preProxy.Encrypt(this.keyPair.Public, newRole.Name);

                        if (newRole.IsRoot)
                        {
                            newRole.Users.Add(this.myId);
                        }

                        proxy = GetServiceProxy();
                        proxy.CreateSubRole(this.myId, selectedRole.Id, newRole);

                        buttonRefreshRolesAndUsers_Click(this, EventArgs.Empty);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: " + ex.Message);
                Logger.LogError("Error creating sub-role user", ex);
            }
        }
Ejemplo n.º 17
0
        private void buttonDeleteRole_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.treeViewRoles.SelectedNode != null &&
                    this.treeViewRoles.SelectedNode.Tag is RoleDescription)
                {
                    RoleDescription selectedRole = (RoleDescription)this.treeViewRoles.SelectedNode.Tag;

                    if (selectedRole.IsRoot ||
                        this.treeViewRoles.SelectedNode.Parent != null)
                    {
                        string message = "Are you sure you want to delete" + selectedRole.Name.GetString() + " ?";
                        if (selectedRole.IsRoot)
                        {
                            message = "Are you sure you want to delete " + selectedRole.Name.GetString() +
                                      "? It is a root role, so all its child roles will also be deleted!";
                        }

                        DialogResult result = MessageBox.Show(message, "Deletion confirmation", MessageBoxButtons.YesNo);

                        if (result == DialogResult.Yes)
                        {
                            IGatewayService proxy = GetServiceProxy();

                            Guid parentRoleId = Guid.Empty;
                            if (!selectedRole.IsRoot)
                            {
                                parentRoleId = ((RoleDescription)this.treeViewRoles.SelectedNode.Parent.Tag).Id;
                            }

                            proxy.DeleteSubRole(this.myId, parentRoleId, selectedRole.Id);

                            buttonRefreshRolesAndUsers_Click(this, EventArgs.Empty);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: " + ex.Message);
                Logger.LogError("Error deleting role user", ex);
            }
        }
Ejemplo n.º 18
0
        private RoleDescription GetRolesRecursively(int depth, User user, Role role)
        {
            bool            includeUsers = role.IsRoot || depth > 0;
            RoleDescription desc         = ConvertRole(user, role, includeUsers);

            foreach (Guid childId in role.ChildRoles)
            {
                Role child = this.storage.GetRole(childId);

                if (child.IsRoot)   // skip root roles as parent roles cannot see and manage them
                {
                    continue;
                }

                desc.ChildRoles.Add(GetRolesRecursively(depth + 1, user, child));
            }

            return(desc);
        }
Ejemplo n.º 19
0
        public IActionResult Add(RoleViewModel model)
        {
            var newRole = new IdentityRole {
                Name = model.Role.Name, NormalizedName = model.Role.Name.ToUpper()
            };

            try
            {
                _context.Add(newRole);
                _context.SaveChanges();
            }
            catch
            {
                model.StatusMessage = "An error occured.";
                // If we got this far, something failed, redisplay form
                return(View(model));
            }

            var createdRole = _context.Roles.SingleOrDefault(c => c.Name == model.Role.Name);

            var roleType = new RoleTypes {
                RoleId = createdRole.Id, Id = model.Role.Type.Id
            };
            var roleDescription = new RoleDescription {
                RoleId = createdRole.Id, Description = model.Role.Description
            };

            try
            {
                _context.Update(createdRole);
                _context.Add(roleType);
                _context.Add(roleDescription);
                _context.SaveChanges();
            }
            catch
            {
                model.StatusMessage = "An error occured.";
                // If we got this far, something failed, redisplay form
                return(View(model));
            }

            return(RedirectToLocal("/Role/Index"));
        }
 /// <summary>
 /// Gets the hash code
 /// </summary>
 /// <returns>Hash code</returns>
 public override int GetHashCode()
 {
     unchecked // Overflow is fine, just wrap
     {
         var hashCode = 41;
         // Suitable nullity checks etc, of course :)
         if (PersonId != null)
         {
             hashCode = hashCode * 59 + PersonId.GetHashCode();
         }
         if (Name != null)
         {
             hashCode = hashCode * 59 + Name.GetHashCode();
         }
         if (Status != null)
         {
             hashCode = hashCode * 59 + Status.GetHashCode();
         }
         if (Role != null)
         {
             hashCode = hashCode * 59 + Role.GetHashCode();
         }
         if (RoleDescription != null)
         {
             hashCode = hashCode * 59 + RoleDescription.GetHashCode();
         }
         if (Lat != null)
         {
             hashCode = hashCode * 59 + Lat.GetHashCode();
         }
         if (Lon != null)
         {
             hashCode = hashCode * 59 + Lon.GetHashCode();
         }
         if (Timestamp != null)
         {
             hashCode = hashCode * 59 + Timestamp.GetHashCode();
         }
         return(hashCode);
     }
 }
Ejemplo n.º 21
0
 /// <summary>
 /// Gets the hash code
 /// </summary>
 /// <returns>Hash code</returns>
 public override int GetHashCode()
 {
     unchecked // Overflow is fine, just wrap
     {
         var hashCode = 41;
         // Suitable nullity checks etc, of course :)
         if (Id != null)
         {
             hashCode = hashCode * 59 + Id.GetHashCode();
         }
         if (Name != null)
         {
             hashCode = hashCode * 59 + Name.GetHashCode();
         }
         if (ContractTypeName != null)
         {
             hashCode = hashCode * 59 + ContractTypeName.GetHashCode();
         }
         if (RoleId != null)
         {
             hashCode = hashCode * 59 + RoleId.GetHashCode();
         }
         if (RoleName != null)
         {
             hashCode = hashCode * 59 + RoleName.GetHashCode();
         }
         if (RoleDescription != null)
         {
             hashCode = hashCode * 59 + RoleDescription.GetHashCode();
         }
         if (HourlySalary != null)
         {
             hashCode = hashCode * 59 + HourlySalary.GetHashCode();
         }
         if (MonthlySalary != null)
         {
             hashCode = hashCode * 59 + MonthlySalary.GetHashCode();
         }
         return(hashCode);
     }
 }
Ejemplo n.º 22
0
    private static RoleDescription readRoleDescription()
    {
        if (!File.Exists(base_datapath + text_datapath))
        {
            Debug.LogError("Obtain description failed");
            return(null);
        }

        StreamReader sr   = new StreamReader(base_datapath + text_datapath);
        string       json = sr.ReadToEnd();

        sr.Close();
        //Debug.LogError(json);
        RoleDescription role_d = new RoleDescription();

        if (json.Length > 0)
        {
            role_d = JsonUtility.FromJson <RoleDescription>(json);
        }
        return(role_d);
    }
Ejemplo n.º 23
0
        //public IList<RoleDescription> GetAvailableInstanceTypes()
        public RoleDescription [] GetAvailableInstanceTypes()
        {
            using (ManagementClient client =
                       CloudContext.Clients.CreateManagementClient(_credentials))
            {
                IList <RoleSizeListResponse.RoleSize> available = client.RoleSizes.List().RoleSizes;

                RoleDescription [] availableRoles = new RoleDescription[available.Count];

                for (int i = 0; i < available.Count; i++)
                {
                    availableRoles[i] = new RoleDescription {
                        Name       = available[i].Name,
                        Label      = available[i].Label,
                        VM         = available[i].SupportedByVirtualMachines,
                        WorkerRole = available[i].SupportedByWebWorkerRoles
                    };
                }

                return(availableRoles);
            }
        }
Ejemplo n.º 24
0
    public static string getRoleDescription(int Type)
    {
        RoleDescription role_d = readRoleDescription();

        if (role_d == null)
        {
            return("hello");
        }
        switch (Type)
        {
        case 1:
            Debug.Log("Obtain role description successfully");
            return(role_d.Lolita_d);

        case 2:
            Debug.Log("Obtain role description successfully");
            return(role_d.Genius_d);

        case 3:
            Debug.Log("Obtain role description successfully");
            return(role_d.Liver_Emperor_d);

        case 4:
            Debug.Log("Obtain role description successfully");
            return(role_d.Master_of_Sports_d);

        case 5:
            Debug.Log("Obtain role description successfully");
            return(role_d.Young_Aritst_d);

        case 6:
            Debug.Log("Obtain role description successfully");
            return(role_d.Computer_Guy_d);

            defualt : return("this");
        }
        return("mother");
    }
Ejemplo n.º 25
0
 /// <summary>
 /// Gets the hash code
 /// </summary>
 /// <returns>Hash code</returns>
 public override int GetHashCode()
 {
     unchecked // Overflow is fine, just wrap
     {
         var hashCode = 41;
         // Suitable nullity checks etc, of course :)
         if (Id != null)
         {
             hashCode = hashCode * 59 + Id.GetHashCode();
         }
         if (FullName != null)
         {
             hashCode = hashCode * 59 + FullName.GetHashCode();
         }
         if (Phone != null)
         {
             hashCode = hashCode * 59 + Phone.GetHashCode();
         }
         if (Email != null)
         {
             hashCode = hashCode * 59 + Email.GetHashCode();
         }
         if (Role != null)
         {
             hashCode = hashCode * 59 + Role.GetHashCode();
         }
         if (RoleDescription != null)
         {
             hashCode = hashCode * 59 + RoleDescription.GetHashCode();
         }
         if (Active != null)
         {
             hashCode = hashCode * 59 + Active.GetHashCode();
         }
         return(hashCode);
     }
 }
Ejemplo n.º 26
0
        private RoleDescription ConvertRole(User user, Role role, bool includeUsers)
        {
            RoleDescription desc = new RoleDescription();

            desc.AssignUnassignRole   = role.AssignUnassignRole;
            desc.CanCreateRoot        = role.CanCreateRoot;
            desc.CanManageSubRoles    = role.CanManageSubRoles;
            desc.CanCreateUsers       = role.CanCreateUsers;
            desc.DataEntityPermission = role.DataEntityPermission;
            desc.Id     = role.Id;
            desc.IsRoot = role.IsRoot;

            if (includeUsers)
            {
                foreach (Guid userId in role.Users)
                {
                    desc.Users.Add(ConvertUser(user, userId));
                }
            }

            desc.Name = ReencryptToUser(user, role.Name);

            return(desc);
        }
        // Handle hashes for everything but the managers / service owners isCertified and the
        // risk rating. The isCertified stuff gets reset everytime a new cycle happens and
        // risk rating is calculated from threat and likelihood ratings so we can ignore those
        public override int GetHashCode()
        {
            // Role stuff
            int hashRolePrivId = RolePrivId == null ? 0 : RolePrivId.GetHashCode();

            int hashRoleId           = RoleId == null ? 0 : RoleId.GetHashCode();
            int hashRoleName         = RoleName == null ? 0 : RoleName.GetHashCode();
            int hashRoleDescription  = RoleDescription == null ? 0 : RoleDescription.GetHashCode();
            int hashRoleOwner_RoleId = RoleOwner_RoleId == null ? 0 : RoleOwner_RoleId.GetHashCode();

            // Manager stuff
            int hashRoleOwner_PrivId                  = RoleOwner_PrivId == null ? 0 : RoleOwner_PrivId.GetHashCode();
            int hashRoleOwner_PermissionGroup         = RoleOwner_PermissionGroup == null ? 0 : RoleOwner_PermissionGroup.GetHashCode();
            int hashRoleOwner_ServicePrivSummary      = RoleOwner_ServicePrivSummary == null ? 0 : RoleOwner_ServicePrivSummary.GetHashCode();
            int hashRoleOwner_CredentialStorageMethod = RoleOwner_CredentialStorageMethod == null ? 0 : RoleOwner_CredentialStorageMethod.GetHashCode();
            int hashRoleOwner_ServiceId               = RoleOwner_ServiceId == null ? 0 : RoleOwner_ServiceId.GetHashCode();
            int hashRoleOwner_ServiceName             = RoleOwner_ServiceName == null ? 0 : RoleOwner_ServiceName.GetHashCode();
            int hashRoleOwner_ServiceDescription      = RoleOwner_ServiceDescription == null ? 0 : RoleOwner_ServiceDescription.GetHashCode();

            int hashRoleOwner_RoleAccessJustification = RoleOwner_RoleAccessJustification == null ? 0 : RoleOwner_RoleAccessJustification.GetHashCode();
            int hashRoleOwner_RemovalImpact           = RoleOwner_RemovalImpact == null ? 0 : RoleOwner_RemovalImpact.GetHashCode();
            int hashRoleOwner_IsRevoked     = RoleOwner_IsRevoked == null ? 0 : RoleOwner_IsRevoked.GetHashCode();
            int hashRoleOwner_DateCertified = RoleOwner_DateCertified == null ? 0 : RoleOwner_DateCertified.GetHashCode();

            // Service Owner Stuff
            int hashServiceOwner_PrivId                  = ServiceOwner_PrivId == null ? 0 : ServiceOwner_PrivId.GetHashCode();
            int hashServiceOwner_PermissionGroup         = ServiceOwner_PermissionGroup == null ? 0 : ServiceOwner_PermissionGroup.GetHashCode();
            int hashServiceOwner_ServicePrivSummary      = ServiceOwner_ServicePrivSummary == null ? 0 : ServiceOwner_ServicePrivSummary.GetHashCode();
            int hashServiceOwner_CredentialStorageMethod = ServiceOwner_CredentialStorageMethod == null ? 0 : ServiceOwner_CredentialStorageMethod.GetHashCode();
            int hashServiceOwner_ServiceId               = ServiceOwner_ServiceId == null ? 0 : ServiceOwner_ServiceId.GetHashCode();
            int hashServiceOwner_ServiceName             = ServiceOwner_ServiceName == null ? 0 : ServiceOwner_ServiceName.GetHashCode();
            int hashServiceOwner_ServiceDescription      = ServiceOwner_ServiceDescription == null ? 0 : ServiceOwner_ServiceDescription.GetHashCode();

            int hashServiceOwner_RoleAccessJustification = ServiceOwner_RoleAccessJustification == null ? 0 : ServiceOwner_RoleAccessJustification.GetHashCode();
            int hashServiceOwner_RemovalImpact           = ServiceOwner_RemovalImpact == null ? 0 : ServiceOwner_RemovalImpact.GetHashCode();
            int hashServiceOwner_IsRevoked     = ServiceOwner_IsRevoked == null ? 0 : ServiceOwner_IsRevoked.GetHashCode();
            int hashServiceOwner_DateCertified = ServiceOwner_DateCertified == null ? 0 : ServiceOwner_DateCertified.GetHashCode();


            // Risk Stuff
            int hashRiskImpact         = RiskImpact == null ? 0 : RiskImpact.GetHashCode();
            int hashRiskLikelihood     = RiskLikelihood == null ? 0 : RiskLikelihood.GetHashCode();
            int hashRiskNotes          = RiskNotes == null ? 0 : RiskNotes.GetHashCode();
            int hashRiskAssessmentDate = RiskAssessmentDate == null ? 0 : ServiceOwner_DateCertified.GetHashCode();


            // Calculate the hash code for the object.
            return // Role stuff
                   (hashRolePrivId ^
                    hashRoleId ^
                    hashRoleName ^
                    hashRoleDescription ^
                    hashRoleOwner_RoleId ^

                    // Manager stuff
                    hashRoleOwner_PrivId ^
                    hashRoleOwner_PermissionGroup ^
                    hashRoleOwner_ServicePrivSummary ^
                    hashRoleOwner_CredentialStorageMethod ^
                    hashRoleOwner_ServiceId ^
                    hashRoleOwner_ServiceName ^
                    hashRoleOwner_ServiceDescription ^

                    hashRoleOwner_RoleAccessJustification ^
                    hashRoleOwner_RemovalImpact ^
                    hashRoleOwner_IsRevoked ^
                    hashRoleOwner_DateCertified ^

                    // Service Owner Stuff
                    hashServiceOwner_PrivId ^
                    hashServiceOwner_PermissionGroup ^
                    hashServiceOwner_ServicePrivSummary ^
                    hashServiceOwner_CredentialStorageMethod ^
                    hashServiceOwner_ServiceId ^
                    hashServiceOwner_ServiceName ^
                    hashServiceOwner_ServiceDescription ^

                    hashServiceOwner_RoleAccessJustification ^
                    hashServiceOwner_RemovalImpact ^
                    hashServiceOwner_IsRevoked ^
                    hashServiceOwner_DateCertified ^

                    // Risk Stuff
                    hashRiskImpact ^
                    hashRiskLikelihood ^
                    hashRiskNotes ^
                    hashRiskAssessmentDate);
        }
Ejemplo n.º 28
0
        private void buttonCreateUser_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.treeViewRoles.SelectedNode == null ||
                    !(this.treeViewRoles.SelectedNode.Tag is RoleDescription))
                {
                    return;
                }

                if (string.IsNullOrEmpty(this.textBoxNewUserName.Text))
                {
                    MessageBox.Show("You must enter a username");
                    return;
                }
                Guid newUserId = GuidCreator.CreateGuidFromString(this.textBoxNewUserName.Text);

                if (this.masterKeypair == null && this.keyPair == null)
                {
                    MessageBox.Show("You must load your key pair first");
                    return;
                }

                string filename = FileDialogs.AskUserForFileNameToSaveIn();
                if (!string.IsNullOrEmpty(filename))
                {
                    if (!Path.HasExtension(filename))
                    {
                        filename = filename + ".xml";
                    }

                    SignKeys        userSignKeyPair = DataSigner.GenerateSignKeyPair();
                    IPreService     proxy;
                    KeyPair         userKeypair;
                    DelegationToken userDelegationToken;

                    if (this.masterKeypair != null)
                    {
                        proxy       = GetPreProxy();
                        userKeypair = proxy.GenerateKeyPair();

                        userDelegationToken = new DelegationToken();
                        proxy = GetPreProxy();
                        userDelegationToken.ToUser = proxy.GenerateDelegationKey(this.masterKeypair.Private, userKeypair.Public);
                    }
                    else
                    {
                        userKeypair         = this.keyPair; // I am not a DO, so when creating a new user then reuse my key
                        userDelegationToken = null;         // I do not know my own delegation key. The server will put it in for me.
                    }

                    proxy = GetPreProxy();
                    byte[] username = proxy.Encrypt(this.keyPair.Public, this.textBoxNewUserName.Text.GetBytes());

                    User user = new User();
                    user.DelegationToken = userDelegationToken;
                    user.Id            = newUserId;
                    user.Name          = username;
                    user.SignPublicKey = userSignKeyPair.PublicOnly;


                    RoleDescription role         = (RoleDescription)this.treeViewRoles.SelectedNode.Tag;
                    IGatewayService gateWayproxy = GetServiceProxy();
                    gateWayproxy.CreateUser(this.myId, role.Id, user);


                    KeyCollection uk = new KeyCollection();
                    uk.PublicKey  = Convert.ToBase64String(this.keyPair.Public); // use original DO public key
                    uk.PrivateKey = Convert.ToBase64String(userKeypair.Private);
                    uk.SignKeys   = Convert.ToBase64String(userSignKeyPair.PublicAndPrivate);

                    XmlFile.WriteFile(uk, filename);

                    buttonRefreshRolesAndUsers_Click(this, EventArgs.Empty);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: " + ex.Message);
                Logger.LogError("Error generating user keypair", ex);
            }
        }
Ejemplo n.º 29
0
 public static Role Create(int roleId, RoleName roleName, RoleDescription roleDescription, bool isActive)
 {
     return(new Role {
         Id = roleId, RoleName = roleName, RoleDescription = roleDescription, IsActive = isActive
     });
 }