/// <summary> /// Valida os dados do token. /// </summary> /// <param name="token"></param> /// <returns></returns> public IValidateUserResult ValidateToken(string token) { var servicesContext = Colosoft.Net.ServicesConfiguration.Current != null ? Colosoft.Net.ServicesConfiguration.Current.ServicesContext : null; AuthenticationHost.ValidateUserResult result = null; try { result = AuthenticationClient.ValidateToken(token, servicesContext); } catch (System.ServiceModel.EndpointNotFoundException) { result = new AuthenticationHost.ValidateUserResult { Status = AuthenticationHost.AuthenticationStatus.ErrorInCommunication, Message = ResourceMessageFormatter.Create(() => Properties.Resources.RemoteUserProvider_ValidateTokenErrorEndpointNotFound).Format() }; } catch (System.ServiceModel.FaultException <DetailsException> ) { result = new AuthenticationHost.ValidateUserResult { Status = AuthenticationHost.AuthenticationStatus.UnknownError, Message = ResourceMessageFormatter.Create(() => Properties.Resources.RemoteUserProvider_ValidateTokenFaultException).Format() }; } catch (System.ServiceModel.CommunicationException) { result = new AuthenticationHost.ValidateUserResult { Status = AuthenticationHost.AuthenticationStatus.ErrorInCommunication, Message = ResourceMessageFormatter.Create(() => Properties.Resources.RemoteUserProvider_ValidateUserErrorInCommunication).Format() }; } catch (TimeoutException) { result = new AuthenticationHost.ValidateUserResult { Status = AuthenticationHost.AuthenticationStatus.ErrorInCommunication, Message = ResourceMessageFormatter.Create(() => Properties.Resources.RemoteUserProvider_ValidateUserErrorInCommunicationTimeout).Format() }; } catch (Exception ex) { result = new AuthenticationHost.ValidateUserResult { Status = AuthenticationHost.AuthenticationStatus.UnknownError, Message = ResourceMessageFormatter.Create(() => Properties.Resources.RemoteUserProvider_ValidateTokenUnknownError, Colosoft.Diagnostics.ExceptionFormatter.FormatException(ex, true)).Format() }; } return(Convert(result)); }
/// <summary> /// Converte o resultado vindo do serviço para o do sistema. /// </summary> /// <param name="validateUserResult"></param> /// <returns></returns> private static IValidateUserResult Convert(AuthenticationHost.ValidateUserResult validateUserResult) { if (validateUserResult == null) { return(null); } return(new Wrappers.ValidateUserResultWrapper { Captcha = Convert(validateUserResult.Captcha), ExpireDate = validateUserResult.ExpireDate, Message = validateUserResult.Message, Status = Convert(validateUserResult.Status), Token = validateUserResult.Token, User = validateUserResult.User != null ? new Wrappers.UserWrapper(validateUserResult.User) : null, UserProviderServiceAddress = validateUserResult.UserProviderServiceAddress, ProfileProviderServiceAddress = validateUserResult.ProfileProviderServiceAddress, ServiceAddressProviderServiceAddress = validateUserResult.ServiceAddressProviderServiceAddress, Error = validateUserResult is ValidateUserResultError ? ((ValidateUserResultError)validateUserResult).Error : null }); }
/// <summary> /// Valida credenciais /// </summary> /// <param name="userName">Nome de usuário</param> /// <param name="password">Senha</param> /// <param name="parameters">Demais parâmetros</param> /// <returns>Resultado da autenticação</returns> public IValidateUserResult ValidateUser(string userName, string password, params SecurityParameter[] parameters) { // Calcula o Hash da senha var passwordHash = HashPassword(password); var servicesContext = Colosoft.Net.ServicesConfiguration.Current != null ? Colosoft.Net.ServicesConfiguration.Current.ServicesContext : null; AuthenticationHost.ValidateUserResult result = null; try { // Realiza a validação do usuário result = AuthenticationClient.ValidateUser(userName, passwordHash, servicesContext, parameters); } catch (System.ServiceModel.EndpointNotFoundException ex) { result = new ValidateUserResultError { Status = AuthenticationHost.AuthenticationStatus.ErrorInCommunication, Message = ResourceMessageFormatter.Create(() => Properties.Resources.RemoteUserProvider_ValidateUserErrorEndpointNotFound).Format(), Error = ex }; } catch (System.ServiceModel.FaultException <System.ServiceModel.ExceptionDetail> ex) { result = new ValidateUserResultError { Status = AuthenticationHost.AuthenticationStatus.UnknownError, Message = ResourceMessageFormatter.Create(() => Properties.Resources.RemoteUserProvider_ValidateUserFaultException, ex.Message).Format(), Error = ex }; } catch (System.ServiceModel.CommunicationException ex) { result = new ValidateUserResultError { Status = AuthenticationHost.AuthenticationStatus.ErrorInCommunication, Message = ResourceMessageFormatter.Create(() => Properties.Resources.RemoteUserProvider_ValidateUserErrorInCommunication).Format(), Error = ex }; } catch (TimeoutException ex) { result = new ValidateUserResultError { Status = AuthenticationHost.AuthenticationStatus.ErrorInCommunication, Message = ResourceMessageFormatter.Create(() => Properties.Resources.RemoteUserProvider_ValidateUserErrorInCommunicationTimeout).Format(), Error = ex }; } catch (Exception ex) { result = new ValidateUserResultError { Status = AuthenticationHost.AuthenticationStatus.UnknownError, Message = ResourceMessageFormatter.Create(() => Properties.Resources.RemoteUserProvider_ValidateUserUnknownError).Format(), Error = ex }; } if (result.Status == AuthenticationHost.AuthenticationStatus.Success) { _userProviderClientUserName = userName; _userProviderClientPassword = password; } else { _userProviderClientUserName = "******"; _userProviderClientPassword = "******"; } Net.ServiceClientsManager.Current.Reset(_authenticationClientUid); return(Convert(result)); }