示例#1
0
        /// <summary>
        /// Valida o usuário no provedor de identidade
        /// </summary>
        /// <param name="userName">Nome de usuário</param>
        /// <param name="password">Senha</param>
        /// <param name="servicesContext">Nome do contexto de serviços que será usado na autenticação.</param>
        /// <param name="parameters">Demais informações necessárias</param>
        /// <returns></returns>
        public ValidateUserResultWrapper ValidateUser(string userName, string password, string servicesContext, SecurityParameter[] parameters)
        {
            IValidateUserResult result = null;

            try
            {
                result = Membership.ValidateUser(userName, password, parameters);
            }
            catch (Exception ex)
            {
                result = new ValidateUserResult {
                    Message = ex.Message,
                    Status  = AuthenticationStatus.ErrorInValidate
                };
            }
            LogRequest(userName, result.Status);
            Colosoft.Net.ServiceAddress userProviderServiceAddress           = null;
            Colosoft.Net.ServiceAddress profileProviderServiceAddress        = null;
            Colosoft.Net.ServiceAddress serviceAddressProviderServiceAddress = null;
            if (result.Status == AuthenticationStatus.PasswordWarning || result.Status == AuthenticationStatus.Success)
            {
                userProviderServiceAddress           = GetServiceAddress(_configurationSection.UserProviderServiceName, servicesContext);
                profileProviderServiceAddress        = GetServiceAddress(_configurationSection.ProfileProviderServiceName, servicesContext);
                serviceAddressProviderServiceAddress = GetServiceAddress(_configurationSection.ServiceAddressProviderServiceName, servicesContext);
            }
            return(new ValidateUserResultWrapper(result, userProviderServiceAddress, profileProviderServiceAddress, serviceAddressProviderServiceAddress));
        }
        /// <summary>
        /// Valida os dados do usuário.
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="password"></param>
        public override void Validate(string userName, string password)
        {
            if (string.IsNullOrEmpty(userName) || string.IsNullOrEmpty(password))
            {
                throw new ArgumentNullException();
            }
            IValidateUserResult result = null;

            try
            {
                result = Membership.ValidateUser(userName, password);
            }
            catch (Exception ex)
            {
                var ex2 = ex;
                if (ex2 is System.Reflection.TargetInvocationException)
                {
                    ex2 = ex2.InnerException;
                }
                Log.Write(ResourceMessageFormatter.Create(() => Colosoft.Properties.Resources.Exception_FailOnValidateUser), ex2, Logging.Priority.Medium);
                throw ex2;
            }
            if (result.Status != AuthenticationStatus.Success)
            {
                throw new System.ServiceModel.FaultException("Unknown Username or Incorrect Password");
            }
        }
示例#3
0
        /// <summary>
        /// Altera o password do usuário
        /// </summary>
        /// <param name="userName">usuário</param>
        /// <param name="oldPassword">senha atual</param>
        /// <param name="newPassword">nova senha</param>
        /// <param name="parameters">demais parametros</param>
        /// <returns>resultado da operação</returns>
        public virtual ChangePasswordResult ChangePassword(string userName, string oldPassword, string newPassword, SecurityParameter[] parameters)
        {
            if (ValidatePassword != null)
            {
                PasswordValidateResult validateResult = ValidatePassword.IsValid(newPassword);
                if (!validateResult.IsOk)
                {
                    return(new ChangePasswordResult()
                    {
                        Status = ChangePasswordStatus.Error,
                        Message = validateResult.Message
                    });
                }
            }
            IValidateUserResult authenticateResult = ValidateUser(userName, oldPassword, parameters);

            if ((authenticateResult.Status == AuthenticationStatus.Success) || (authenticateResult.Status == AuthenticationStatus.PasswordWarning) || (authenticateResult.Status == AuthenticationStatus.PasswordExpired))
            {
                if (!_providers.ContainsKey(authenticateResult.User.IdentityProvider))
                {
                    try
                    {
                        _providers.Add(authenticateResult.User.IdentityProvider, Activator.CreateInstance(Microsoft.Practices.ServiceLocation.ServiceLocator.Current.GetInstance <IIdentityProviderManager>().GetProviderByName(authenticateResult.User.IdentityProvider).Type) as IAuthenticate);
                    }
                    catch (Exception ex)
                    {
                        return(new ChangePasswordResult()
                        {
                            Status = ChangePasswordStatus.Error,
                            Message = ex.Message
                        });
                    }
                }
                return(_providers[authenticateResult.User.IdentityProvider].ChangePassword(userName, oldPassword, newPassword, parameters));
            }
            else
            {
                ChangePasswordStatus status = ChangePasswordStatus.Error;
                switch (authenticateResult.Status)
                {
                case AuthenticationStatus.InvalidCaptcha:
                    status = ChangePasswordStatus.InvalidCaptcha;
                    break;

                case AuthenticationStatus.CaptchaRequired:
                    status = ChangePasswordStatus.CaptchaRequired;
                    break;
                }
                return(new ChangePasswordResult()
                {
                    Status = status,
                    Message = authenticateResult.Message,
                    Captcha = authenticateResult.Captcha
                });
            }
        }
示例#4
0
 /// <summary>
 /// Construtor padrão.
 /// </summary>
 /// <param name="instance">Instancia que será adaptada.</param>
 /// <param name="userProviderServiceAddress">Endereço do serviço do provedor dos usuários.</param>
 /// <param name="profileProviderServiceAddress">Endereço do serviço do provedor dos perfis.</param>
 /// <param name="serviceAddressProviderServiceAddress">Endereço do serviço do provedor dos endereços dos serviços.</param>
 public ValidateUserResultWrapper(IValidateUserResult instance, Colosoft.Net.ServiceAddress userProviderServiceAddress, Colosoft.Net.ServiceAddress profileProviderServiceAddress, Colosoft.Net.ServiceAddress serviceAddressProviderServiceAddress)
 {
     Status     = instance.Status;
     Message    = instance.Message;
     User       = instance.User != null ? new User(instance.User) : null;
     Captcha    = instance.Captcha;
     ExpireDate = instance.ExpireDate;
     Token      = instance.Token;
     UserProviderServiceAddress           = userProviderServiceAddress;
     ProfileProviderServiceAddress        = profileProviderServiceAddress;
     ServiceAddressProviderServiceAddress = serviceAddressProviderServiceAddress;
 }
示例#5
0
        /// <summary>
        /// Altera o password do usuário
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <param name="newPasswordQuestion"></param>
        /// <param name="newPasswordAnswer"></param>
        /// <returns></returns>
        public virtual bool ChangePasswordQuestionAndAnswer(string username, string password, string newPasswordQuestion, string newPasswordAnswer)
        {
            IValidateUserResult authenricateResult = ValidateUser(username, password, null);

            if ((authenricateResult.Status == AuthenticationStatus.Success) || (authenricateResult.Status == AuthenticationStatus.PasswordWarning) || (authenricateResult.Status == AuthenticationStatus.PasswordExpired))
            {
                var changedUser = authenricateResult.User as Security.Authentication.IAutheticableUser;
                changedUser.PasswordAnswer   = newPasswordAnswer;
                changedUser.PasswordQuestion = newPasswordQuestion;
                UpdateUser(changedUser);
                return(true);
            }
            return(false);
        }