public static ICollection <InMemoryScope> Get(int limit) { var scopes = new HashSet <InMemoryScope> { new InMemoryScope { Id = 1, Name = "Admin", Description = "They run the show" }, new InMemoryScope { Id = 2, Name = "Manager", Description = "They pay the bills" }, }; for (var i = 0; i < limit; i++) { var client = new InMemoryScope { Name = GenName().ToLower(), Description = GenName().ToLower(), Id = scopes.Count + 1 }; scopes.Add(client); } return(scopes); }
public Task <IdentityAdminResult <CreateResult> > CreateScopeAsync(IEnumerable <PropertyValue> properties) { var errors = ValidateRoleProperties(properties); if (errors.Any()) { return(Task.FromResult(new IdentityAdminResult <CreateResult>(errors.ToArray()))); } var scope = new InMemoryScope(); var createPropsMeta = GetMetadata().ScopeMetaData.CreateProperties; foreach (var prop in properties) { var result = SetScopeProperty(createPropsMeta, scope, prop.Type, prop.Value); if (!result.IsSuccess) { return(Task.FromResult(new IdentityAdminResult <CreateResult>(result.Errors.ToArray()))); } } if (_scopes.Any(x => x.Name.Equals(scope.Name, StringComparison.OrdinalIgnoreCase))) { return(Task.FromResult(new IdentityAdminResult <CreateResult>("Role name already in use."))); } _scopes.Add(scope); return (Task.FromResult(new IdentityAdminResult <CreateResult>(new CreateResult { Subject = scope.Id.ToString() }))); }
protected string GetScopeProperty(PropertyMetadata propMetadata, InMemoryScope scope) { string val; if (propMetadata.TryGet(scope, out val)) { return(val); } throw new Exception("Invalid property type " + propMetadata.Type); }
protected IdentityAdminResult SetScopeProperty(IEnumerable <PropertyMetadata> propsMeta, InMemoryScope scope, string type, string value) { IdentityAdminResult result; if (propsMeta.TrySet(scope, type, value, out result)) { return(result); } throw new Exception("Invalid property type " + type); }