Skip to content

Commit

Permalink
[CONJ-742] ensure plugin using Driver classloader
Browse files Browse the repository at this point in the history
  • Loading branch information
rusher committed Oct 30, 2019
1 parent ed382fa commit 4e0705b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,16 @@

package org.mariadb.jdbc.authentication;

import org.mariadb.jdbc.Driver;

import java.sql.*;
import java.util.*;

public class AuthenticationPluginLoader {

private static ServiceLoader<AuthenticationPlugin> loader =
ServiceLoader.load(AuthenticationPlugin.class, Driver.class.getClassLoader());

/**
* Get authentication plugin from type String. Customs authentication plugin can be added
* implementing AuthenticationPlugin and registering new type in resources services.
Expand All @@ -39,16 +44,16 @@ public static AuthenticationPlugin get(String type) throws SQLException {
if (type == null || type.isEmpty()) {
return null;
}
ServiceLoader<AuthenticationPlugin> loader = ServiceLoader.load(AuthenticationPlugin.class);

for (AuthenticationPlugin implClass : loader) {
if (type.equals(implClass.type())) {
return implClass;
}
}
throw new SQLException(
"Client does not support authentication protocol requested by server. "
+ "plugin type was = "
+ type,
+ "plugin type was = '"
+ type + "'",
"08004",
1251);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

package org.mariadb.jdbc.credential;

import org.mariadb.jdbc.Driver;

import java.sql.*;
import java.util.*;

Expand All @@ -30,6 +32,9 @@
*/
public class CredentialPluginLoader {

private static ServiceLoader<CredentialPlugin> loader =
ServiceLoader.load(CredentialPlugin.class, Driver.class.getClassLoader());

/**
* Get current Identity plugin according to option `identityType`.
*
Expand All @@ -41,7 +46,7 @@ public static CredentialPlugin get(String type) throws SQLException {
if (type == null || type.isEmpty()) {
return null;
}
ServiceLoader<CredentialPlugin> loader = ServiceLoader.load(CredentialPlugin.class);

for (CredentialPlugin implClass : loader) {
if (type.equals(implClass.type())) {
return implClass;
Expand Down

0 comments on commit 4e0705b

Please sign in to comment.