- Timestamp:
- 07/09/10 17:19:19 (14 years ago)
- Location:
- branches/HeuristicLab.Services.Authentication Prototype/Service/Provider
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Services.Authentication Prototype/Service/Provider/HeuristicLabMembershipProvider.cs
r4019 r4024 153 153 using (DataClassesDataContext db = DatabaseUtil.createDataClassesDataContext()) { 154 154 // check database connection 155 if (db == null) { 156 return false; 157 } 158 155 159 156 if (newPassword.Length < MinRequiredPasswordLength) { 160 157 return false; 161 158 } 162 163 try { 164 // try to get user 159 if (db.HeuristicLabUsers.Count(x => x.UserName == username) > 0) { 165 160 HeuristicLabUser u = db.HeuristicLabUsers.Single(x => x.UserName == username); 166 161 … … 171 166 } 172 167 return false; 173 174 175 } 176 catch (Exception) { 177 return false; 178 } 168 } else { 169 return false; 170 } 171 172 179 173 } 180 174 } -
branches/HeuristicLab.Services.Authentication Prototype/Service/Provider/HeuristicLabRoleProvider.cs
r4000 r4024 9 9 class HeuristicLabRoleProvider : RoleProvider { 10 10 protected string applicationName; 11 12 13 11 14 12 15 public override void AddUsersToRoles(string[] usernames, string[] roleNames) { … … 85 88 Persistence.DataClassesDataContext db = DatabaseUtil.createDataClassesDataContext(); 86 89 if (roleName != null && db.HeuristicLabRole.Count(r => r.RoleName == roleName) == 1) { 90 87 91 HeuristicLabRole role = db.HeuristicLabRole.Single(r => r.RoleName == roleName); 92 88 93 foreach (HeuristicLabUserRole userRole in role.HeuristicLabUserRoles) { 89 94 if (userRole.HeuristicLabUser.UserName.Contains(usernameToMatch)) { … … 121 126 context.Dispose(); 122 127 return roleList.ToArray(); 128 } 129 130 public virtual void AddChildRole(string parentRoleName, string childRoleName) { 131 using (DataClassesDataContext db = DatabaseUtil.createDataClassesDataContext()) { 132 133 if (db.HeuristicLabRole.Count(x => x.RoleName == parentRoleName) > 0 && db.HeuristicLabRole.Count(x => x.RoleName == childRoleName) > 0) { 134 135 HeuristicLabRole parentRole = db.HeuristicLabRole.Single(x => x.RoleName == parentRoleName); 136 HeuristicLabRole childRole = db.HeuristicLabRole.Single(x => x.RoleName == childRoleName); 137 childRole.ParentRoleID = parentRole.ID; 138 parentRole.HeuristicLabRoleChilds.Add(childRole); 139 db.SubmitChanges(); 140 } 141 } 142 123 143 } 124 144 … … 142 162 DataClassesDataContext context = DatabaseUtil.createDataClassesDataContext(); 143 163 if (username != null && roleName != null) { 144 returnValue = (context.HeuristicLabUserRole.Count(ur => ur.HeuristicLabRole.RoleName == roleName && ur.HeuristicLabUser.UserName == username) > 0); 164 165 Persistence.HeuristicLabUser user = context.HeuristicLabUsers.Single(x => x.UserName == username); 166 foreach (Persistence.HeuristicLabUserRole ur in user.HeuristicLabUserRoles) { 167 if (ur.HeuristicLabRole.RoleName.Equals(roleName)) { 168 return true; 169 } else { 170 List<HeuristicLabRole> tmpList = ur.HeuristicLabRole.HeuristicLabRoleChilds.ToList<HeuristicLabRole>(); 171 if (ResolveChildRoles(tmpList, roleName)) { 172 return true; 173 } 174 } 175 } 176 177 178 145 179 } 146 180 context.Dispose(); 147 181 return returnValue; 148 182 } 149 183 protected bool ResolveChildRoles(List<HeuristicLabRole> roles, string roleName) 184 { 185 bool returnValue = false; 186 foreach (HeuristicLabRole r in roles) { 187 if (r.RoleName.Equals(roleName)) { 188 return true; 189 } else { 190 if (ResolveChildRoles(r.HeuristicLabRoleChilds.ToList<HeuristicLabRole>(), roleName)) { 191 return true; 192 } 193 } 194 } 195 return returnValue; 196 } 150 197 public override void RemoveUsersFromRoles(string[] usernames, string[] roleNames) { 151 198
Note: See TracChangeset
for help on using the changeset viewer.