protected override void Up(MigrationBuilder migrationBuilder)
 {
     using (var db = new ProxyConfigurationDbContext())
     {
         db.RenameClientId("devops", "service.tagov.devops");
     }
 }
Пример #2
0
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            using (var db = new ProxyConfigurationDbContext())
            {
                db.Database.ExecuteSqlCommand(IdentityHelper.DeleteSql(
                                                  AumentumSecurityObjectModel.BaseValueSegementSecurityObjectModel.Name,
                                                  AumentumSecurityObjectModel.BaseValueSegementSecurityObjectModel.Resources.BaseValueSegmentConclusion,
                                                  ServiceTypes.Service));

                db.Database.ExecuteSqlCommand(IdentityHelper.DeleteSql(
                                                  AumentumSecurityObjectModel.BaseValueSegementSecurityObjectModel.Name,
                                                  AumentumSecurityObjectModel.BaseValueSegementSecurityObjectModel.Resources.BaseValueSegmentHistory,
                                                  ServiceTypes.Service));

                db.Database.ExecuteSqlCommand(IdentityHelper.DeleteSql(
                                                  AumentumSecurityObjectModel.BaseValueSegementSecurityObjectModel.Name,
                                                  AumentumSecurityObjectModel.BaseValueSegementSecurityObjectModel.Resources.BaseValueSegmentTransaction,
                                                  ServiceTypes.Service));

                db.Database.ExecuteSqlCommand(IdentityHelper.DeleteSql(
                                                  AumentumSecurityObjectModel.BaseValueSegementSecurityObjectModel.Name,
                                                  AumentumSecurityObjectModel.BaseValueSegementSecurityObjectModel.Resources.Owner,
                                                  ServiceTypes.Service));

                db.SaveChanges();
            }
        }
Пример #3
0
        /// <summary>
        /// Ability to add new client prior to v2 of Identity EF.
        /// </summary>
        /// <param name="db">ProxyConfigurationDbContext</param>
        /// <param name="clients">Clients</param>
        /// <remarks>There's a breaking change from v1 to v2 of Identity EF in terms of the clients table schema. Thus, prior to v2, this is how we should be adding new client(s). Do NOT continue to use this!</remarks>
        public static void AddClients(this ProxyConfigurationDbContext db, Client[] clients)
        {
            var sb = new StringBuilder();

            clients.ToList().ForEach(client =>
            {
                var uniqueclientId = "@clientId_" + Guid.NewGuid().ToString("N");
                var values         = string.Format(ClientValues, client.ClientId);
                sb.AppendLine($"DECLARE {uniqueclientId} INT; INSERT INTO [dbo].[Clients]({ClientColumns}) VALUES ({values}); SET {uniqueclientId}=SCOPE_IDENTITY()");

                client.AllowedGrantTypes.ForEach(grantType =>
                {
                    sb.AppendLine($"INSERT INTO [dbo].[ClientGrantTypes]([ClientId],[GrantType]) VALUES ({uniqueclientId},'{grantType.GrantType}')");
                });

                client.ClientSecrets.ForEach(secret =>
                {
                    sb.AppendLine($"INSERT INTO [dbo].[ClientSecrets]([ClientId],[Type],[Value]) VALUES ({uniqueclientId},'SharedSecret','{secret.Value}')");
                });

                client.AllowedScopes.ForEach(allowedScope =>
                {
                    sb.AppendLine($"INSERT INTO [dbo].[ClientScopes]([ClientId],[Scope]) VALUES ({uniqueclientId},'{allowedScope.Scope}')");
                });
            });

            db.Database.ExecuteSqlCommand(sb.ToString());
        }
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            using (var db = new ProxyConfigurationDbContext())
            {
                db.ApiResources.AddRange(new ApiResource[]
                {
                    new ApiResource
                    {
                        Name        = ApiServices.Service.LegalPartySearch,
                        Description = "API to search for legal parties.",
                        Scopes      = new List <ApiScope> {
                            new ApiScope {
                                Name = ApiServices.Service.LegalPartySearch
                            }
                        }
                    },
                });

                db.SaveChanges();

                db.AddClientScope("aumentum.web", ApiServices.Service.LegalPartySearch);

                db.AddClientScope("service.tagov.search", ApiServices.Service.LegalPartySearch);

                db.Database.ExecuteSqlCommand(IdentityHelper.InsertSql(
                                                  AumentumSecurityObjectModel.LegalPartySearchSecurityObjectModel.Name,
                                                  AumentumSecurityObjectModel.LegalPartySearchSecurityObjectModel.Resources.LegalPartySearch,
                                                  ServiceTypes.Service));

                db.SaveChanges();
            }
        }
