public static bool ContainsTenant(string tenantId) { using (TenantDb context = new TenantDb()) { return(context.Tenants .Where(tenant => tenant.Id == tenantId) .Any()); } }
public static bool ContainsKey(string thumbprint) { using (TenantDb context = new TenantDb()) { return(context.IssuingAuthorityKeys .Where(key => key.Id == thumbprint) .Any()); } }
public static void RefreshKeys(string metadataLocation) { IssuingAuthority issuingAuthority = ValidatingIssuerNameRegistry.GetIssuingAuthority(metadataLocation); bool newKeys = false; foreach (string thumbprint in issuingAuthority.Thumbprints) { if (!ContainsKey(thumbprint)) { newKeys = true; break; } } if (newKeys) { using (TenantDb context = new TenantDb()) { context.IssuingAuthorityKeys.RemoveRange(context.IssuingAuthorityKeys); foreach (string thumbprint in issuingAuthority.Thumbprints) { context.IssuingAuthorityKeys.Add(new IssuingAuthorityKey { Id = thumbprint }); } foreach (string issuer in issuingAuthority.Issuers) { context.Tenants.Add(new Tenant { Id = issuer.TrimEnd('/').Split('/').Last() }); } context.SaveChanges(); } } }
public TenantsCache(ICacheService cacheService) { this._cacheService = cacheService; this._tenantDb = new TenantDb(); }