Exemple #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="eventEndpoint"></param>
        public AuditTrailClient(string eventEndpoint, string scope, TokenClientOptions tokenClientOptions)
        {
            if (eventEndpoint is null)
            {
                throw new ArgumentNullException(nameof(eventEndpoint));
            }

            if (scope is null)
            {
                throw new ArgumentNullException(nameof(scope));
            }

            if (tokenClientOptions is null)
            {
                throw new ArgumentNullException(nameof(tokenClientOptions));
            }

            _httpClient = new HttpClient();
            _sink       = new NullSink();
            _logger     = new ConsoleLogger <AuditTrailClient>();
            _writer     = new JwtWriter();
            _store      = new NullStore();
            _options    = new AuditTrailClientOptions
            {
                DeliveryEndpoint   = eventEndpoint,
                AccessTokenScope   = scope,
                TokenClientOptions = tokenClientOptions
            };
            _accessTokenAcquirer = new DefaultAccessTokenAcquirer(
                new ConsoleLogger <DefaultAccessTokenAcquirer>(),
                new TokenClient(new HttpClient(), tokenClientOptions),
                Options.Create(_options));
        }
Exemple #2
0
        public DefaultAuditTrailStore(IOptions <AuditTrailClientOptions> options, ILogger <DefaultAuditTrailStore> logger)
        {
            _options = options.Value;
            _logger  = logger;
            if (_options.TemporaryStoragePath is null)
            {
                const string auditTrailFallbackDir = "AUDITTRAIL_FALLBACK_DIR";
                var          root = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
                                    ?? Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)
                                    ?? Environment.GetEnvironmentVariable(auditTrailFallbackDir);

                if (string.IsNullOrEmpty(root))
                {
                    throw new InvalidOperationException("Could not determine an appropriate location for storing tokens. Set the " + auditTrailFallbackDir + " environment variable to a folder where tokens should be stored.");
                }

                _directory = Path.Combine(root, Constants.DefaultStorageDirectory);
            }
            else
            {
                _directory = _options.TemporaryStoragePath;
            }

            try
            {
                if (ContainerUtils.IsContainer && !ContainerUtils.IsVolumeMountedFolder(_directory))
                {
                    // warn users that tokens may be lost when running in docker without a volume mounted folder
                    _logger.UsingEphemeralFileSystemLocationInContainer(_directory);
                }
            }
            catch (Exception ex)
            {
                // Treat exceptions as non-fatal when attempting to detect docker.
                // These might occur if fstab is an unrecognized format, or if there are other unusual
                // file IO errors.
                _logger.LogTrace(ex, "Failure occurred while attempting to detect docker.");
            }

            if (_options.TemporaryStorageEncryptionKey != null)
            {
                _encryptionKey = _options.TemporaryStorageEncryptionKey;
                _writer        = new JwtWriter();
                _policy        = new TokenValidationPolicyBuilder()
                                 .IgnoreNestedToken()
                                 .IgnoreSignatureByDefault()
                                 .WithDecryptionKey(_encryptionKey)
                                 .Build();
            }
            else
            {
                _logger.LogWarning("No encryption key is defined. The audit trail will be stored in plaintext.");
            }
        }
        public AuditTrailRecoveryService(IOptions <AuditTrailClientOptions> options, ILogger <AuditTrailRecoveryService> logger, IAuditTrailStore store, IAuditTrailSink sink)
        {
            if (options is null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            _options = options.Value;
            _logger  = logger ?? throw new ArgumentNullException(nameof(logger));
            _store   = store ?? throw new ArgumentNullException(nameof(store));
            _sink    = sink ?? throw new ArgumentNullException(nameof(sink));
        }
Exemple #4
0
        public AuditTrailClient(HttpClient httpClient, IOptions <AuditTrailClientOptions> options, IAuditTrailSink sink, IAuditTrailStore store, ILogger <AuditTrailClient> logger, IAccessTokenAcquirer tokenAcquirer, IHostEnvironment?env = null)
        {
            if (options is null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            _httpClient          = httpClient ?? throw new ArgumentNullException(nameof(httpClient));
            _sink                = sink ?? throw new ArgumentNullException(nameof(sink));
            _logger              = logger ?? throw new ArgumentNullException(nameof(logger));
            _accessTokenAcquirer = tokenAcquirer ?? throw new ArgumentNullException(nameof(tokenAcquirer));
            _store               = store ?? throw new ArgumentNullException(nameof(store));
            _env     = env;
            _options = options.Value;
            if (_options.DeliveryEndpoint is null)
            {
                throw new ArgumentException("The delivery endpoint is not defined.", nameof(options));
            }

            _writer = new JwtWriter();
        }
Exemple #5
0
 public DefaultAccessTokenAcquirer(ILogger <DefaultAccessTokenAcquirer> logger, TokenClient?tokenClient, IOptions <AuditTrailClientOptions> options)
 {
     _logger      = logger ?? throw new ArgumentNullException(nameof(logger));
     _tokenClient = tokenClient ?? throw new ArgumentNullException(nameof(tokenClient));
     _options     = options.Value;
 }