diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2017-11-11 18:40:40 +1300 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2017-11-11 18:40:40 +1300 |
commit | 1908351b442732acc375397648a6834f09c0d9c4 (patch) | |
tree | 9814b1273b991ebe9831c53482cd083bcb149661 /src/org/traccar/database/DataManager.java | |
parent | 204b1074ee57960775066c7c483d54bab8ebf279 (diff) | |
download | traccar-server-1908351b442732acc375397648a6834f09c0d9c4.tar.gz traccar-server-1908351b442732acc375397648a6834f09c0d9c4.tar.bz2 traccar-server-1908351b442732acc375397648a6834f09c0d9c4.zip |
Implement LDAP authentication
Diffstat (limited to 'src/org/traccar/database/DataManager.java')
-rw-r--r-- | src/org/traccar/database/DataManager.java | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/src/org/traccar/database/DataManager.java b/src/org/traccar/database/DataManager.java index e88ff7f0d..f71e3e538 100644 --- a/src/org/traccar/database/DataManager.java +++ b/src/org/traccar/database/DataManager.java @@ -40,6 +40,7 @@ import liquibase.resource.FileSystemResourceAccessor; import liquibase.resource.ResourceAccessor; import org.traccar.Config; +import org.traccar.Context; import org.traccar.helper.Log; import org.traccar.model.Attribute; import org.traccar.model.Device; @@ -300,11 +301,23 @@ public class DataManager { User user = QueryBuilder.create(dataSource, getQuery("database.loginUser")) .setString("email", email.trim()) .executeQuerySingle(User.class); - if (user != null && user.isPasswordValid(password)) { - return user; + LdapProvider ldapProvider = Context.getLdapProvider(); + if (user != null) { + if (ldapProvider != null && ldapProvider.login(user.getLogin(), password) + || user.isPasswordValid(password)) { + return user; + } } else { - return null; + if (ldapProvider != null && ldapProvider.login(email, password)) { + user = new User(); + user.setName(email); + user.setEmail(email); + user.setLogin(email); + Context.getUsersManager().addItem(user); + return user; + } } + return null; } public void updateDeviceStatus(Device device) throws SQLException { |