Exemplo n.º 1
0
        public static bool IsRole(IdentityUserRole userRole, RoleId roleId)
        {
            if (userRole.RoleId == null)
                return false;

            var currRole = (RoleId) Enum.Parse(typeof(RoleId), userRole.RoleId);

            if (currRole == roleId)
                return true;

            return true;
        }
Exemplo n.º 2
0
        public static RoleLists GetMSNList(RoleId memberRole)
        {
            switch (memberRole)
            {
            case RoleId.Allow:
                return(RoleLists.Allow);

            case RoleId.Pending:
                return(RoleLists.Pending);

            case RoleId.Hide:
                return(RoleLists.Hide);
            }
            return(RoleLists.None);
        }
Exemplo n.º 3
0
 //当使用Authorize特性时,会调用改方法验证角色
 public virtual bool IsInRole(string role)
 {
     try
     {
         if (string.IsNullOrWhiteSpace(role))
         {
             return(true);
         }
         return(RoleId.Contains(Guid.Parse(role)));
     }
     catch (Exception)
     {
         return(true);
     }
 }
Exemplo n.º 4
0
 public async Task <IEnumerable <PermissionOverrideDto> > HandleAsync(GetChannelRolePermissionOverridesQuery query)
 {
     return(await _context.Channels
            .AsNoTracking()
            .Where(x => x.GroupId == GroupId.From(query.GroupId))
            .Where(x => x.Id == ChannelId.From(query.ChannelId))
            .SelectMany(x => x.RolePermissionOverrides)
            .Where(x => x.RoleId == RoleId.From(query.RoleId))
            .Select(
                x => new PermissionOverrideDto
     {
         Permission = x.Permission.Name,
         Type = x.Type == OverrideType.Allow ? OverrideTypeDto.Allow : OverrideTypeDto.Deny
     }
                ).ToListAsync());
 }
Exemplo n.º 5
0
        public static bool IsRole(IdentityUserRole userRole, RoleId roleId)
        {
            if (userRole.RoleId == null)
            {
                return(false);
            }

            var currRole = (RoleId)Enum.Parse(typeof(RoleId), userRole.RoleId);

            if (currRole == roleId)
            {
                return(true);
            }

            return(true);
        }
Exemplo n.º 6
0
        public bool Equals(RoleModulePermissionModel rmpm)
        {
            //Check whether the compared object is null.
            if (Object.ReferenceEquals(rmpm, null))
            {
                return(false);
            }

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

            //Check whether the objects properties are equal.
            return(RoleId.Equals(rmpm.RoleId) && ModuleId.Equals(rmpm.ModuleId) && PermissionId.Equals(rmpm.PermissionId));
        }
