/* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. * A copy of the License is located at * * http://aws.amazon.com/apache2.0 * * or in the "license" file accompanying this file. This file is distributed * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either * express or implied. See the License for the specific language governing * permissions and limitations under the License. */ using Amazon.Util; using System; namespace Amazon.Runtime.CredentialManagement { /// /// Represents the different types of authentication available for SAML endpoints. /// public enum SAMLAuthenticationType { NTLM, Digest, Kerberos, Negotiate } /// /// Representation of a SAML Endpoint. /// public class SAMLEndpoint { private SAMLAuthenticationType DefaultAuthenticationType = SAMLAuthenticationType.Kerberos; /// /// The name given to this SAMLEndpoint. /// public string Name { get; private set; } /// /// The URI of the SAML endnpoint. /// public Uri EndpointUri { get; private set; } /// /// The authentication type associated with the SAML endpoint. /// public SAMLAuthenticationType AuthenticationType { get; private set; } /// /// Internal constructor. Used by SAMLEndpointManager when reading endpoints from the encrypted store. /// /// /// /// internal SAMLEndpoint(string name, string endpointUri, string authenticationType) { var parsedEndpointUri = new Uri(endpointUri, UriKind.RelativeOrAbsolute); var parsedAuthenticationType = DefaultAuthenticationType; if (!string.IsNullOrEmpty(authenticationType)) { parsedAuthenticationType = (SAMLAuthenticationType)Enum.Parse(typeof(SAMLAuthenticationType), authenticationType); } SetProperties(name, parsedEndpointUri, parsedAuthenticationType); } /// /// Construct a SAMLEndpoint using the default SAMLAuthenticationType - Kerberos. /// /// The name of the endpoint. /// The URI of the endpoint. public SAMLEndpoint(string name, Uri endpointUri) { SetProperties(name, endpointUri, DefaultAuthenticationType); } /// /// Construct a SAMLEndpoint. /// /// The name of the endpoint. /// The URI of the endpoint. /// The authentication type of the endpoint. public SAMLEndpoint(string name, Uri endpointUri, SAMLAuthenticationType authenticationType) { SetProperties(name, endpointUri, authenticationType); } private void SetProperties(string name, Uri endpointUri, SAMLAuthenticationType authenticationType) { if (!string.Equals(endpointUri.Scheme, "https", StringComparison.OrdinalIgnoreCase)) { throw new ArgumentException("EndpointUri is not Https protocol."); } if (string.IsNullOrEmpty(name)) { throw new ArgumentException("Name is null or empty."); } Name = name; EndpointUri = endpointUri; AuthenticationType = authenticationType; } } }