You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
3.1 KiB

4 years ago
  1. #if MYSQL_6_9
  2. // Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  3. //
  4. // MySQL Connector/NET is licensed under the terms of the GPLv2
  5. // <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most
  6. // MySQL Connectors. There are special exceptions to the terms and
  7. // conditions of the GPLv2 as it is applied to this software, see the
  8. // FLOSS License Exception
  9. // <http://www.mysql.com/about/legal/licensing/foss-exception.html>.
  10. //
  11. // This program is free software; you can redistribute it and/or modify
  12. // it under the terms of the GNU General Public License as published
  13. // by the Free Software Foundation; version 2 of the License.
  14. //
  15. // This program is distributed in the hope that it will be useful, but
  16. // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  17. // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  18. // for more details.
  19. //
  20. // You should have received a copy of the GNU General Public License along
  21. // with this program; if not, write to the Free Software Foundation, Inc.,
  22. // 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  23. using System;
  24. using System.Collections.Generic;
  25. using System.Reflection;
  26. using System.Text;
  27. using Externals.MySql.Data.MySqlClient.Properties;
  28. namespace Externals.MySql.Data.MySqlClient.Authentication
  29. {
  30. internal class AuthenticationPluginManager
  31. {
  32. static Dictionary<string, PluginInfo> plugins = new Dictionary<string, PluginInfo>();
  33. static AuthenticationPluginManager()
  34. {
  35. plugins["mysql_native_password"] = new PluginInfo("Externals.MySql.Data.MySqlClient.Authentication.MySqlNativePasswordPlugin");
  36. plugins["sha256_password"] = new PluginInfo("Externals.MySql.Data.MySqlClient.Authentication.Sha256AuthenticationPlugin");
  37. plugins["authentication_windows_client"] = new PluginInfo("Externals.MySql.Data.MySqlClient.Authentication.MySqlWindowsAuthenticationPlugin");
  38. if (MySqlConfiguration.Settings != null && MySqlConfiguration.Settings.AuthenticationPlugins != null)
  39. {
  40. foreach (AuthenticationPluginConfigurationElement e in MySqlConfiguration.Settings.AuthenticationPlugins)
  41. plugins[e.Name] = new PluginInfo(e.Type);
  42. }
  43. }
  44. public static MySqlAuthenticationPlugin GetPlugin(string method)
  45. {
  46. if (!plugins.ContainsKey(method))
  47. throw new MySqlException(String.Format(Resources.AuthenticationMethodNotSupported, method));
  48. return CreatePlugin(method);
  49. }
  50. private static MySqlAuthenticationPlugin CreatePlugin(string method)
  51. {
  52. PluginInfo pi = plugins[method];
  53. try
  54. {
  55. Type t = Type.GetType(pi.Type);
  56. MySqlAuthenticationPlugin o = (MySqlAuthenticationPlugin)Activator.CreateInstance(t);
  57. return o;
  58. }
  59. catch (Exception e)
  60. {
  61. throw new MySqlException(String.Format(Resources.UnableToCreateAuthPlugin, method), e);
  62. }
  63. }
  64. }
  65. struct PluginInfo
  66. {
  67. public string Type;
  68. public Assembly Assembly;
  69. public PluginInfo(string type)
  70. {
  71. Type = type;
  72. Assembly = null;
  73. }
  74. }
  75. }
  76. #endif