Пример #5
0
 protected override void Down(MigrationBuilder migrationBuilder)
 {
     using (var db = new ProxyConfigurationDbContext())
     {
         db.UpdateClientGrantType("service.tagov.devops", GrantType.ResourceOwnerPassword);
     }
 }
 protected override void Down(MigrationBuilder migrationBuilder)
 {
     using (var db = new ProxyConfigurationDbContext())
     {
         db.RemoveClient("service.tagov.search");
     }
 }
Пример #7
0
 protected override void Up(MigrationBuilder migrationBuilder)
 {
     using (var db = new ProxyConfigurationDbContext())
     {
         db.UpdateClientGrantType("service.tagov.devops", GrantType.ClientCredentials);
     }
 }
Пример #8
0
        /// <summary>
        /// Adds scope to client.
        /// </summary>
        /// <param name="db">ProxyConfigurationDbContext</param>
        /// <param name="clientId">clientId</param>
        /// <param name="scope">scope</param>
        /// <remarks>There's a breaking change from v1 to v2 of Identity EF in terms of the clients table schema. Thus, prior to v2, this is how we should be adding new client(s). Do NOT continue to use this!</remarks>
        public static void AddClientScope(this ProxyConfigurationDbContext db, string clientId, string scope)
        {
            var uniqueclientId = "@clientId_" + Guid.NewGuid().ToString("N");
            var sql            =
                $"DECLARE {uniqueclientId} INT; SET {uniqueclientId} = (SELECT Id from [dbo].[Clients] WHERE ClientId='{clientId}'); INSERT INTO [dbo].[ClientScopes]([ClientId],[Scope]) VALUES ({uniqueclientId},'{scope}')";

            db.Database.ExecuteSqlCommand(sql);
        }
Пример #9
0
        /// <summary>
        /// Updates an existing client's grant-type.
        /// </summary>
        /// <param name="db">ProxyConfigurationDbContext.</param>
        /// <param name="clientId">clientId.</param>
        /// <param name="grantType">grantType.</param>
        /// <remarks>There's a breaking change from v1 to v2 of Identity EF in terms of the clients table schema. Thus, prior to v2, this is how we should be adding new client(s). Do NOT continue to use this!</remarks>
        public static void UpdateClientGrantType(this ProxyConfigurationDbContext db, string clientId, string grantType)
        {
            var uniqueclientId = "@clientId_" + Guid.NewGuid().ToString("N");
            var sql            =
                $"DECLARE {uniqueclientId} INT; SET {uniqueclientId} = (SELECT Id from [dbo].[Clients] WHERE ClientId='{clientId}'); UPDATE [dbo].[ClientGrantTypes] SET [GrantType]='{grantType}' WHERE ClientId={uniqueclientId}";

            db.Database.ExecuteSqlCommand(sql);
        }
