Skip to content

Commit 9a269ac

Browse files
committed
switch to Controller-based redirect for root to /manager
1 parent d8793a9 commit 9a269ac

File tree

5 files changed

+47
-40
lines changed

5 files changed

+47
-40
lines changed

src/main/java/de/rwth/idsg/steve/JettyServer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ private void prepare() {
9999
}
100100

101101
steveAppContext = new SteveAppContext();
102-
server.setHandler(steveAppContext.getHandlers());
102+
server.setHandler(steveAppContext.getHandler());
103103
}
104104

105105
private ServerConnector httpConnector(HttpConfiguration httpConfig) {

src/main/java/de/rwth/idsg/steve/SteveAppContext.java

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,11 @@
1919
package de.rwth.idsg.steve;
2020

2121
import org.eclipse.jetty.ee10.webapp.WebAppContext;
22-
import org.eclipse.jetty.rewrite.handler.RedirectPatternRule;
23-
import org.eclipse.jetty.rewrite.handler.RewriteHandler;
2422
import org.eclipse.jetty.server.Handler;
25-
import org.eclipse.jetty.server.handler.ContextHandler;
26-
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
2723
import org.eclipse.jetty.server.handler.gzip.GzipHandler;
2824
import org.springframework.core.io.ClassPathResource;
2925

3026
import java.io.IOException;
31-
import java.util.HashSet;
3227

3328
import static de.rwth.idsg.steve.SteveConfiguration.CONFIG;
3429

@@ -65,11 +60,8 @@ public SteveAppContext() {
6560
webAppContext.setAttribute("org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern", SCAN_PATTERN);
6661
}
6762

68-
public ContextHandlerCollection getHandlers() {
69-
return new ContextHandlerCollection(
70-
new ContextHandler(getRedirectHandler()),
71-
new ContextHandler(getWebApp())
72-
);
63+
public Handler getHandler() {
64+
return getWebApp();
7365
}
7466

7567
private Handler getWebApp() {
@@ -82,34 +74,6 @@ private Handler getWebApp() {
8274
return new GzipHandler(webAppContext);
8375
}
8476

85-
private Handler getRedirectHandler() {
86-
RewriteHandler rewrite = new RewriteHandler();
87-
for (String redirect : getRedirectSet()) {
88-
RedirectPatternRule rule = new RedirectPatternRule();
89-
rule.setTerminating(true);
90-
rule.setPattern(redirect);
91-
rule.setLocation(CONFIG.getContextPath() + "/manager/home");
92-
rewrite.addRule(rule);
93-
}
94-
return rewrite;
95-
}
96-
97-
private HashSet<String> getRedirectSet() {
98-
String path = CONFIG.getContextPath();
99-
100-
HashSet<String> redirectSet = new HashSet<>(3);
101-
redirectSet.add("");
102-
redirectSet.add(path + "");
103-
104-
// Otherwise (if path = ""), we would already be at root of the server ("/")
105-
// and using the redirection below would cause an infinite loop.
106-
if (!"".equals(path)) {
107-
redirectSet.add(path + "/");
108-
}
109-
110-
return redirectSet;
111-
}
112-
11377
private static String getWebAppURIAsString() {
11478
try {
11579
return new ClassPathResource("webapp").getURI().toString();

src/main/java/de/rwth/idsg/steve/config/ApiDocsConfiguration.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,12 @@
3131
import org.springdoc.core.properties.SwaggerUiOAuthProperties;
3232
import org.springdoc.webmvc.core.configuration.SpringDocWebMvcConfiguration;
3333
import org.springdoc.webmvc.ui.SwaggerConfig;
34+
import org.springdoc.webmvc.ui.SwaggerUiHome;
3435
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
3536
import org.springframework.context.annotation.Bean;
3637
import org.springframework.context.annotation.ComponentScan;
3738
import org.springframework.context.annotation.Configuration;
39+
import org.springframework.context.annotation.FilterType;
3840
import org.springframework.context.annotation.Import;
3941

4042
import java.util.List;
@@ -46,7 +48,10 @@
4648
* @since 15.09.2022
4749
*/
4850
@Configuration
49-
@ComponentScan(basePackages = {"org.springdoc"})
51+
@ComponentScan(basePackages = {"org.springdoc"},
52+
// exclude because SwaggerUiHome's root redirect clashes with our own RootRedirectController
53+
excludeFilters = @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = SwaggerUiHome.class)
54+
)
5055
@Import({SpringDocConfiguration.class,
5156
SpringDocWebMvcConfiguration.class,
5257
SwaggerConfig.class,

src/main/java/de/rwth/idsg/steve/config/SecurityConfiguration.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
6464
.authorizeHttpRequests(
6565
req -> req
6666
.requestMatchers(
67+
"/", // we have RootRedirectController to redirect "/" to "/manager"
6768
"/static/**",
6869
CONFIG.getCxfMapping() + "/**",
6970
WebSocketConfiguration.PATH_INFIX + "**",
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* SteVe - SteckdosenVerwaltung - https://github.com/steve-community/steve
3+
* Copyright (C) 2013-2025 SteVe Community Team
4+
* All Rights Reserved.
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
18+
*/
19+
package de.rwth.idsg.steve.web.controller;
20+
21+
import org.springframework.stereotype.Controller;
22+
import org.springframework.web.bind.annotation.GetMapping;
23+
import org.springframework.web.bind.annotation.RequestMapping;
24+
25+
/**
26+
* @author Sevket Goekay <[email protected]>
27+
* @since 17.09.2025
28+
*/
29+
@Controller
30+
@RequestMapping("/")
31+
public class RootRedirectController {
32+
33+
@GetMapping
34+
public String redirectToManager() {
35+
return "redirect:/manager";
36+
}
37+
}

0 commit comments

Comments
 (0)