aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar
diff options
context:
space:
mode:
authorDaniel <djr2468@gmail.com>2023-04-05 22:29:32 +0100
committerDaniel <djr2468@gmail.com>2023-04-05 22:29:32 +0100
commit88a56f29fff1ab252a2c415f0d44a22192dd6b66 (patch)
tree119d616817ca314057c31df6848ee633fe99b467 /src/main/java/org/traccar
parentc0dd2a6187de517af33aa92e0524414e65d973b4 (diff)
downloadtrackermap-server-88a56f29fff1ab252a2c415f0d44a22192dd6b66.tar.gz
trackermap-server-88a56f29fff1ab252a2c415f0d44a22192dd6b66.tar.bz2
trackermap-server-88a56f29fff1ab252a2c415f0d44a22192dd6b66.zip
Implement retrieveWebUrl
Diffstat (limited to 'src/main/java/org/traccar')
-rw-r--r--src/main/java/org/traccar/MainModule.java3
-rw-r--r--src/main/java/org/traccar/database/OpenIdProvider.java6
-rw-r--r--src/main/java/org/traccar/helper/WebHelper.java14
3 files changed, 17 insertions, 6 deletions
diff --git a/src/main/java/org/traccar/MainModule.java b/src/main/java/org/traccar/MainModule.java
index 41124bd03..6a2fe21c3 100644
--- a/src/main/java/org/traccar/MainModule.java
+++ b/src/main/java/org/traccar/MainModule.java
@@ -26,7 +26,6 @@ import com.google.inject.name.Names;
import io.netty.util.HashedWheelTimer;
import io.netty.util.Timer;
import org.apache.velocity.app.VelocityEngine;
-import org.eclipse.jetty.util.URIUtil;
import org.traccar.broadcast.BroadcastService;
import org.traccar.broadcast.MulticastBroadcastService;
import org.traccar.broadcast.NullBroadcastService;
@@ -96,9 +95,7 @@ import javax.inject.Singleton;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import java.io.IOException;
-import java.net.InetAddress;
import java.net.URISyntaxException;
-import java.net.UnknownHostException;
import java.net.http.HttpClient;
import java.util.Properties;
diff --git a/src/main/java/org/traccar/database/OpenIdProvider.java b/src/main/java/org/traccar/database/OpenIdProvider.java
index 6550a1278..d0ec4e98d 100644
--- a/src/main/java/org/traccar/database/OpenIdProvider.java
+++ b/src/main/java/org/traccar/database/OpenIdProvider.java
@@ -86,9 +86,9 @@ public class OpenIdProvider {
clientId = new ClientID(config.getString(Keys.OPENID_CLIENT_ID));
clientAuth = new ClientSecretBasic(clientId, new Secret(config.getString(Keys.OPENID_CLIENT_SECRET)));
- callbackUrl = new URI(config.getString(Keys.WEB_URL, "") + "/api/session/openid/callback");
- baseUrl = new URI(config.getString(Keys.WEB_URL, ""));
-
+ baseUrl = new URI(WebHelper.retrieveWebUrl(config));
+ callbackUrl = new URI(WebHelper.retrieveWebUrl(config) + "/api/session/openid/callback");
+
if (config.hasKey(Keys.OPENID_ISSUER_URL)) {
HttpRequest httpRequest = HttpRequest.newBuilder(
URI.create(config.getString(Keys.OPENID_ISSUER_URL) + "/.well-known/openid-configuration"))
diff --git a/src/main/java/org/traccar/helper/WebHelper.java b/src/main/java/org/traccar/helper/WebHelper.java
index 9c6547d8d..e2844bc4d 100644
--- a/src/main/java/org/traccar/helper/WebHelper.java
+++ b/src/main/java/org/traccar/helper/WebHelper.java
@@ -48,4 +48,18 @@ public final class WebHelper {
return null;
}
}
+
+ public static String retrieveWebUrl(Config config) {
+ if (config.hasKey(Keys.WEB_URL)) {
+ return config.getString(Keys.WEB_URL).replaceAll("/$", "");
+ } else {
+ String address;
+ try {
+ address = config.getString(Keys.WEB_ADDRESS, InetAddress.getLocalHost().getHostAddress());
+ } catch (UnknownHostException e) {
+ address = "localhost";
+ }
+ return URIUtil.newURI("http", address, config.getInteger(Keys.WEB_PORT), "", "");
+ }
+ }
}