Exemplo n.º 1
0
        /// <summary>
        /// Verifies that the persisted settings contains the minimal viable data to
        /// instantiate an AWSCredentialsProfile instance.
        /// </summary>
        /// <param name="os">The persisted settings.</param>
        /// <exception cref="InvalidDataException">Thrown if the profile settings fail to validate.</exception>
        private static void Validate(SettingsCollection.ObjectSettings os)
        {
            var accessKeyId = os.GetValueOrDefault(SettingsConstants.AccessKeyField, null);

            if (accessKeyId == null)
            {
                throw new InvalidDataException("Missing or invalid access key value in the profile settings.");
            }

            var secretkey = os.GetValueOrDefault(SettingsConstants.SecretKeyField, null);

            if (secretkey == null)
            {
                throw new InvalidDataException("Missing or invalid secret key value in the profile settings.");
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Tests if an AWSCredentialsProfile instance could be instantiated from
        /// the persisted settings data.
        /// </summary>
        /// <param name="os">The persisted settings.</param>
        /// <returns>True if the settings are compatible with an AWSCredentialsProfile type.</returns>
        public static bool CanCreateFrom(SettingsCollection.ObjectSettings os)
        {
            var osProfileType = os.GetValueOrDefault(SettingsConstants.ProfileTypeField, null);

            // legacy AWS profiles will not have the type key present
            return(osProfileType == null || osProfileType.Equals(ProfileManager.AWSCredentialsProfileType, StringComparison.OrdinalIgnoreCase));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Instantiates an instance from the supplied settings.
        /// </summary>
        /// <param name="os">The persisted settings.</param>
        /// <returns>Profile instance or an exception if the profile data is invalid.</returns>
        public static SAMLEndpointSettings LoadFrom(SettingsCollection.ObjectSettings os)
        {
            if (os == null)
            {
                throw new ArgumentNullException("os");
            }

            if (!CanCreateFrom(os))
            {
                throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "Endpoint settings '{0}' does not contain SAML endpoint materials", os[SettingsConstants.DisplayNameField]));
            }

            Validate(os);

            var    endpoint           = os.GetValueOrDefault(SettingsConstants.EndpointField, null);
            string authenticationType = os.GetValueOrDefault(SettingsConstants.AuthenticationType, null);

            return(new SAMLEndpointSettings(os[SettingsConstants.DisplayNameField], new Uri(endpoint, UriKind.RelativeOrAbsolute), authenticationType));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Instantiates an AWSCredentialsProfile instance from the supplied settings collection.
        /// </summary>
        /// <param name="os">The settings representing the stored profile.</param>
        /// <returns>New credentials profile instance. An exception is thrown if the profile data is invalid.</returns>
        public static AWSCredentialsProfile LoadFrom(SettingsCollection.ObjectSettings os)
        {
            if (os == null)
            {
                throw new ArgumentNullException("os");
            }

            if (!CanCreateFrom(os))
            {
                throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "Profile '{0}' does not contain AWS credential materials", os[SettingsConstants.DisplayNameField]));
            }

            Validate(os);

            var accessKeyId = os.GetValueOrDefault(SettingsConstants.AccessKeyField, null);
            var secretkey   = os.GetValueOrDefault(SettingsConstants.SecretKeyField, null);

            return(new AWSCredentialsProfile(os[SettingsConstants.DisplayNameField], accessKeyId, secretkey));
        }
Exemplo n.º 5
0
        /// <summary>
        /// Validates that the presented settings would result in a valid role profile
        /// instance.
        /// </summary>
        /// <param name="os">The persisted settings.</param>
        /// <exception cref="InvalidDataException">Thrown if the profile settings fail to validate.</exception>
        private static void Validate(SettingsCollection.ObjectSettings os)
        {
            var endpointName = os.GetValueOrDefault(SettingsConstants.EndpointNameField, null);

            if (endpointName == null)
            {
                throw new InvalidDataException("Missing EndpointName data.");
            }

            SAMLEndpointSettings endpointSettings;

            if (!ProfileManager.TryGetSAMLEndpoint(endpointName, out endpointSettings))
            {
                throw new InvalidDataException(string.Format(CultureInfo.InvariantCulture, "Endpoint settings with the name '{0}' could not be found.", endpointName));
            }

            if (string.IsNullOrEmpty(os[SettingsConstants.RoleArnField]))
            {
                throw new InvalidDataException("Missing role ARN data.");
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Instantiates an instance from the supplied settings.
        /// </summary>
        /// <param name="os">The persisted settings.</param>
        /// <returns>Profile instance or an exception if the profile data is invalid.</returns>
        public static SAMLRoleProfile LoadFrom(SettingsCollection.ObjectSettings os)
        {
            if (os == null)
            {
                throw new ArgumentNullException("os");
            }

            if (!CanCreateFrom(os))
            {
                throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "Profile '{0}' does not contain SAML role materials", os[SettingsConstants.DisplayNameField]));
            }

            Validate(os);

            var endpointName     = os[SettingsConstants.EndpointNameField];
            var endpointSettings = ProfileManager.GetSAMLEndpoint(endpointName);

            var roleArn      = os[SettingsConstants.RoleArnField];
            var userIdentity = os.GetValueOrDefault(SettingsConstants.UserIdentityField, null);

            return(new SAMLRoleProfile(os[SettingsConstants.DisplayNameField], endpointSettings, roleArn, userIdentity));
        }
Exemplo n.º 7
0
        /// <summary>
        /// Verifies that the persisted settings contains the minimal viable data to
        /// instantiate a SAMLEndpointSettings instance.
        /// </summary>
        /// <param name="os">The persisted settings.</param>
        /// <exception cref="InvalidDataException">Thrown if the settings fail to validate.</exception>
        private static void Validate(SettingsCollection.ObjectSettings os)
        {
            var endpoint = os.GetValueOrDefault(SettingsConstants.EndpointField, null);

            if (endpoint == null)
            {
                throw new InvalidDataException("Missing endpoint value in the profile settings.");
            }

            try
            {
                var u = new Uri(endpoint);
                if (u.Scheme != Uri.UriSchemeHttps)
                {
                    throw new InvalidDataException("The scheme of the endpoint must be HTTPS.");
                }
            }
            catch (UriFormatException e)
            {
                throw new InvalidDataException("The configured endpoint is not valid.", e);
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Tests if a SAMLRoleProfile instance could be instantiated from
        /// the persisted settings data.
        /// </summary>
        /// <param name="os">The persisted settings.</param>
        /// <returns>True if the settings are compatible with a SAMLRoleProfile type.</returns>
        public static bool CanCreateFrom(SettingsCollection.ObjectSettings os)
        {
            var osProfileType = os.GetValueOrDefault(SettingsConstants.ProfileTypeField, null);

            return(osProfileType != null && osProfileType.Equals(ProfileManager.SAMLRoleProfileType, StringComparison.OrdinalIgnoreCase));
        }
Exemplo n.º 9
0
        /// <summary>
        /// Tests if a SAMLEndpointSettings instance could be instantiated from
        /// the persisted settings data.
        /// </summary>
        /// <param name="os">The persisted settings.</param>
        /// <returns>True if the settings are compatible.</returns>
        public static bool CanCreateFrom(SettingsCollection.ObjectSettings os)
        {
            var endpoint = os.GetValueOrDefault(SettingsConstants.EndpointField, null);

            return(!string.IsNullOrEmpty(endpoint));
        }