GridLab Persona Data Seed Module - Skills Guide¶
Skill Type: Development & Testing
Technology Stack: .NET, ABP Framework, Identity Management
Complexity Level: Beginner
Last Updated: 2024
📋 Overview¶
The Persona Data Seed Module provides predefined test users with role-based access for development and testing environments, replacing ABP's default IdentityDataSeedContributor with a comprehensive set of personas.
Key Capabilities¶
- ✅ Pre-configured test users with different roles
- ✅ Automatic user seeding on application startup
- ✅ Role-based access control (RBAC) testing
- ✅ Consistent test data across environments
- ✅ Password-protected accounts
Default Personas¶
The module automatically seeds the following users:
| Persona Name | Username | Password | Role | Use Case |
|---|---|---|---|---|
| Platform Admin | platon | 1q2w3E* | Platform Administrator | Full system access, platform configuration |
| IT Admin | adrian | Admin1234+ | IT Administrator | Infrastructure management, user management |
| Model Admin | madisson | Model1234+ | Model Administrator | Data model configuration, schema management |
| Data Provider | priscilla | Provider1234+ | Data Provider | Data input, content creation |
| Data User | dustin | Data1234+ | Data Consumer | Read-only data access, reporting |
| User | polly | User1234+ | Standard User | Basic application access |
Prerequisites¶
- .NET 9.0 or higher
- ABP Identity module
- NuGet package manager
🚀 Quick Start¶
Step 1: Install NuGet Package¶
Install the GridLab.Abp.Persona package from NuGet:
Install-Package GridLab.Abp.Persona
Package Information:
- Package Name: GridLab.Abp.Persona
- Repository: GitLab - GridLab ABP Framework
- NuGet: GridLab.Abp.Persona
Step 2: Add Module Dependency¶
Add the AbpGridLabPersonaModule to your ABP module's dependency list:
[DependsOn(
//...other dependencies
typeof(AbpGridLabPersonaModule)
)]
public class YourModule : AbpModule
{
}
Step 3: Run Application¶
The personas will be automatically seeded on first application startup!
💡 Usage Examples¶
Testing Different User Roles¶
public class RoleBasedAccessTests
{
// Test Platform Admin Access
[Fact]
public async Task PlatformAdmin_ShouldHaveFullAccess()
{
// Login as platon (Platform Admin)
await LoginAsync("platon", "1q2w3E*");
// Test administrative operations
var canManageTenants = await AuthorizationService.IsGrantedAsync("Tenants.Manage");
Assert.True(canManageTenants);
}
// Test Data User Access
[Fact]
public async Task DataUser_ShouldHaveReadOnlyAccess()
{
// Login as dustin (Data User)
await LoginAsync("dustin", "Data1234+");
// Test read-only operations
var canReadData = await AuthorizationService.IsGrantedAsync("Data.Read");
var canWriteData = await AuthorizationService.IsGrantedAsync("Data.Write");
Assert.True(canReadData);
Assert.False(canWriteData);
}
}
Demo Data Scenarios¶
public class DemoDataService : ITransientDependency
{
private readonly IIdentityUserRepository _userRepository;
public DemoDataService(IIdentityUserRepository userRepository)
{
_userRepository = userRepository;
}
public async Task<List<IdentityUser>> GetAllPersonasAsync()
{
var personaUsernames = new[]
{
"platon", "adrian", "madisson",
"priscilla", "dustin", "polly"
};
return await _userRepository.GetListAsync(
u => personaUsernames.Contains(u.UserName)
);
}
}
🔧 Advanced Scenarios¶
Custom Persona Extension¶
While the module provides default personas, you can extend with custom users:
public class CustomPersonaSeeder : IDataSeedContributor, ITransientDependency
{
private readonly IIdentityUserRepository _userRepository;
private readonly ILookupNormalizer _lookupNormalizer;
public CustomPersonaSeeder(
IIdentityUserRepository userRepository,
ILookupNormalizer lookupNormalizer)
{
_userRepository = userRepository;
_lookupNormalizer = lookupNormalizer;
}
public async Task SeedAsync(DataSeedContext context)
{
if (await _userRepository.FindByNormalizedUserNameAsync(
_lookupNormalizer.NormalizeName("customUser")) == null)
{
await _userRepository.InsertAsync(
new IdentityUser(
Guid.NewGuid(),
"customUser",
"custom@test.com"
)
);
}
}
}
📚 Best Practices¶
✅ Do's¶
- Use personas for development and testing environments only
- Change default passwords in production
- Document which persona to use for testing specific features
- Use personas for integration tests
- Update persona passwords periodically in dev environments
❌ Don'ts¶
- Don't deploy persona module to production
- Don't use default persona passwords in production
- Don't rely on personas for production user management
- Don't share persona credentials publicly
- Don't use personas for load testing
⚠️ Security Warning¶
IMPORTANT: This module is designed for development and testing environments only. Never deploy to production with default passwords!
// Example: Conditional module loading
[DependsOn(
typeof(AbpGridLabPersonaModule)
)]
public class YourModule : AbpModule
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
var hostEnvironment = context.Services.GetHostingEnvironment();
if (hostEnvironment.IsProduction())
{
// Disable persona seeding in production
Configure<AbpDataSeedOptions>(options =>
{
options.Contributors.RemoveAll(
c => c.Type.Namespace?.Contains("Persona") == true
);
});
}
}
}