Exemplo n.º 7
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (RoleId != 0L)
            {
                hash ^= RoleId.GetHashCode();
            }
            if (Name.Length != 0)
            {
                hash ^= Name.GetHashCode();
            }
            if (UserId != 0L)
            {
                hash ^= UserId.GetHashCode();
            }
            if (ServerId != 0)
            {
                hash ^= ServerId.GetHashCode();
            }
            if (ServerName.Length != 0)
            {
                hash ^= ServerName.GetHashCode();
            }
            if (Type != 0)
            {
                hash ^= Type.GetHashCode();
            }
            if (Level != 0)
            {
                hash ^= Level.GetHashCode();
            }
            if (Sex != 0)
            {
                hash ^= Sex.GetHashCode();
            }
            if (HeadImgId != 0)
            {
                hash ^= HeadImgId.GetHashCode();
            }
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
Exemplo n.º 8
0
        public void DeleteRole(UserId responsibleUserId, RoleId roleId)
        {
            _unitOfWork.WithAuthUserTransaction(tran => {
                var role = FindRole(roleId);
                long nrOfUsersWithRole = _authUserRepository.Count(new UsersWithRoleSpecification(roleId));
                if (nrOfUsersWithRole > 0)
                {
                    throw new ManualValidationException("You cannot delete roles with users assigned.");
                }

                _roleRepository.Delete(roleId);

                _unitOfWork.Raise(RoleDeleted.Factory(role, responsibleUserId));

                tran.Commit();
            });
        }
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = (VaultUri != null ? VaultUri.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (int)AuthenticationType;
         hashCode = (hashCode * 397) ^ (RoleId != null ? RoleId.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (SecretId != null ? SecretId.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (Username != null ? Username.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (Password != null ? Password.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (Token != null ? Token.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (int)SecretsEngine;
         hashCode = (hashCode * 397) ^ (SecretsEnginePath != null ? SecretsEnginePath.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (DataPath != null ? DataPath.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (Namespace != null ? Namespace.GetHashCode() : 0);
         return(hashCode);
     }
 }
Exemplo n.º 10
0
        public void RemoveRole(UserId responsibleUserId, RoleId roleId, UserId userId)
        {
            _unitOfWork.WithAuthUserTransaction(tran => {
                var role     = FindRole(roleId);
                var authUser = _authUserRepository.FindByIdOrNull(userId);
                if (authUser is null)
                {
                    throw new ManualValidationException("User not found");
                }

                _userRoleDomainService.RemoveRole(authUser, role);
                _authUserRepository.Save(authUser);

                _unitOfWork.Raise(UserLostRole.Factory(role, authUser, responsibleUserId));

                tran.Commit();
            });
        }
Exemplo n.º 11
0
        public void AssignRole(UserId responsibleUserId, RoleId roleId, Username username)
        {
            _unitOfWork.WithAuthUserTransaction(tran => {
                var role     = FindRole(roleId);
                var authUser = _authUserRepository.FindOrNull(new UsernameSpecification(username));
                if (authUser is null)
                {
                    throw new ManualValidationException("User not found");
                }

                _userRoleDomainService.AssignRole(authUser, role);
                _authUserRepository.Save(authUser);

                _unitOfWork.Raise(UserGainedRole.Factory(role, authUser, responsibleUserId));

                tran.Commit();
            });
        }
Exemplo n.º 12
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (RoleId != 0)
            {
                hash ^= RoleId.GetHashCode();
            }
            if (PitchOn != false)
            {
                hash ^= PitchOn.GetHashCode();
            }
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
Exemplo n.º 13
0
        public async Task <IEnumerable <PermissionDto> > HandleAsync(GetRolePermissionsQuery query)
        {
            var permissions = await _context.Groups.AsNoTracking()
                              .Where(x => x.Id == GroupId.From(query.GroupId))
                              .SelectMany(x => x.Roles)
                              .Where(x => x.Id == RoleId.From(query.RoleId))
                              .Select(x => x.Permissions)
                              .ToListAsync();

            if (permissions.Count == 0)
            {
                return(new List <PermissionDto>());
            }
            var permission = permissions[0];

            return(permission.ToListOfPermissions()
                   .Select(x => new PermissionDto(x.Name, x.Value))
                   .ToList());
        }
Exemplo n.º 14
0
        /// <summary>
        /// Gets the hash code
        /// </summary>
        /// <returns>Hash code</returns>
        public override int GetHashCode()
        {
            // credit: http://stackoverflow.com/a/263416/677735
            unchecked // Overflow is fine, just wrap
            {
                int hash = 41;

                // Suitable nullity checks
                hash = hash * 59 + RoleId.GetHashCode();
                hash = hash * 59 + PermissionId.GetHashCode();

                if (Id != null)
                {
                    hash = hash * 59 + Id.GetHashCode();
                }

                return(hash);
            }
        }
Exemplo n.º 15
0
        private void LoadData()
        {
            LoadComboBox();

            // Verificar si el usuario tiene permisos asignados
            OperationResult objSecurityOperationResult1 = new OperationResult();

            if (Mode == "New")
            {
                hfMode.Text = "New";
            }
            else if (Mode == "Edit")
            {
                ddlRole.SelectedValue = RoleId.ToString();
                ddlRole.Enabled       = false;

                var filterExpression = string.Format("i_NodeId=={0}&&i_RoleId=={1}&&i_IsDeleted==0", NodeId, RoleId);
                int count1           = _objNodeBL.GetRoleNodeProfileCount(ref objSecurityOperationResult1, filterExpression);

                if (count1 == 0)
                {
                    // Additional logic here.
                    hfMode.Text = "New";
                }
                else
                {
                    hfMode.Text = "Edit";
                    // Cargar permisos Globales
                    OperationResult objCommonOperationResultGlobal = new OperationResult();
                    var             objRoleNodeProfile             = _objNodeBL.GetRoleNodeProfile(ref objCommonOperationResultGlobal, NodeId, RoleId);

                    if (objRoleNodeProfile != null)
                    {
                        // Marcar (CkeckBox) los permisos en el Tree Contextual
                        foreach (var item in objRoleNodeProfile)
                        {
                            SearchNode(tvContextPermissions.Nodes, int.Parse(item.Id), true);
                        }
                    }
                }
            }
        }
Exemplo n.º 16
0
        public async Task <ClaimsIdentity> GenerateUserIdentityAsync(UserManager <ApplicationUser> manager)
        {
            // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
            var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);

            // Add custom user claims here
            userIdentity.AddClaim(new Claim(ClaimTypeCustomize.UserRole, RoleId.ToString()));
            userIdentity.AddClaim(new Claim(ClaimTypeCustomize.RoleName, RoleName ?? ""));
            userIdentity.AddClaim(new Claim(ClaimTypeCustomize.LastLoginDate, LastLoginDate != null ? LastLoginDate.ToString() : ""));
            userIdentity.AddClaim(new Claim(ClaimTypeCustomize.Email, Email != null ? Email.ToString() : ""));
            userIdentity.AddClaim(new Claim(ClaimTypeCustomize.LastName, LastName ?? ""));
            userIdentity.AddClaim(new Claim(ClaimTypeCustomize.FirstName, FirstName ?? ""));
            userIdentity.AddClaim(new Claim(ClaimTypeCustomize.FullName, FullName ?? ""));
            userIdentity.AddClaim(new Claim(ClaimTypeCustomize.InstitutionId, InstitutionId.ToString()));
            userIdentity.AddClaim(new Claim(ClaimTypeCustomize.InstitutionName, InstitutionName ?? ""));
            userIdentity.AddClaim(new Claim(ClaimTypeCustomize.DeptCode, DeptCode ?? ""));
            userIdentity.AddClaim(new Claim(ClaimTypeCustomize.DeptName, DeptName ?? ""));
            userIdentity.AddClaim(new Claim(ClaimTypeCustomize.AppKey, AppKey ?? ""));
            return(userIdentity);
        }
Exemplo n.º 17
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);
     }
 }
Exemplo n.º 18
0
        /// <summary>
        /// Returns true if Authorization instances are equal
        /// </summary>
        /// <param name="other">Instance of Authorization to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(Authorization other)
        {
            if (ReferenceEquals(null, other))
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                ((
                     Id == other.Id ||
                     Id != null &&
                     Id.Equals(other.Id)
                     ) &&
                 (
                     ResourceId == other.ResourceId ||
                     ResourceId != null &&
                     ResourceId.Equals(other.ResourceId)
                 ) &&
                 (
                     RoleId == other.RoleId ||
                     RoleId != null &&
                     RoleId.Equals(other.RoleId)
                 ) &&
                 (
                     PolicyId == other.PolicyId ||
                     PolicyId != null &&
                     PolicyId.Equals(other.PolicyId)
                 ) &&
                 (
                     ScopeMap == other.ScopeMap ||
                     ScopeMap != null &&
                     ScopeMap.Equals(other.ScopeMap)
                 ));
        }
Exemplo n.º 19
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (Id != 0)
            {
                hash ^= Id.GetHashCode();
            }
            if (Content.Length != 0)
            {
                hash ^= Content.GetHashCode();
            }
            if (RoleId != 0)
            {
                hash ^= RoleId.GetHashCode();
            }
            hash ^= select_.GetHashCode();
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
Exemplo n.º 20
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (RoleId != 0)
            {
                hash ^= RoleId.GetHashCode();
            }
            if (PitchOn != false)
            {
                hash ^= PitchOn.GetHashCode();
            }
            hash ^= choiceId_.GetHashCode();
            if (ChoiceList.Length != 0)
            {
                hash ^= ChoiceList.GetHashCode();
            }
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
Exemplo n.º 21
0
        public int CompareTo(UserBO other)
        {
            if (ReferenceEquals(this, other))
            {
                return(0);
            }
            if (ReferenceEquals(null, other))
            {
                return(1);
            }
            var idComparison = Id.CompareTo(other.Id);

            if (idComparison != 0)
            {
                return(idComparison);
            }
            var usernameComparison = string.Compare(Username, other.Username, StringComparison.Ordinal);

            if (usernameComparison != 0)
            {
                return(usernameComparison);
            }
            var passwordComparison = string.Compare(Password, other.Password, StringComparison.Ordinal);

            if (passwordComparison != 0)
            {
                return(passwordComparison);
            }
            var roleIdComparison = RoleId.CompareTo(other.RoleId);

            if (roleIdComparison != 0)
            {
                return(roleIdComparison);
            }
            return(Comparer <RoleBO> .Default.Compare(Role, other.Role));
        }
Exemplo n.º 22
0
 void When(AddedRole @event)
 {
     Id = new RoleId(@event.RoleId);
       _permissions = new List<RolePermission>();
       _archived = false;
 }
Exemplo n.º 23
0
 protected bool Equals(DUserRole other)
 {
     return(UserId.Equals(other.UserId) && RoleId.Equals(other.RoleId));
 }
Exemplo n.º 24
0
 public override string ToString()
 {
     return
         ($"RiftTempRole: {nameof(UserId)}: {UserId.ToString()}, {nameof(RoleId)}: {RoleId.ToString()}, {nameof(ExpirationTime)}: {ExpirationTime.Humanize()}");
 }
Exemplo n.º 25
0
 public override int GetHashCode()
 {
     return(UserId.GetHashCode() * 37 + RoleId.GetHashCode());
 }
Exemplo n.º 26
0
 public AuthFilter(RoleId role = RoleId.User)
 {
     this.role = role;
 }
Exemplo n.º 27
0
 public static string MapRoleName(RoleId role)
 {
     AP1Entities e = new AP1Entities();
     RoleMapper result = e.Roles.Where(r => r.CategoryId == role.Category &&
                                            r.BandaraId == role.Bandara &&
                                            r.TerminalId == role.Terminal &&
                                            r.SubTerminalId == role.SubTerminal &&
                                            r.Role == role.Role).FirstOrDefault();
     if (result == null) return GUEST;
     return result.Name;
 }
 public void GivenIHaveVisitorRole()
 {
     _roleId = new RoleId("visitor");
 }
Exemplo n.º 29
0
 public override int GetHashCode()
 {
     return((ActivityId.ToString() + "|" + RoleId.ToString()).GetHashCode());
 }
Exemplo n.º 30
0
 public static string GetRoleName(RoleId roleId)
 {
     return(Enum.GetName(typeof(RoleId), roleId));
 }
Exemplo n.º 31
0
 public static string GetRoleId(RoleId roleid)
 {
     var roleAsInt = (int) roleid;
     var roleIdStr = roleAsInt.ToString("D");
     return roleIdStr;
 }
Exemplo n.º 32
0
 internal void RemoveMemberhip(ServiceName servicetype, string account, IMAddressInfoType type, RoleId memberrole)
 {
     lock (SyncObject)
     {
         SerializableDictionary<RoleId, SerializableDictionary<string, BaseMember>> ms = SelectTargetMemberships(servicetype);
         if (ms != null && ms.ContainsKey(memberrole))
         {
             string hash = Contact.MakeHash(account, type);
             if (ms[memberrole].ContainsKey(hash))
             {
                 ms[memberrole].Remove(hash);
             }
         }
     }
 }
Exemplo n.º 33
0
 public static string GetRoleName(RoleId roleId)
 {
     return Enum.GetName(typeof(RoleId), roleId);
 }
Exemplo n.º 34
0
        internal void SetFriendshipStatus(RoleId fs, bool fireEvent)
        {
            if (friendshipStatus != fs)
            {
                RoleId oldFs = friendshipStatus;
                friendshipStatus = fs;

                if (fireEvent)
                {
                    OnFriendshipStatusChanged(new FriendshipStatusChangedEventArgs(this, oldFs, fs));
                }
            }
        }
Exemplo n.º 35
0
 // Behavior
 public Role(RoleId roleId, Name name)
     : this()
 {
     Apply(
     new AddedRole(roleId, name));
 }
Exemplo n.º 36
0
        public virtual void Validate(ValidationResult result)
        {
            RoleId.ValidateRequired(result, nameof(RoleId));

            UserId.ValidateRequired(result, nameof(UserId));
        }
Exemplo n.º 37
0
 private bool HasMemberhip(ServiceName servicetype, string account, IMAddressInfoType type, RoleId memberrole)
 {
     SerializableDictionary<RoleId, SerializableDictionary<string, BaseMember>> ms = SelectTargetMemberships(servicetype);
     return (ms != null) && ms.ContainsKey(memberrole) && ms[memberrole].ContainsKey(Contact.MakeHash(account, type));
 }
Exemplo n.º 38
0
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="RoleId">角色ID</param>
        /// <returns></returns>
        public bool Delete(int CompanyId, params int[] RoleId)
        {
            dcDal = new EyouSoft.Data.EyouSoftTBL(this._db.ConnectionString);

            bool IsTrue = false;
            IEnumerable <EyouSoft.Data.SysRoleManage> SysRoleLists = (from item in dcDal.SysRoleManage
                                                                      where item.CompanyId == CompanyId && RoleId.Contains(item.Id)
                                                                      select item);

            dcDal.SysRoleManage.DeleteAllOnSubmit <EyouSoft.Data.SysRoleManage>(SysRoleLists);
            dcDal.SubmitChanges();
            IsTrue       = true;
            SysRoleLists = null;

            return(IsTrue);
        }
Exemplo n.º 39
0
 /// <summary>
 /// Get a basemember from membership list.
 /// </summary>
 /// <param name="servicetype"></param>
 /// <param name="account"></param>
 /// <param name="type"></param>
 /// <param name="memberrole"></param>
 /// <returns>If the member not exist, return null.</returns>
 public BaseMember SelectBaseMember(ServiceName servicetype, string account, IMAddressInfoType type, RoleId memberrole)
 {
     SerializableDictionary<RoleId, SerializableDictionary<string, BaseMember>> ms = SelectTargetMemberships(servicetype);
     if ((ms != null) && ms.ContainsKey(memberrole))
     {
         string hash = Contact.MakeHash(account, type);
         if (ms[memberrole].ContainsKey(hash))
             return ms[memberrole][hash];
     }
     return null;
 }
 public void GivenIHaveSysAdminRole()
 {
     _roleId = new RoleId("sysadmin");
 }
Exemplo n.º 41
0
        /// <summary>
        /// Add a member to the underlying membership data structure.
        /// </summary>
        /// <param name="servicetype"></param>
        /// <param name="account"></param>
        /// <param name="type"></param>
        /// <param name="memberrole"></param>
        /// <param name="member"></param>
        internal void AddMemberhip(ServiceName servicetype, string account, IMAddressInfoType type, RoleId memberrole, BaseMember member)
        {
            lock (SyncObject)
            {
                SerializableDictionary<RoleId, SerializableDictionary<string, BaseMember>> ms = SelectTargetMemberships(servicetype);
                if (ms != null)
                {
                    if (!ms.ContainsKey(memberrole))
                        ms.Add(memberrole, new SerializableDictionary<string, BaseMember>(0));

                    ms[memberrole][Contact.MakeHash(account, type)] = member;
                }
            }
        }