Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/09/10 17:19:19 (14 years ago)
Author:
bfarka
Message:

last bugfixes for project #1046

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  
    153153      using (DataClassesDataContext db = DatabaseUtil.createDataClassesDataContext()) {
    154154        // check database connection
    155         if (db == null) {
    156           return false;
    157         }
    158 
     155       
    159156        if (newPassword.Length < MinRequiredPasswordLength) {
    160157          return false;
    161158        }
    162 
    163         try {
    164           // try to get user
     159        if (db.HeuristicLabUsers.Count(x => x.UserName == username) > 0) {
    165160          HeuristicLabUser u = db.HeuristicLabUsers.Single(x => x.UserName == username);
    166161
     
    171166          }
    172167          return false;
    173 
    174 
    175         }
    176         catch (Exception) {
    177           return false;
    178         }
     168        } else {
     169          return false;
     170        }
     171
     172       
    179173      }
    180174    }
  • branches/HeuristicLab.Services.Authentication Prototype/Service/Provider/HeuristicLabRoleProvider.cs

    r4000 r4024  
    99  class HeuristicLabRoleProvider : RoleProvider {
    1010    protected string applicationName;
     11
     12
     13
    1114
    1215    public override void AddUsersToRoles(string[] usernames, string[] roleNames) {
     
    8588      Persistence.DataClassesDataContext db = DatabaseUtil.createDataClassesDataContext();
    8689      if (roleName != null && db.HeuristicLabRole.Count(r => r.RoleName == roleName) == 1) {
     90       
    8791        HeuristicLabRole role = db.HeuristicLabRole.Single(r => r.RoleName == roleName);
     92     
    8893        foreach (HeuristicLabUserRole userRole in role.HeuristicLabUserRoles) {
    8994          if (userRole.HeuristicLabUser.UserName.Contains(usernameToMatch)) {
     
    121126      context.Dispose();
    122127      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   
    123143    }
    124144
     
    142162      DataClassesDataContext context = DatabaseUtil.createDataClassesDataContext();
    143163      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
    145179      }
    146180      context.Dispose();
    147181      return returnValue;
    148182    }
    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    }
    150197    public override void RemoveUsersFromRoles(string[] usernames, string[] roleNames) {
    151198
Note: See TracChangeset for help on using the changeset viewer.