Пример #10
0
        public ClientRepositoryTests()
        {
            var optionsBuilder = new DbContextOptionsBuilder <ConfigurationDbContext>();

            optionsBuilder.UseInMemoryDatabase(Guid.NewGuid().ToString("N"));

            _dbContext        = new ProxyConfigurationDbContext(optionsBuilder);
            _clientRepository = new ClientRepository(_dbContext);
        }
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            using (var db = new ProxyConfigurationDbContext())
            {
                db.Database.ExecuteSqlCommand("DELETE FROM [dbo].[ApiScopeClaims]");

                db.SaveChanges();
            }
        }
 protected override void Up(MigrationBuilder migrationBuilder)
 {
     using (var db = new ProxyConfigurationDbContext())
     {
         db.Database.ExecuteSqlCommand(IdentityHelper.InsertSql(
                                           AumentumSecurityObjectModel.BaseValueSegementSecurityObjectModel.Name,
                                           AumentumSecurityObjectModel.BaseValueSegementSecurityObjectModel.Resources.Flags,
                                           ServiceTypes.Service));
     }
 }
 protected override void Down(MigrationBuilder migrationBuilder)
 {
     using (var db = new ProxyConfigurationDbContext())
     {
         db.Database.ExecuteSqlCommand(IdentityHelper.DeleteSql(
                                           AumentumSecurityObjectModel.GRMEventSecurityObjectModel.Name,
                                           AumentumSecurityObjectModel.GRMEventSecurityObjectModel.Resources.SubComponentValues,
                                           ServiceTypes.Service));
     }
 }
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            using (var db = new ProxyConfigurationDbContext())
            {
                db.RemoveClient("aumentum.web");

                db.RemoveRange(db.ApiResources);

                db.SaveChanges();
            }
        }
Пример #15
0
        /// <summary>
        /// Ability to remove an existing client prior to v2 of Identity EF.
        /// </summary>
        /// <param name="db"></param>
        /// <param name="clientId"></param>
        /// <remarks>There's a breaking change from v1 to v2 of Identity EF in terms of the clients table schema. Thus, prior to v2, this is how we should be adding new client(s). Do NOT continue to use this!</remarks>
        public static void RemoveClient(this ProxyConfigurationDbContext db, string clientId)
        {
            var sb = new StringBuilder();

            var uniqueclientId = "@clientId_" + Guid.NewGuid().ToString("N");

            sb.AppendLine($"DECLARE {uniqueclientId} INT; SET {uniqueclientId} = (SELECT Id from [dbo].[Clients] WHERE ClientId='{clientId}');");
            sb.AppendLine($"DELETE [dbo].[ClientGrantTypes] WHERE [ClientId]={uniqueclientId}");
            sb.AppendLine($"DELETE [dbo].[ClientSecrets] WHERE [ClientId]={uniqueclientId}");
            sb.AppendLine($"DELETE [dbo].[ClientScopes] WHERE [ClientId]={uniqueclientId}");
            sb.AppendLine($"DELETE [dbo].[Clients] WHERE [Id]={uniqueclientId}");

            db.Database.ExecuteSqlCommand(sb.ToString());
        }
 protected override void Up(MigrationBuilder migrationBuilder)
 {
     using (var db = new ProxyConfigurationDbContext())
     {
         db.AddClients(new Client[]
         {
             new Client
             {
                 ClientId          = "service.tagov.search",
                 AllowedGrantTypes = new List <ClientGrantType>()
                 {
                     new ClientGrantType {
                         GrantType = GrantType.ClientCredentials
                     }
                 }, ClientSecrets = new List <ClientSecret>()
                 {
                     new ClientSecret {
                         Value = "password".Sha256()
                     }
                 }, AllowedScopes = new List <ClientScope>()
                 {
                     new ClientScope {
                         Scope = ApiServices.Common.ResourceLocator
                     },
                     new ClientScope {
                         Scope = ApiServices.Facade.AssessmentHeader
                     },
                     new ClientScope {
                         Scope = ApiServices.Facade.BaseValueSegment
                     },
                     new ClientScope {
                         Scope = ApiServices.Service.GrmEvent
                     },
                     new ClientScope {
                         Scope = ApiServices.Service.BaseValueSegment
                     },
                     new ClientScope {
                         Scope = ApiServices.Service.AssessmentEvent
                     },
                     new ClientScope {
                         Scope = ApiServices.Service.LegalParty
                     },
                     new ClientScope {
                         Scope = ApiServices.Service.RevenueObject
                     }
                 }
             }
         });
     }
 }
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            using (var db = new ProxyConfigurationDbContext())
            {
                db.Database.ExecuteSqlCommand("DELETE FROM [dbo].[ClientScopes] WHERE [Scope] ='api.service.legalpartysearch';");

                db.Database.ExecuteSqlCommand($"DELETE FROM [dbo].[ApiScopeClaims] WHERE [Type] LIKE '%api.legalpartysearch';");

                var apiRes = db.ApiResources.Single(x => x.Name == ApiServices.Service.LegalPartySearch);

                db.ApiResources.Remove(apiRes);

                db.SaveChanges();
            }
        }
