diff --git a/Authentication/ConfigBasedAuthenticatorFactory.cs b/Authentication/ConfigBasedAuthenticatorFactory.cs index e61cba5..e9d8101 100644 --- a/Authentication/ConfigBasedAuthenticatorFactory.cs +++ b/Authentication/ConfigBasedAuthenticatorFactory.cs @@ -22,11 +22,14 @@ using IBM.Cloud.SDK.Authentication.NoAuth; using IBM.Cloud.SDK.Utilities; using System.Collections.Generic; +using System; namespace IBM.Cloud.SDK.Authentication { public class ConfigBasedAuthenticatorFactory { + public static string ErrorMessageAuthTypeUnknown = "Unrecognized authentication type: {0}"; + public static Authenticator GetAuthenticator(string serviceName) { Authenticator authenticator = null; @@ -77,29 +80,29 @@ private static Authenticator CreateAuthenticator(Dictionary prop authType = Authenticator.AuthTypeIam; } - switch (authType) + if (authType.Equals(Authenticator.AuthTypeNoAuth, StringComparison.InvariantCultureIgnoreCase)) { - case Authenticator.AuthTypeNoAuth: - authenticator = new NoAuthAuthenticator(props); - break; - - case Authenticator.AuthTypeBasic: - authenticator = new BasicAuthenticator(props); - break; - - case Authenticator.AuthTypeIam: - authenticator = new IamAuthenticator(props); - break; - - case Authenticator.AuthTypeCp4d: - authenticator = new CloudPakForDataAuthenticator(props); - break; - - case Authenticator.AuthTypeBearer: - authenticator = new BearerTokenAuthenticator(props); - break; - default: - break; + authenticator = new NoAuthAuthenticator(props); + } + else if (authType.Equals(Authenticator.AuthTypeBasic, StringComparison.InvariantCultureIgnoreCase)) + { + authenticator = new BasicAuthenticator(props); + } + else if (authType.Equals(Authenticator.AuthTypeIam, StringComparison.InvariantCultureIgnoreCase)) + { + authenticator = new IamAuthenticator(props); + } + else if (authType.Equals(Authenticator.AuthTypeCp4d, StringComparison.InvariantCultureIgnoreCase)) + { + authenticator = new CloudPakForDataAuthenticator(props); + } + else if (authType.Equals(Authenticator.AuthTypeBearer, StringComparison.InvariantCultureIgnoreCase)) + { + authenticator = new BearerTokenAuthenticator(props); + } + else + { + throw new ArgumentException(string.Format(ErrorMessageAuthTypeUnknown, authType)); } return authenticator;