public void ShouldCreateUserAndAuthenticate()
        {
            var username  = Guid.NewGuid().ToString();
            var succeeded = _service.CreateUser(username, Password);

            succeeded.Should().BeTrue();

            var authenticationSucceeded = _service.AuthenticateUser(username, Password);

            authenticationSucceeded.Should().BeTrue();
        }
示例#2
0
 public void Run()
 {
     try
     {
         _userDirectoryProvider.AuthenticateUser(Guid.NewGuid().ToString(), "valtech");
     }
     catch (CustomException)
     {
         // It's ok to get a custom exception
     }
 }
        public void UpdateUsername(Guid userId, string verfiyCode, string password)
        {
            var user = _userReadRepository.Get(userId);

            if (!verfiyCode.Equals(user.PendingUsernameCode, StringComparison.InvariantCultureIgnoreCase))
            {
                _logService.Debug("UpdateUsername failed to validate PendingUsernameCode: {0} for userId: {1}", verfiyCode, userId);
                throw new CustomException(ErrorCodes.InvalidUpdateUsernameCode);
            }

            if (!_userDirectoryProvider.AuthenticateUser(userId.ToString(), password))
            {
                _logService.Debug("UpdateUsername failed to autheticate userId: {0}", userId);
                throw new CustomException(ErrorCodes.UserPasswordError);
            }

            var pendingActivationUser = _userReadRepository.Get(user.PendingUsername, false);

            if (pendingActivationUser != null && pendingActivationUser.Status != UserStatuses.PendingDeletion)
            {
                //Delete any user with username = user.PendingUsername - they must be PendingActivation
                if (pendingActivationUser.Status != UserStatuses.PendingActivation)
                {
                    _logService.Error("UpdateUsername error, existing userId ({0}) to pending username ({1}) failed as username already exists and is not in PendingActivation state", userId, user.PendingUsername);
                    throw new CustomException(ErrorCodes.UsernameExistsAndNotInPendingActivationState);
                }
                _userWriteRepository.Delete(pendingActivationUser.EntityId);
                _authenticationRepository.Delete(pendingActivationUser.EntityId);
            }

            _logService.Info("UpdateUsername updating from '{0}' to '{1}'", user.Username, user.PendingUsername);
            _auditRepository.Audit(user, AuditEventTypes.UsernameChanged, user.EntityId);
            user.Username            = user.PendingUsername;
            user.PendingUsername     = null;
            user.PendingUsernameCode = null;
            _userWriteRepository.Save(user);
            _logService.Info("UpdateUsername updated to '{0}'", user.Username);
        }
示例#4
0
 public bool AuthenticateUser(Guid userId, string password)
 {
     _logger.Debug("Calling AuthenticationService to authenticate user with Id={0}", userId);
     return(_userDirectoryProvider.AuthenticateUser(userId.ToString(), password));
 }