Пример #18
0
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            using (var db = new ProxyConfigurationDbContext())
            {
                db.RemoveClient("devops");

                var apiResource = db.ApiResources.SingleOrDefault(x => x.Name == ApiServices.Common.Security);

                if (apiResource != null)
                {
                    db.ApiResources.Remove(apiResource);
                }

                db.SaveChanges();
            }
        }
Пример #19
0
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            using (var db = new ProxyConfigurationDbContext())
            {
                db.ApiResources.AddRange(new ApiResource[]
                {
                    new ApiResource
                    {
                        Name        = ApiServices.Common.Security,
                        Description = "API to manage security resources.",
                        Scopes      = new List <ApiScope> {
                            new ApiScope {
                                Name = ApiServices.Common.Security
                            }
                        }
                    },
                });

                db.SaveChanges();

                db.AddClients(new Client[]
                {
                    new Client
                    {
                        ClientId          = "devops",
                        AllowedGrantTypes = new List <ClientGrantType>()
                        {
                            new ClientGrantType {
                                GrantType = GrantType.ResourceOwnerPassword
                            }
                        }, ClientSecrets = new List <ClientSecret>()
                        {
                            new ClientSecret {
                                Value = "password".Sha256()
                            }
                        }, AllowedScopes = new List <ClientScope>()
                        {
                            new ClientScope {
                                Scope = ApiServices.Common.Security
                            },
                        }
                    }
                });
            }
        }
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            using (var db = new ProxyConfigurationDbContext())
            {
                db.ApiResources.AddRange(new ApiResource[]
                {
                    new ApiResource {
                        Name   = ApiServices.Common.ResourceLocator, Description = "Resource Locator is a common or shared service used to provide resource information such as service endpoints to consumer.",
                        Scopes = new List <ApiScope> {
                            new ApiScope {
                                Name = ApiServices.Common.ResourceLocator
                            }
                        }
                    },
                    new ApiResource {
                        Name   = ApiServices.Facade.AssessmentHeader, Description = "Assessment Header is a facade service used to provide assessment header information to base value segement header panel.",
                        Scopes = new List <ApiScope> {
                            new ApiScope {
                                Name = ApiServices.Facade.AssessmentHeader
                            }
                        }
                    },
                    new ApiResource {
                        Name   = ApiServices.Facade.BaseValueSegment, Description = "Base value segment is a facade service used to provide assessment header information to base value segement grids.",
                        Scopes = new List <ApiScope> {
                            new ApiScope {
                                Name = ApiServices.Facade.BaseValueSegment
                            }
                        }
                    },
                    new ApiResource {
                        Name   = ApiServices.Service.GrmEvent, Description = "GRM event service.",
                        Scopes = new List <ApiScope> {
                            new ApiScope {
                                Name = ApiServices.Service.GrmEvent
                            }
                        }
                    },
                    new ApiResource {
                        Name   = ApiServices.Service.BaseValueSegment, Description = "Base value segment service.",
                        Scopes = new List <ApiScope> {
                            new ApiScope {
                                Name = ApiServices.Service.BaseValueSegment
                            }
                        }
                    },
                    new ApiResource {
                        Name   = ApiServices.Service.AssessmentEvent, Description = "Assessment event service.",
                        Scopes = new List <ApiScope> {
                            new ApiScope {
                                Name = ApiServices.Service.AssessmentEvent
                            }
                        }
                    },
                    new ApiResource {
                        Name   = ApiServices.Service.LegalParty, Description = "Legal party service.",
                        Scopes = new List <ApiScope> {
                            new ApiScope {
                                Name = ApiServices.Service.LegalParty
                            }
                        }
                    },
                    new ApiResource {
                        Name   = ApiServices.Service.RevenueObject, Description = "Revenue object service.",
                        Scopes = new List <ApiScope> {
                            new ApiScope {
                                Name = ApiServices.Service.RevenueObject
                            }
                        }
                    }
                });

                db.SaveChanges();

                db.AddClients(new Client[]
                {
                    new Client
                    {
                        ClientId          = "aumentum.web",
                        AllowedGrantTypes = new List <ClientGrantType>()
                        {
                            new ClientGrantType {
                                GrantType = GrantType.ResourceOwnerPassword
                            }
                        }, ClientSecrets = new List <ClientSecret>()
                        {
                            new ClientSecret {
                                Value = "password".Sha256()
                            }
                        }, AllowedScopes = new List <ClientScope>()
                        {
                            new ClientScope {
                                Scope = ApiServices.Common.ResourceLocator
                            },
                            new ClientScope {
                                Scope = ApiServices.Facade.AssessmentHeader
                            },
                            new ClientScope {
                                Scope = ApiServices.Facade.BaseValueSegment
                            },
                            new ClientScope {
                                Scope = ApiServices.Service.GrmEvent
                            },
                            new ClientScope {
                                Scope = ApiServices.Service.BaseValueSegment
                            },
                            new ClientScope {
                                Scope = ApiServices.Service.AssessmentEvent
                            },
                            new ClientScope {
                                Scope = ApiServices.Service.LegalParty
                            },
                            new ClientScope {
                                Scope = ApiServices.Service.RevenueObject
                            }
                        }
                    }
                });
            }
        }
