public void AddCredentialAddsToUnderlyingList()
        {
            LoginRequest request = new LoginRequest();

            request.AddCredential(LoginRequest.PasswordCredential, "whoami");
            string actual = NameValuePair.FindNamedValue(request.Credentials, LoginRequest.PasswordCredential);

            Assert.AreEqual("whoami", actual);
        }
        public void AddBuildValueAddsToUnderlyingList()
        {
            BuildIntegrationRequest request = new BuildIntegrationRequest();

            request.AddBuildValue("value1", "actual value");
            string actual = NameValuePair.FindNamedValue(request.BuildValues, "value1");

            Assert.AreEqual("actual value", actual);
        }
        /// <summary>
        /// Starts a new session for a user.
        /// </summary>
        /// <param name="credentials">The credentials to use.</param>
        /// <returns>The session token if the credentials are valid, null otherwise.</returns>
        public string Login(LoginRequest credentials)
        {
            // Since we need a user name, let's attempt to find a user name in the credentials, otherwise
            // we'll just have to use string.Empty
            string userName = NameValuePair.FindNamedValue(credentials.Credentials,
                                                           LoginRequest.UserNameCredential);

            return(userName);
        }
示例#4
0
        public void LoginReturnsUserName()
        {
            LoginRequest        credentials = new LoginRequest("johndoe");
            NullSecurityManager manager     = new NullSecurityManager();

            manager.Initialise();
            string sessionToken = manager.Login(credentials);

            Assert.AreEqual(NameValuePair.FindNamedValue(credentials.Credentials, LoginRequest.UserNameCredential), sessionToken);
        }
        public void InitialiseRequestWithAUsernameSetsCorrectCredential()
        {
            LoginRequest request = new LoginRequest("johndoe");
            string       actual  = NameValuePair.FindNamedValue(request.Credentials, LoginRequest.UserNameCredential);

            Assert.AreEqual("johndoe", actual);
            var credentials = new List <NameValuePair>();

            request.Credentials = credentials;
            Assert.AreSame(credentials, request.Credentials);
        }
        /// <summary>
        /// Attempts to authenticate a user from the credentials.
        /// </summary>
        /// <param name="credentials">The credentials.</param>
        /// <returns>True if the credentials are valid, false otherwise..</returns>
        public bool Authenticate(LoginRequest credentials)
        {
            // Check that both the user name and the password match
            string userName = GetUserName(credentials);
            string password = NameValuePair.FindNamedValue(credentials.Credentials,
                                                           LoginRequest.PasswordCredential);
            bool isValid = !string.IsNullOrEmpty(userName) && !string.IsNullOrEmpty(password);

            if (isValid)
            {
                isValid = SecurityHelpers.IsWildCardMatch(userName, this.userName) &&
                          string.Equals(password, this.password, StringComparison.InvariantCulture);
            }
            return(isValid);
        }
        /// <summary>
        /// Starts a new session for a user.
        /// </summary>
        /// <param name="credentials">The credentials to use.</param>
        /// <returns>The session token if the credentials are valid, null otherwise.</returns>
        public virtual string Login(LoginRequest credentials)
        {
            string sessionToken = null;

            // Find the authentication
            string identifier = NameValuePair.FindNamedValue(credentials.Credentials,
                                                             LoginRequest.UserNameCredential);
            IAuthentication authentication = RetrieveUser(identifier);

            string userName    = credentials.Identifier;
            string displayName = null;

            if (authentication != null)
            {
                userName = authentication.GetUserName(credentials);
                // Attempt to authenticate
                if (authentication.Authenticate(credentials))
                {
                    // Start a new session
                    sessionToken = sessionCache.AddToCache(userName);
                    displayName  = authentication.GetDisplayName(credentials);
                    sessionCache.StoreSessionValue(sessionToken, displayNameKey, displayName);
                }
            }

            if (sessionToken != null)
            {
                Log.Debug(string.Format(System.Globalization.CultureInfo.CurrentCulture, "{0} [{1}] has logged in", displayName, userName));
                LogEvent(null, userName, SecurityEvent.Login, SecurityRight.Allow, null);
            }
            else
            {
                Log.Warning(string.Format(System.Globalization.CultureInfo.CurrentCulture, "Login failure: {0} has failed to login", userName));
                LogEvent(null, userName, SecurityEvent.Login, SecurityRight.Deny, null);
            }

            return(sessionToken);
        }
示例#8
0
 /// <summary>
 /// Retrieves the password from the credentials.
 /// </summary>
 /// <param name="credentials">The credentials.</param>
 /// <returns>The users password from the credentials. If the credentials do not exist in the system
 /// then null will be returned.</returns>
 public string GetPassword(LoginRequest credentials)
 {
     return(NameValuePair.FindNamedValue(credentials.Credentials, LoginRequest.PasswordCredential));
 }