Ejemplo n.º 1
0
        public ProposalMetadataService(IConfiguration config, ILogger <ProposalMetadataService> logger) : base(config)
        {
            Config = config.GetMetadataConfig();
            Logger = logger;

            if (!File.Exists(Config.ProposalsPath))
            {
                Aliases  = new List <ProposalMetadataAlias>();
                Metadata = new Dictionary <string, ProposalMetadata>();
                Logger.LogInformation("Proposals metadata not found");
                return;
            }

            Logger.LogDebug("Loading proposals metadata...");

            var json      = File.ReadAllText(Config.ProposalsPath);
            var proposals = JsonSerializer.Deserialize <List <ProposalMetadata> >(json);

            Metadata = proposals.ToDictionary(x => x.Hash);
            Aliases  = new List <ProposalMetadataAlias>(Metadata.Count);

            foreach (var meta in Metadata.Values)
            {
                Aliases.Add(new ProposalMetadataAlias
                {
                    Hash  = meta.Hash,
                    Alias = meta.Alias
                });

                meta.Hash = null;
            }

            Logger.LogDebug($"Loaded {Metadata.Count} proposals metadata");
        }
Ejemplo n.º 2
0
            public DocumentMappingExpression <T> Metadata(Action <MetadataConfig> configure)
            {
                var metadata = new MetadataConfig(this);

                configure(metadata);

                return(this);
            }