Пример #21
0
        /// <summary>
        /// Renames an existing client Id.
        /// </summary>
        /// <param name="db">ProxyConfigurationDbContext</param>
        /// <param name="oldName">oldName</param>
        /// <param name="newName">newName</param>
        /// <remarks>There's a breaking change from v1 to v2 of Identity EF in terms of the clients table schema. Thus, prior to v2, this is how we should be adding new client(s). Do NOT continue to use this!</remarks>
        public static void RenameClientId(this ProxyConfigurationDbContext db, string oldName, string newName)
        {
            var sql = $"UPDATE [dbo].[Clients] SET ClientId='{newName}' WHERE ClientId='{oldName}'";

            db.Database.ExecuteSqlCommand(sql);
        }
Пример #22
0
 public ApiResourceRepository(ProxyConfigurationDbContext proxyConfigurationDbContext)
 {
     _proxyConfigurationDbContext = proxyConfigurationDbContext;
 }
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            using (var db = new ProxyConfigurationDbContext())
            {
                db.Database.ExecuteSqlCommand(IdentityHelper.InsertSql(
                                                  AumentumSecurityObjectModel.LegalPartySecurityObjectModel.Name,
                                                  AumentumSecurityObjectModel.LegalPartySecurityObjectModel.Resources.LegalParty,
                                                  ServiceTypes.Service));

                db.Database.ExecuteSqlCommand(IdentityHelper.InsertSql(
                                                  AumentumSecurityObjectModel.LegalPartySecurityObjectModel.Name,
                                                  AumentumSecurityObjectModel.LegalPartySecurityObjectModel.Resources.LegalPartyRole,
                                                  ServiceTypes.Service));

                db.Database.ExecuteSqlCommand(IdentityHelper.InsertSql(
                                                  AumentumSecurityObjectModel.LegalPartySecurityObjectModel.Name,
                                                  AumentumSecurityObjectModel.LegalPartySecurityObjectModel.Resources.LegalPartyDocument,
                                                  ServiceTypes.Service));

                db.Database.ExecuteSqlCommand(IdentityHelper.InsertSql(
                                                  AumentumSecurityObjectModel.AssessmentEventSecurityObjectModel.Name,
                                                  AumentumSecurityObjectModel.AssessmentEventSecurityObjectModel.Resources.AssessmentEventRevision,
                                                  ServiceTypes.Service));

                db.Database.ExecuteSqlCommand(IdentityHelper.InsertSql(
                                                  AumentumSecurityObjectModel.AssessmentEventSecurityObjectModel.Name,
                                                  AumentumSecurityObjectModel.AssessmentEventSecurityObjectModel.Resources.AssessmentEventAttributeValue,
                                                  ServiceTypes.Service));

                db.Database.ExecuteSqlCommand(IdentityHelper.InsertSql(
                                                  AumentumSecurityObjectModel.AssessmentEventSecurityObjectModel.Name,
                                                  AumentumSecurityObjectModel.AssessmentEventSecurityObjectModel.Resources.AssessmentEvent,
                                                  ServiceTypes.Service));

                db.Database.ExecuteSqlCommand(IdentityHelper.InsertSql(
                                                  AumentumSecurityObjectModel.AssessmentEventSecurityObjectModel.Name,
                                                  AumentumSecurityObjectModel.AssessmentEventSecurityObjectModel.Resources.StatutoryReference,
                                                  ServiceTypes.Service));

                db.Database.ExecuteSqlCommand(IdentityHelper.InsertSql(
                                                  AumentumSecurityObjectModel.RevenueObjectSecurityObjectModel.Name,
                                                  AumentumSecurityObjectModel.RevenueObjectSecurityObjectModel.Resources.RevenueObject,
                                                  ServiceTypes.Service));

                db.Database.ExecuteSqlCommand(IdentityHelper.InsertSql(
                                                  AumentumSecurityObjectModel.RevenueObjectSecurityObjectModel.Name,
                                                  AumentumSecurityObjectModel.RevenueObjectSecurityObjectModel.Resources.TaxAuthorityGroup,
                                                  ServiceTypes.Service));

                db.Database.ExecuteSqlCommand(IdentityHelper.InsertSql(
                                                  AumentumSecurityObjectModel.GRMEventSecurityObjectModel.Name,
                                                  AumentumSecurityObjectModel.GRMEventSecurityObjectModel.Resources.GRMEvent,
                                                  ServiceTypes.Service));

                db.Database.ExecuteSqlCommand(IdentityHelper.InsertSql(
                                                  AumentumSecurityObjectModel.GRMEventSecurityObjectModel.Name,
                                                  AumentumSecurityObjectModel.GRMEventSecurityObjectModel.Resources.GRMEventInformation,
                                                  ServiceTypes.Service));

                db.Database.ExecuteSqlCommand(IdentityHelper.InsertSql(
                                                  AumentumSecurityObjectModel.ResourceLocatorSecurityObjectModel.Name,
                                                  AumentumSecurityObjectModel.ResourceLocatorSecurityObjectModel.Resources.Resource,
                                                  ServiceTypes.Common));

                db.Database.ExecuteSqlCommand(IdentityHelper.InsertSql(
                                                  AumentumSecurityObjectModel.BaseValueSegementSecurityObjectModel.Name,
                                                  AumentumSecurityObjectModel.BaseValueSegementSecurityObjectModel.Resources.BaseValueSegment,
                                                  ServiceTypes.Service));

                db.Database.ExecuteSqlCommand(IdentityHelper.InsertSql(
                                                  AumentumSecurityObjectModel.BaseValueSegementSecurityObjectModel.Name,
                                                  AumentumSecurityObjectModel.BaseValueSegementSecurityObjectModel.Resources.BaseValueSegmentEvent,
                                                  ServiceTypes.Service));

                db.Database.ExecuteSqlCommand(IdentityHelper.InsertSql(
                                                  AumentumSecurityObjectModel.BaseValueSegementSecurityObjectModel.Name,
                                                  AumentumSecurityObjectModel.BaseValueSegementSecurityObjectModel.Resources.CaliforniaConsumerPriceIndex,
                                                  ServiceTypes.Service));

                db.Database.ExecuteSqlCommand(IdentityHelper.InsertSql(
                                                  AumentumSecurityObjectModel.BaseValueSegementSecurityObjectModel.Name,
                                                  AumentumSecurityObjectModel.BaseValueSegementSecurityObjectModel.Resources.SubComponent,
                                                  ServiceTypes.Service));
            }
        }
Пример #24
0
 public ClientRepository(ProxyConfigurationDbContext proxyConfigurationDbContext)
 {
     _proxyConfigurationDbContext = proxyConfigurationDbContext;
 }