public virtual UserEntity?AutoCreateUserInternal(IAutoCreateUserContext ctx) { var result = new UserEntity { UserName = ctx.UserName, PasswordHash = null, Email = ctx.EmailAddress, Role = GetRole(ctx, throwIfNull: true) !, State = UserState.Active, }; UpdateUserInternal(result, ctx); return(result); }
public virtual void UpdateUser(UserEntity user, IAutoCreateUserContext ctx) { if (this.GetConfig().AutoUpdateUsers == false) { return; } UpdateUserInternal(user, ctx); if (GraphExplorer.IsGraphModified(user)) { using (AuthLogic.Disable()) using (OperationLogic.AllowSave <UserEntity>()) { user.Save(); } } }
public virtual Lite <RoleEntity>?GetRole(IAutoCreateUserContext ctx, bool throwIfNull) { var config = GetConfig(); if (ctx is DirectoryServiceAutoCreateUserContext ds) { var groups = ds.GetUserPrincipal().GetGroups(); var role = config.RoleMapping.FirstOrDefault(m => { Guid.TryParse(m.ADNameOrGuid, out var guid); return(groups.Any(g => g.Name == m.ADNameOrGuid || g.Guid == guid)); })?.Role ?? config.DefaultRole; if (role != null) { return(role); } if (throwIfNull) { throw new InvalidOperationException("No Default Role set and no matching RoleMapping found for any role: \r\n" + groups.ToString(a => a.Name, "\r\n")); } else { return(null); } } else { if (config.DefaultRole != null) { return(config.DefaultRole); } if (throwIfNull) { throw new InvalidOperationException("No default role set"); } else { return(null); } } }
public virtual UserEntity?AutoCreateUserInternal(IAutoCreateUserContext ctx) { var result = new UserEntity { UserName = ctx.UserName, PasswordHash = null, Email = ctx.EmailAddress, Role = GetRole(ctx, throwIfNull: true) !, State = UserState.Saved, }; var mixin = result.TryMixin <UserOIDMixin>(); if (mixin != null) { mixin.OID = ctx.OID; } return(result); }
public virtual UserEntity?OnAutoCreateUser(IAutoCreateUserContext ctx) { if (!GetConfig().AutoCreateUsers) { return(null); } var user = this.AutoCreateUserInternal(ctx); if (user != null && user.IsNew) { using (ExecutionMode.Global()) using (OperationLogic.AllowSave <UserEntity>()) { user.Save(); } } return(user); }
public virtual void UpdateUserInternal(UserEntity user, IAutoCreateUserContext ctx) { if (ctx.OID != null) { user.Mixin <UserADMixin>().OID = ctx.OID; if (!UserADMixin.AllowPasswordForActiveDirectoryUsers) { user.PasswordHash = null; } } if (ctx.SID != null) { user.Mixin <UserADMixin>().SID = ctx.SID; if (!UserADMixin.AllowPasswordForActiveDirectoryUsers) { user.PasswordHash = null; } } user.UserName = ctx.UserName; user.Email = ctx.EmailAddress; }
public override void UpdateUserInternal(UserEntity user, IAutoCreateUserContext ctx) { base.UpdateUserInternal(user, ctx); //user.Mixin<UserADMixin>().FirstName = ctx.FirstName; }