Ejemplo n.º 3
0
        /// <summary>
        /// Configures the metadata.
        /// </summary>
        /// <param name="predicate">The metadata configuration.</param>
        /// <returns>The <see cref="Saml2ConfigBuilder"/>.</returns>
        public Saml2ConfigBuilder WithMetadataConfig(Action <MetadataConfigBuilder> predicate)
        {
            var builder = new MetadataConfigBuilder();

            predicate(builder);
            _metadataConfig = builder.Build();
            return(this);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Changes the links for the servicestack/metadata page
        /// </summary>
        public static ServiceEndpointsMetadataConfig Create(string serviceStackHandlerPrefix)
        {
            var config = new MetadataConfig("{0}", "{0}", "/{0}/reply", "/{0}/oneway", "/{0}/metadata");

            return(new ServiceEndpointsMetadataConfig
            {
                DefaultMetadataUri = "/metadata",
                Soap11 = new SoapMetadataConfig("soap11", "SOAP 1.1", "/soap11", "/soap11", "/soap11/metadata", "soap11"),
                Soap12 = new SoapMetadataConfig("soap12", "SOAP 1.2", "/soap12", "/soap12", "/soap12/metadata", "soap12"),
                Custom = config
            });
        }
Ejemplo n.º 5
0
        public AccountMetadataService(IConfiguration config, ILogger <AccountMetadataService> logger) : base(config)
        {
            Config = config.GetMetadataConfig();
            Logger = logger;

            if (!File.Exists(Config.AccountsPath))
            {
                Aliases  = new List <AccountMetadataAlias>();
                Metadata = new Dictionary <int, AccountMetadata>();
                Logger.LogInformation("Accounts metadata not found");
                return;
            }

            Logger.LogDebug("Loading accounts metadata...");

            var json     = File.ReadAllText(Config.AccountsPath);
            var accounts = JsonSerializer.Deserialize <List <AccountMetadata> >(json);

            var sql = @"
                    SELECT  ""Id"", ""Address""
                    FROM    ""Accounts""
                    WHERE   ""Address"" = ANY (@addresses)";

            using var db = GetConnection();
            var links = db.Query <(int Id, string Address)>(sql, new { addresses = accounts.Select(x => x.Address).ToArray() });

            Metadata = links.ToDictionary(x => x.Id, x => accounts.First(a => a.Address == x.Address));
            Aliases  = new List <AccountMetadataAlias>(Metadata.Count);

            foreach (var meta in Metadata.Values)
            {
                Aliases.Add(new AccountMetadataAlias
                {
                    Address = meta.Address,
                    Alias   = meta.Alias,
                    Logo    = meta.Logo
                });

                meta.Address = null;
            }

            Logger.LogDebug($"Loaded {Metadata.Count} accounts metadata");

            // temporary
            var fi = new FileInfo(Config.AccountsPath);

            Watcher = new FileSystemWatcher(fi.Directory.FullName, fi.Name);
            Watcher.NotifyFilter        = NotifyFilters.Size;
            Watcher.Changed            += Watcher_Changed;
            Watcher.Error              += Watcher_Error;
            Watcher.EnableRaisingEvents = true;
        }
 /// <summary>
 /// Changes the links for the servicestack/metadata page
 /// </summary>
 public static ServiceEndpointsMetadataConfig Create(string serviceStackHandlerPrefix)
 {
     var config = new MetadataConfig("{0}", "{0}", "/{0}/reply", "/{0}/oneway", "/{0}/metadata");
     return new ServiceEndpointsMetadataConfig {
         DefaultMetadataUri = "/metadata",
         Soap11 = new SoapMetadataConfig("soap11", "SOAP 1.1", "/soap11", "/soap11", "/soap11/metadata", "soap11"),
         Soap12 = new SoapMetadataConfig("soap12", "SOAP 1.2", "/soap12", "/soap12", "/soap12/metadata", "soap12"),
         Xml = config.Create("xml"),
         Json = config.Create("json"),
         Jsv = config.Create("jsv"),
         Custom = config
     };
 }
Ejemplo n.º 7
0
        public AccountMetadataService(IConfiguration config, ILogger <AccountMetadataService> logger) : base(config)
        {
            Config = config.GetMetadataConfig();
            Logger = logger;

            if (!File.Exists(Config.AccountsPath))
            {
                Aliases  = new List <AccountMetadataAlias>();
                Metadata = new Dictionary <int, AccountMetadata>();
                Logger.LogInformation("Accounts metadata not found");
                return;
            }

            Logger.LogDebug("Loading accounts metadata...");

            var json     = File.ReadAllText(Config.AccountsPath);
            var accounts = JsonSerializer.Deserialize <List <AccountMetadata> >(json);

            var sql = @"
                    SELECT  ""Id"", ""Address""
                    FROM    ""Accounts""
                    WHERE   ""Address"" = ANY (@addresses)";

            using var db = GetConnection();
            var links = db.Query <(int Id, string Address)>(sql, new { addresses = accounts.Select(x => x.Address).ToArray() });

            Metadata = accounts.ToDictionary(x => links.First(l => l.Address == x.Address).Id);
            Aliases  = new List <AccountMetadataAlias>(Metadata.Count);

            foreach (var meta in Metadata.Values)
            {
                Aliases.Add(new AccountMetadataAlias
                {
                    Address = meta.Address,
                    Alias   = meta.Alias,
                    Logo    = meta.Logo
                });

                meta.Address = null;
            }

            Logger.LogDebug($"Loaded {Metadata.Count} accounts metadata");
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Builds a <see cref="MetadataConfig"/> based on the current builder properties.
        /// </summary>
        /// <returns>A <see cref="MetadataConfig"/>.</returns>
        public MetadataConfig Build()
        {
            var config = new MetadataConfig();

            config.ExcludeArtifactEndpoints = _excludeArtifactEndpoints;
            config.Lifetime     = _lifetime;
            config.Organization = _organization;

            foreach (var contact in _contacts)
            {
                config.Contacts.Add(contact);
            }

            foreach (var requestedAttribute in _requestedAttributes)
            {
                config.RequestedAttributes.Add(requestedAttribute);
            }

            return(config);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Validates the <see cref="MetadataConfig"/>.
        /// </summary>
        /// <param name="metadataConfig">The <see cref="MetadataConfig"/>.</param>
        private void ValidateMetadata(MetadataConfig metadataConfig)
        {
            if (metadataConfig == null)
            {
                throw new Saml20ConfigurationException("Configuration Metadata cannot be null");
            }

            if (metadataConfig.Contacts == null)
            {
                throw new Saml20ConfigurationException("Configuration Metadata Contacts cannot be null");
            }

            if (metadataConfig.Lifetime == null)
            {
                throw new Saml20ConfigurationException("Configuration Metadata Lifetime cannot be null");
            }

            if (metadataConfig.RequestedAttributes == null)
            {
                throw new Saml20ConfigurationException("Configuration Metadata RequestedAttributes cannot be null");
            }
        }