org.mariadb.jdbc.credential.CredentialPluginLoader Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mariadb-java-client Show documentation
Show all versions of mariadb-java-client Show documentation
JDBC driver for MariaDB and MySQL
/*
* MariaDB Client for Java
*
* Copyright (c) 2012-2014 Monty Program Ab.
* Copyright (c) 2015-2019 MariaDB Ab.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License along
* with this library; if not, write to Monty Program Ab [email protected].
*
*/
package org.mariadb.jdbc.credential;
import org.mariadb.jdbc.Driver;
import java.sql.*;
import java.util.*;
/**
* Provider to handle plugin authentication. This can allow library users to override our default
* Authentication provider.
*/
public class CredentialPluginLoader {
private static ServiceLoader loader =
ServiceLoader.load(CredentialPlugin.class, Driver.class.getClassLoader());
/**
* Get current Identity plugin according to option `identityType`.
*
* @param type identity plugin type
* @return identity plugin
* @throws SQLException if no identity plugin found with this type is in classpath
*/
public static CredentialPlugin get(String type) throws SQLException {
if (type == null || type.isEmpty()) {
return null;
}
for (CredentialPlugin implClass : loader) {
if (type.equals(implClass.type())) {
return implClass;
}
}
throw new SQLException(
"No identity plugin registered with the type \"" + type + "\".", "08004", 1251);
}
}