Created
March 9, 2018 04:48
-
-
Save Sam7/e9bf2c2ed23d2caf370423d68035b3c9 to your computer and use it in GitHub Desktop.
UmbracoCustomOwinStartup.AddGroups.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static void AddGroups(BackOfficeIdentityUser autoLinkUser, IEnumerable<string> groupsToAdd, Dictionary<string, Claim> adGroupNames) | |
{ | |
// add new groups | |
foreach (var adGroup in groupsToAdd.Where(s => !string.IsNullOrWhiteSpace(s))) | |
{ | |
var userService = UmbracoContext.Current.Application.Services.UserService; | |
var userGroup = userService.GetUserGroupByAlias(adGroup); | |
if (userGroup == null) | |
{ | |
// Create new Group without permissions. They have to be | |
userGroup = new UserGroup { Alias = adGroup, Name = GroupLabelPrefix + adGroupNames[adGroup].Value }; | |
userService.Save(userGroup); | |
} | |
autoLinkUser.AddRole(userGroup.Alias); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment