/// <summary>
        /// Validates the credentials according to the given <paramref name="requirements"/>.
        /// The <see cref="CloudStorageCredentials.CloudStorageId"/> is not part of the validation,
        /// because it is not used for authorization itself.
        /// </summary>
        /// <param name="credentials">The credentials to validate.</param>
        /// <param name="requirements">The requirements the credentials must comply with.</param>
        /// <param name="allowAnonymous">Specifies whether username and password can be empty.</param>
        /// <exception cref="InvalidParameterException">Is thrown when the credentials are invalid.</exception>
        public static void ThrowIfInvalid(this CloudStorageCredentials credentials, CloudStorageCredentialsRequirements requirements, bool allowAnonymous = false)
        {
            if (credentials == null)
            {
                throw new InvalidParameterException(nameof(CloudStorageCredentials));
            }

            if (requirements.NeedsToken() && (credentials.Token == null))
            {
                throw new InvalidParameterException(string.Format("{0}.{1}", nameof(CloudStorageCredentials), nameof(CloudStorageCredentials.Token)));
            }

            if (requirements.NeedsUrl() && string.IsNullOrWhiteSpace(credentials.Url))
            {
                throw new InvalidParameterException(string.Format("{0}.{1}", nameof(CloudStorageCredentials), nameof(CloudStorageCredentials.Url)));
            }

            bool usernameRequiredOrProvided = !allowAnonymous || !string.IsNullOrEmpty(credentials.Username);

            if (usernameRequiredOrProvided)
            {
                if (requirements.NeedsUsername() && string.IsNullOrWhiteSpace(credentials.Username))
                {
                    throw new InvalidParameterException(string.Format("{0}.{1}", nameof(CloudStorageCredentials), nameof(CloudStorageCredentials.Username)));
                }

                if (requirements.NeedsPassword() && (credentials.Password == null))
                {
                    throw new InvalidParameterException(string.Format("{0}.{1}", nameof(CloudStorageCredentials), nameof(CloudStorageCredentials.Password)));
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Validates the credentials according to the given <paramref name="requirements"/>.
        /// The <see cref="CloudStorageCredentials.CloudStorageId"/> is not part of the validation,
        /// because it is not used for authorization itself.
        /// </summary>
        /// <param name="credentials">The credentials to validate.</param>
        /// <param name="requirements">The requirements the credentials must comply with.</param>
        /// <exception cref="InvalidParameterException">Is thrown when the credentials are invalid.</exception>
        public static void ThrowIfInvalid(this CloudStorageCredentials credentials, CloudStorageCredentialsRequirements requirements)
        {
            if (credentials == null)
            {
                throw new InvalidParameterException(nameof(CloudStorageCredentials));
            }

            if (requirements.NeedsToken() && (credentials.Token == null))
            {
                throw new InvalidParameterException(string.Format("{0}.{1}", nameof(CloudStorageCredentials), nameof(CloudStorageCredentials.Token)));
            }

            if (requirements.NeedsUrl() && string.IsNullOrWhiteSpace(credentials.Url))
            {
                throw new InvalidParameterException(string.Format("{0}.{1}", nameof(CloudStorageCredentials), nameof(CloudStorageCredentials.Url)));
            }

            if (requirements.NeedsUsername() && string.IsNullOrWhiteSpace(credentials.Username))
            {
                throw new InvalidParameterException(string.Format("{0}.{1}", nameof(CloudStorageCredentials), nameof(CloudStorageCredentials.Username)));
            }

            if (requirements.NeedsPassword() && (credentials.Password == null))
            {
                throw new InvalidParameterException(string.Format("{0}.{1}", nameof(CloudStorageCredentials), nameof(CloudStorageCredentials.Password)));
            }
        }
Exemple #3
0
        public CloudStorageAccountViewModel(
            INavigationService navigationService,
            ILanguageService languageService,
            ISvgIconService svgIconService,
            IBaseUrlService webviewBaseUrl,
            IStoryBoardService storyBoardService,
            IFeedbackService feedbackService,
            ICloudStorageClientFactory cloudStorageClientFactory,
            SerializeableCloudStorageCredentials model)
            : base(navigationService, languageService, svgIconService, webviewBaseUrl)
        {
            _storyBoardService = storyBoardService ?? throw new ArgumentNullException(nameof(storyBoardService));
            _feedbackService   = feedbackService ?? throw new ArgumentNullException(nameof(feedbackService));
            Model = model;

            _credentialsRequirements = cloudStorageClientFactory.GetOrCreate(Model.CloudStorageId).CredentialsRequirements;
            CloudServiceName         = cloudStorageClientFactory.GetCloudStorageMetadata(Model.CloudStorageId).Title;

            GoBackCommand = new RelayCommand(GoBack);
            CancelCommand = new RelayCommand(Cancel);
            OkCommand     = new RelayCommand(Ok);
        }
 /// <summary>
 /// Checks whether this requirement needs a secure flag.
 /// </summary>
 /// <param name="requirements">Requirement to check.</param>
 /// <returns>Returns true if if requires a secure flag, otherwise false.</returns>
 public static bool NeedsSecureFlag(this CloudStorageCredentialsRequirements requirements)
 {
     return(requirements == CloudStorageCredentialsRequirements.UsernamePasswordUrlSecure);
 }
 /// <summary>
 /// Checks whether this requirement needs a password.
 /// </summary>
 /// <param name="requirements">Requirement to check.</param>
 /// <returns>Returns true if if requires a password, otherwise false.</returns>
 public static bool NeedsPassword(this CloudStorageCredentialsRequirements requirements)
 {
     return(requirements != CloudStorageCredentialsRequirements.Token);
 }