public override async Task <IdentityUser> FindByNameAsync(string userName) { LDAPUserData userData = LDAPUserAccessor.GetUserData(userName); if (userData == null) { return(null); } var dbUser = await base.FindByNameAsync(userName); if (dbUser != null) { return(dbUser); } if (_isUserCreating) { return(null); } dbUser = new IdentityUser(userName) { UserName = userName }; _isUserCreating = true; await this.CreateAsync(dbUser); _isUserCreating = false; return(dbUser); }
public LDAPUserData GetUserData(string username) { using (var context = ContextFactory.Create()) { UserPrincipal userPrincipal = new UserPrincipal(context); userPrincipal.SamAccountName = username; PrincipalSearcher searcher = new PrincipalSearcher(userPrincipal); var principal = (UserPrincipal)searcher.FindOne(); if (principal == null) { return(null); } LDAPUserData model = new LDAPUserData(); model.DisplayName = principal.DisplayName; model.Name = principal.Name + " " + principal.MiddleName; model.Surname = principal.Surname; model.GivenName = principal.GivenName; model.Mail = principal.EmailAddress; return(model); } }