Exemplo n.º 1
0
        private async Task SeedGlobalAdministrator(
            ICredentialRoleStore credentialRoleStore,
            ICredentialStore credentialStore)
        {
            bool isExistingAnyAdminCredentials =
                await credentialStore.IsExistingByCredentialRoleCode(SentinelCredentialRoleCodes.GlobalAdmin);

            if (!isExistingAnyAdminCredentials)
            {
                string adminCredentialId = SentinelCredentialIds.Admin;

                CredentialRole adminRole =
                    await credentialRoleStore.Get(SentinelCredentialRoleCodes.GlobalAdmin);

                Credential admin = new Credential();
                admin.BirthDate    = new DateTime(2000, 1, 1);
                admin.CreationDate = DateTime.UtcNow;
                admin.DisplayName  = adminCredentialId;
                admin.CredentialId = adminCredentialId;
                admin.Email        = adminCredentialId + "@admin.com";
                admin.PasswordSalt = HashingUtil.GenerateSalt();
                admin.PasswordHash = HashingUtil.GenerateHash(adminCredentialId, admin.PasswordSalt);
                admin.Roles        = new List <CredentialRole> {
                    adminRole
                };

                await credentialStore.Create(admin);
            }
        }
Exemplo n.º 2
0
 public CredentialsController(
     ICredentialRoleStore credentialRoleStore,
     ICredentialStore credentialStore,
     IDisplayNameRule displayNameRule)
 {
     this.CredentialRoleStore = credentialRoleStore;
     this.CredentialStore     = credentialStore;
     this.DisplayNameRule     = displayNameRule;
 }
Exemplo n.º 3
0
        private async Task SeetRegularUserRole(ICredentialRoleStore store)
        {
            bool isRegularUserRoleExisting = await store.IsExisting(SentinelCredentialRoleCodes.RegularUser);

            if (!isRegularUserRoleExisting)
            {
                CredentialRole role = new CredentialRole();
                role.Code        = SentinelCredentialRoleCodes.RegularUser;
                role.Description = "Regular authenticated user";

                await store.Create(role);
            }
        }
Exemplo n.º 4
0
        private async Task SeedGlobalAdministratorRole(ICredentialRoleStore store)
        {
            bool isGlobalAdminRoleExisting = await store.IsExisting(SentinelCredentialRoleCodes.GlobalAdmin);

            if (!isGlobalAdminRoleExisting)
            {
                CredentialRole role = new CredentialRole();
                role.Code        = SentinelCredentialRoleCodes.GlobalAdmin;
                role.Description = "Godlike administrator, completely unrestricted";

                await store.Create(role);
            }
        }
Exemplo n.º 5
0
        public static void UseSentinel(this IApplicationBuilder app)
        {
            ICredentialRoleStore credentialRoleStore = (ICredentialRoleStore)app.ApplicationServices.GetService(typeof(ICredentialRoleStore));
            ICredentialStore     credentialStore     = (ICredentialStore)app.ApplicationServices.GetService(typeof(ICredentialStore));

            var credentialRoleSeeder = new CredentialRoleSeeder();
            var credentialSeeder     = new CredentialSeeder();

            credentialRoleSeeder.Seed(credentialRoleStore).Wait();
            credentialSeeder.Seed(credentialRoleStore, credentialStore).Wait();

            //app.UseMiddleware<GatekeeperAuthenticationMiddleware>();
        }
Exemplo n.º 6
0
 public virtual async Task Seed(ICredentialRoleStore store)
 {
     await SeedGlobalAdministratorRole(store);
     await SeetRegularUserRole(store);
 }
Exemplo n.º 7
0
 public virtual async Task Seed(
     ICredentialRoleStore credentialRoleStore,
     ICredentialStore credentialStore)
 {
     await SeedGlobalAdministrator(credentialRoleStore, credentialStore);
 }