Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load SQL Drivers using isolated ClassLoader #159

Merged
merged 5 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion core/src/main/java/me/mastercapexd/auth/BaseAuthPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.util.concurrent.Executors;
import java.util.stream.IntStream;

import com.alessiodp.libby.classloader.IsolatedClassLoader;
import com.bivashy.auth.api.AuthPlugin;
import com.bivashy.auth.api.AuthPluginProvider;
import com.bivashy.auth.api.account.AccountFactory;
Expand Down Expand Up @@ -155,7 +156,8 @@ private void initializeBasic() {
this.authenticationStepContextFactoryBucket = new BaseAuthenticationStepContextFactoryBucket(config.getAuthenticationSteps());
this.accountFactory = new AuthAccountFactory();
this.linkTypeProvider = BaseLinkTypeProvider.allLinks();
this.accountDatabase = new AuthAccountDatabaseProxy(new DatabaseHelper(this));
// TODO: Replace this with IsolatedDatabaseHelperFactory
this.accountDatabase = new AuthAccountDatabaseProxy(new DatabaseHelper(this, new IsolatedClassLoader()));
this.loginManagement = new BaseLoginManagement(this);

this.registerAuthenticationSteps();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class DatabaseHelper {
private AuthAccountDao authAccountDao;
private AccountLinkDao accountLinkDao;

public DatabaseHelper(AuthPlugin plugin) {
public DatabaseHelper(AuthPlugin plugin, ClassLoader classLoader) {
DatabaseSettings databaseConfiguration = plugin.getConfig().getDatabaseConfiguration();
SchemaSettings schemaSettings = databaseConfiguration.getSchemaSettings();

Expand All @@ -62,7 +62,7 @@ public DatabaseHelper(AuthPlugin plugin) {
String cacheDriverCheckSum = HashUtils.getFileCheckSum(cacheDriverFile, HashUtils.getMD5());
if (!cacheDriverFile.exists() || cacheDriverCheckSum != null && !DownloadUtil.checkSum(HashUtils.mapToMd5URL(downloadUrl), cacheDriverCheckSum))
DownloadUtil.downloadFile(downloadUrl, cacheDriverFile);
DriverUtil.loadDriver(cacheDriverFile, plugin.getClass().getClassLoader());
DriverUtil.loadDriver(cacheDriverFile, classLoader);

DataPersisterManager.registerDataPersisters(new CryptoProviderPersister());

Expand All @@ -84,7 +84,7 @@ public DatabaseHelper(AuthPlugin plugin) {
accountLinkMigrationCoordinator.migrate(connectionSource, accountLinkDao);
}
enabled = true;
} catch(SQLException | IOException e) {
} catch (SQLException | IOException e) {
e.printStackTrace();
}
});
Expand All @@ -97,7 +97,7 @@ private void modifyDatabaseType(Consumer<List<DatabaseType>> consumer) {
List<DatabaseType> databaseTypes = (List<DatabaseType>) field.get(null);
consumer.accept(databaseTypes);
field.setAccessible(false);
} catch(NoSuchFieldException | IllegalAccessException ignored) {
} catch (NoSuchFieldException | IllegalAccessException ignored) {
}
}

Expand All @@ -124,4 +124,5 @@ public AuthAccountDao getAuthAccountDao() {
public AccountLinkDao getAccountLinkDao() {
return accountLinkDao;
}

}
Loading