aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2022-06-04 09:59:13 -0700
committerAnton Tananaev <anton@traccar.org>2022-06-04 09:59:13 -0700
commitfd84b0dcb86208c2c9c64fbe067cf7d4324892ac (patch)
tree4cab6727dba45c1a9610814df668c59783fff09b
parent4b0c47095c4fdd8d8b6849e36aac2761226b5b7e (diff)
downloadtrackermap-server-fd84b0dcb86208c2c9c64fbe067cf7d4324892ac.tar.gz
trackermap-server-fd84b0dcb86208c2c9c64fbe067cf7d4324892ac.tar.bz2
trackermap-server-fd84b0dcb86208c2c9c64fbe067cf7d4324892ac.zip
Remove ldap from context
-rw-r--r--src/main/java/org/traccar/Context.java13
-rw-r--r--src/main/java/org/traccar/MainModule.java12
-rw-r--r--src/main/java/org/traccar/database/DataManager.java13
-rw-r--r--src/main/java/org/traccar/database/LdapProvider.java2
4 files changed, 20 insertions, 20 deletions
diff --git a/src/main/java/org/traccar/Context.java b/src/main/java/org/traccar/Context.java
index 97cfb2bf9..1aa673077 100644
--- a/src/main/java/org/traccar/Context.java
+++ b/src/main/java/org/traccar/Context.java
@@ -25,14 +25,12 @@ import org.traccar.config.Config;
import org.traccar.config.Keys;
import org.traccar.database.BaseObjectManager;
import org.traccar.database.CalendarManager;
-import org.traccar.session.ConnectionManager;
import org.traccar.database.DataManager;
import org.traccar.database.DeviceManager;
import org.traccar.database.DriversManager;
import org.traccar.database.GeofenceManager;
import org.traccar.database.GroupsManager;
import org.traccar.database.IdentityManager;
-import org.traccar.database.LdapProvider;
import org.traccar.database.MailManager;
import org.traccar.database.MaintenancesManager;
import org.traccar.database.NotificationManager;
@@ -53,6 +51,7 @@ import org.traccar.model.User;
import org.traccar.notification.EventForwarder;
import org.traccar.notification.NotificatorManager;
import org.traccar.reports.model.TripsConfig;
+import org.traccar.session.ConnectionManager;
import org.traccar.sms.HttpSmsClient;
import org.traccar.sms.SmsManager;
import org.traccar.sms.SnsSmsClient;
@@ -94,12 +93,6 @@ public final class Context {
return dataManager;
}
- private static LdapProvider ldapProvider;
-
- public static LdapProvider getLdapProvider() {
- return ldapProvider;
- }
-
private static MailManager mailManager;
public static MailManager getMailManager() {
@@ -263,10 +256,6 @@ public final class Context {
dataManager = new DataManager(config);
}
- if (config.hasKey(Keys.LDAP_URL)) {
- ldapProvider = new LdapProvider(config);
- }
-
mailManager = new MailManager();
if (dataManager != null) {
diff --git a/src/main/java/org/traccar/MainModule.java b/src/main/java/org/traccar/MainModule.java
index 7b46656b3..15b9cefda 100644
--- a/src/main/java/org/traccar/MainModule.java
+++ b/src/main/java/org/traccar/MainModule.java
@@ -19,12 +19,12 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.inject.AbstractModule;
import com.google.inject.Provides;
import com.google.inject.Scopes;
-import com.google.inject.Singleton;
import io.netty.util.HashedWheelTimer;
import io.netty.util.Timer;
import org.traccar.config.Config;
import org.traccar.config.Keys;
import org.traccar.database.CalendarManager;
+import org.traccar.database.LdapProvider;
import org.traccar.session.ConnectionManager;
import org.traccar.database.DataManager;
import org.traccar.database.DeviceManager;
@@ -66,6 +66,7 @@ import org.traccar.speedlimit.SpeedLimitProvider;
import org.traccar.storage.Storage;
import javax.annotation.Nullable;
+import javax.inject.Singleton;
import javax.ws.rs.client.Client;
public class MainModule extends AbstractModule {
@@ -142,6 +143,15 @@ public class MainModule extends AbstractModule {
@Singleton
@Provides
+ public static LdapProvider provideLdapProvider(Config config) {
+ if (config.hasKey(Keys.LDAP_URL)) {
+ return new LdapProvider(config);
+ }
+ return null;
+ }
+
+ @Singleton
+ @Provides
public static Geocoder provideGeocoder(Config config) {
if (config.getBoolean(Keys.GEOCODER_ENABLE)) {
String type = config.getString(Keys.GEOCODER_TYPE, "google");
diff --git a/src/main/java/org/traccar/database/DataManager.java b/src/main/java/org/traccar/database/DataManager.java
index 1426daea3..29d70ec32 100644
--- a/src/main/java/org/traccar/database/DataManager.java
+++ b/src/main/java/org/traccar/database/DataManager.java
@@ -25,6 +25,7 @@ import liquibase.exception.LiquibaseException;
import liquibase.resource.FileSystemResourceAccessor;
import liquibase.resource.ResourceAccessor;
import org.traccar.Context;
+import org.traccar.Main;
import org.traccar.config.Config;
import org.traccar.config.Keys;
import org.traccar.model.BaseModel;
@@ -131,12 +132,12 @@ public class DataManager {
config.getString(Keys.DATABASE_DRIVER),
null, null, null, resourceAccessor);
- Liquibase liquibase = new Liquibase(
- config.getString(Keys.DATABASE_CHANGELOG), resourceAccessor, database);
+ String changelog = config.getString(Keys.DATABASE_CHANGELOG);
- liquibase.clearCheckSums();
-
- liquibase.update(new Contexts());
+ try (Liquibase liquibase = new Liquibase(changelog, resourceAccessor, database)) {
+ liquibase.clearCheckSums();
+ liquibase.update(new Contexts());
+ }
}
}
@@ -146,7 +147,7 @@ public class DataManager {
new Condition.Or(
new Condition.Equals("email", "email", email.trim()),
new Condition.Equals("login", "email"))));
- LdapProvider ldapProvider = Context.getLdapProvider();
+ LdapProvider ldapProvider = Main.getInjector().getInstance(LdapProvider.class);
if (user != null) {
if (ldapProvider != null && user.getLogin() != null && ldapProvider.login(user.getLogin(), password)
|| !forceLdap && user.isPasswordValid(password)) {
diff --git a/src/main/java/org/traccar/database/LdapProvider.java b/src/main/java/org/traccar/database/LdapProvider.java
index d659a11a1..d517294b8 100644
--- a/src/main/java/org/traccar/database/LdapProvider.java
+++ b/src/main/java/org/traccar/database/LdapProvider.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2017 - 2020 Anton Tananaev (anton@traccar.org)
+ * Copyright 2017 - 2022 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.