An interface which describes the authenticated User for a request. You should provide at least either an id (a unique identifier for an authenticated user) or ip_address (their IP address).
Example #1
0
        public void Constructor_AssignedPrincipal_UsernameIsSet()
        {
            const string username = "******";
            var principal = Substitute.For<IPrincipal>();
            principal.Identity.Name.Returns(username);
            var user = new SentryUser(principal);

            Assert.That(user.Username, Is.EqualTo(username));
        }
        /// <summary>
        /// Gets the user.
        /// </summary>
        /// <returns>
        /// If an HTTP context is available, an instance of <see cref="SentryUser"/>, otherwise <c>null</c>.
        /// </returns>
        public SentryUser Create()
        {
            SentryUser user;
            if (!SentryRequestFactory.HasHttpContext)
                user = new SentryUser(Environment.UserName);
            else
            {
                user = new SentryUser(GetPrincipal())
                {
                    IpAddress = GetIpAddress()
                };
            }

            return OnCreate(user);
        }
Example #3
0
        /// <summary>
        /// Gets the user.
        /// </summary>
        /// <returns>
        /// If an HTTP context is available, an instance of <see cref="SentryUser"/>, otherwise <c>null</c>.
        /// </returns>
        public SentryUser Create()
        {
            SentryUser user;

            if (!SentryRequestFactory.HasHttpContext)
            {
                user = new SentryUser(Environment.UserName);
            }
            else
            {
                user = new SentryUser(GetPrincipal())
                {
                    IpAddress = GetIpAddress()
                };
            }

            return(OnCreate(user));
        }
Example #4
0
 public void Constructor_NullUsername_DoesNotThrow()
 {
     var user = new SentryUser((string) null);
     Assert.That(user.Username, Is.Null);
 }
Example #5
0
 public void Constructor_NullPrincipal_DoesNotThrow()
 {
     var user = new SentryUser((IPrincipal) null);
     Assert.That(user.Username, Is.Null);
 }
Example #6
0
 /// <summary>
 /// Called when the <see cref="SentryUser"/> has been created. Can be overridden to
 /// adjust the values of the <paramref name="user"/> before it is sent to Sentry.
 /// </summary>
 /// <param name="user">The user information.</param>
 /// <returns>
 /// The <see cref="SentryUser"/>.
 /// </returns>
 protected virtual SentryUser OnCreate(SentryUser user)
 {
     return(user);
 }
 /// <summary>
 /// Called when the <see cref="SentryUser"/> has been created. Can be overridden to
 /// adjust the values of the <paramref name="user"/> before it is sent to Sentry.
 /// </summary>
 /// <param name="user">The user information.</param>
 /// <returns>
 /// The <see cref="SentryUser"/>.
 /// </returns>
 protected virtual SentryUser OnCreate(SentryUser user)
 {
     return user;
 }