Reputation: 41
How to give the LDAP account the default role, now the LDAP account login default role is admin
Integrated LDAP login in the abp framework
public async override Task<User> CreateUserAsync(string userNameOrEmailAddress, Tenant tenant)
{
await CheckIsEnabled(tenant);
var user = await base.CreateUserAsync(userNameOrEmailAddress, tenant);
using (var principalContext = await CreatePrincipalContext(tenant))
{
var userPrincipal = UserPrincipal.FindByIdentity(principalContext, userNameOrEmailAddress);
if (userPrincipal == null)
{
throw new AbpException("Unknown LDAP user: " + userNameOrEmailAddress);
}
UpdateUserFromPrincipal(user, userPrincipal);
user.IsEmailConfirmed = true;
user.IsActive = true;
return user;
}
}
Upvotes: 4
Views: 283
Reputation: 69
user have AddRole method. you need to pass the roleId to that method.
// create roles
var role = new IdentityRole(
id: GuidGenerator.Create(),
name: item.Role,
tenantId: CurrentTenant.Id)
{
IsDefault = false,
IsPublic = true
};
user.AddRole(role.Id);
Upvotes: 0