diff --git a/backend/pom.xml b/backend/pom.xml index 1604570..e0bbd02 100644 --- a/backend/pom.xml +++ b/backend/pom.xml @@ -6,7 +6,7 @@ com.wire.bots roman - 1.18.0 + 1.18.1 Roman Wire Bot API Proxy @@ -47,7 +47,7 @@ com.fasterxml.jackson.core jackson-databind - 2.13.3 + 2.13.4 io.jsonwebtoken @@ -104,7 +104,7 @@ org.mockito mockito-core - 2.23.4 + 4.8.0 test diff --git a/backend/src/main/java/com/wire/bots/roman/Application.java b/backend/src/main/java/com/wire/bots/roman/Application.java index 64d8e68..14b11e9 100644 --- a/backend/src/main/java/com/wire/bots/roman/Application.java +++ b/backend/src/main/java/com/wire/bots/roman/Application.java @@ -30,21 +30,14 @@ import com.wire.xenon.factories.CryptoFactory; import com.wire.xenon.factories.StorageFactory; import io.dropwizard.bundles.assets.ConfiguredAssetsBundle; -import io.dropwizard.bundles.redirect.PathRedirect; -import io.dropwizard.bundles.redirect.Redirect; -import io.dropwizard.server.DefaultServerFactory; import io.dropwizard.setup.Bootstrap; import io.dropwizard.setup.Environment; import io.dropwizard.util.Strings; import io.dropwizard.websockets.WebsocketBundle; import io.jsonwebtoken.security.Keys; -import org.apache.http.HttpHeaders; import org.eclipse.jetty.servlets.CrossOriginFilter; import javax.servlet.*; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; import java.security.Key; import java.util.EnumSet; import java.util.concurrent.ExecutorService; @@ -95,7 +88,7 @@ protected void initialize(Config config, Environment env) { this.config = config; this.key = Keys.hmacShaKeyFor(config.key.getBytes()); - if (!Strings.isNullOrEmpty(this.config.allowedCors)) { + if (!Tools.isNullOrEmpty(this.config.allowedCors)) { // Enable CORS headers final FilterRegistration.Dynamic cors = environment.servlets().addFilter("CORS", CrossOriginFilter.class); @@ -118,14 +111,6 @@ protected void onRun(Config config, Environment env) { ProviderClient providerClient = new ProviderClient(getClient(), config.apiHost); Sender sender = new Sender(getRepo()); - var rootPath = ((DefaultServerFactory) config.getServerFactory()).getJerseyRootPath().orElse(""); - rootPath = rootPath.endsWith("/") ? rootPath : rootPath + "/"; - var swaggerPath = rootPath + "swagger#/default"; - registerRedirects( - new PathRedirect("/swagger-ui", swaggerPath), - new PathRedirect("/swagger", swaggerPath) - ); - final var jdbi = getJdbi(); addResource(new ProviderResource(jdbi, providerClient)); addResource(new ServiceResource(jdbi, providerClient)); @@ -137,37 +122,6 @@ protected void onRun(Config config, Environment env) { messageHandler.setSender(sender); } - private void registerRedirects(PathRedirect... redirects) { - environment.servlets().addFilter("redirect", new Filter() { - @Override - public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) - throws IOException, ServletException { - if (req instanceof HttpServletRequest) { - HttpServletRequest request = (HttpServletRequest) req; - - for (Redirect redirect : redirects) { - String redirectUrl = redirect.getRedirect(request); - if (redirectUrl != null) { - HttpServletResponse response = (HttpServletResponse) res; - - response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY); - response.setHeader(HttpHeaders.LOCATION, redirectUrl); - return; - } - } - } - - chain.doFilter(req, res); - } - - @Override - public void destroy() { /* unused */ } - - @Override - public void init(FilterConfig filterConfig) { /* unused */ } - }).addMappingForUrlPatterns(null, false, "*"); - } - @Override protected ClientRepo createClientRepo() { StorageFactory storageFactory = getStorageFactory(); diff --git a/backend/src/main/java/com/wire/bots/roman/Tools.java b/backend/src/main/java/com/wire/bots/roman/Tools.java index 3b70f5f..421f381 100644 --- a/backend/src/main/java/com/wire/bots/roman/Tools.java +++ b/backend/src/main/java/com/wire/bots/roman/Tools.java @@ -2,6 +2,7 @@ import io.jsonwebtoken.Jwts; +import javax.annotation.Nullable; import java.nio.charset.StandardCharsets; import java.util.Base64; import java.util.Date; @@ -39,4 +40,8 @@ public static String decodeBase64(final String base64String) { byte[] keyBytes = Base64.getDecoder().decode(base64String); return new String(keyBytes, StandardCharsets.UTF_8); } + + public static boolean isNullOrEmpty(@Nullable String string) { + return string == null || string.isEmpty(); + } }