public Task <bool> RemoveUserFromAllGroupsAsync(string UserId) { using (var ug = new UserGroupsFactory()) { ug.ClearGroups(UserId); }; return(Task.FromResult(true)); }
public Task <bool> RemoveUserFromGroupAsync(string UserId, string GroupName) { using (var ug = new UserGroupsFactory()) { ug.RemoveUserFromGroup(UserId, GroupName); }; return(Task.FromResult(true)); }
internal static bool CheckAccess(string usrName, string accessRule) { bool granted = false; using (var ur = new UserGroupsFactory()) { granted = ur.CheckAccess(usrName, accessRule); } return(granted); }
public Task <bool> AddUserToGroupsAsync(string UserId, string[] GroupNames) { using (var ug = new UserGroupsFactory()) { foreach (var item in GroupNames) { ug.AddUserToGroup(UserId, item); } }; return(Task.FromResult(true)); }
public static bool AddToGroup(this ClaimsPrincipal usr, string groupName) { if (!usr.Identity.IsAuthenticated) { return(false); } using (var ug = new UserGroupsFactory()) { ug.AddUserToGroup(usr.Identity.Name, groupName); }; return(true); }
public static bool IsInGroup(this ClaimsPrincipal usr, string groupName) { if (!usr.Identity.IsAuthenticated) { return(false); } bool?f = false; using (var ug = new UserGroupsFactory()) { f = ug.GetUserGroups(usr.Identity.Name)?.Contains(groupName); }; return(f ?? false); }
internal static void SetDefaults(FreshlyOptions D) { var AG = new ApplicationGroupsFactory(); var AP = new ApplicationPoliciesFactory(); var UG = new UserGroupsFactory(); var GP = new GroupPoliciesFactory(); var AU = new UserHelpers(); var gs = D?.Groups; var ps = D?.Policies; var AdminGroup = "Administrator"; (new DatabaseInitializer()).SetupDB(); try { AG.AddGroup(AdminGroup); } catch (Exception ex) { }; try { if (D?.DefaultUser != null) { D.DefaultUser.CurrentStatus = AccountStatus.Active; AU.CreateUser(D.DefaultUser, D.DefaultUser.Password); UG.AddUserToGroup(D.DefaultUser.UserId, AdminGroup); } } catch (Exception ex) { } try { if (gs != null) { foreach (var s in gs) { if (!string.IsNullOrEmpty(s)) { AG.AddGroup(s); } } } } catch (Exception ex) { } try { if (ps != null) { foreach (var s in ps) { if (!string.IsNullOrEmpty(s)) { AP.AddAccessPolicy(s); GP.AddGroupPolicy(AdminGroup, s); } } } } catch (Exception ex) { } try { if (!string.IsNullOrEmpty(D?.DefaultUser.Groups)) { var ug = D?.DefaultUser?.Groups.Split(','); var un = D?.DefaultUser.UserId; foreach (var g in ug) { UG.AddUserToGroup(un, g); } } } catch (Exception ex) { } try { //Create policies for all the access Policies LstPolicy = AP.GetApplicationPolicies(); } catch (Exception ex) { } AP.Dispose(); AG.Dispose(); AU.Dispose(); GP.Dispose(); UG.Dispose(); //AuthB.Services.AddDataProtection() // .PersistKeysToFileSystem(new DirectoryInfo(@"")) // .ProtectKeysWithCertificate("thumbnail") // .SetApplicationName("Freshly"); }