Commit 4597aa08 authored by Daniel Gerhardt's avatar Daniel Gerhardt

Improve proxy path handling for API

* Automatically append /v2 to `apiPath` in legacy config.
* Renamed `api.path` config property to `api.proxy-path`.
* `api.proxy-path` is not set by default.
parent 89eeea06
......@@ -134,10 +134,17 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
final ServletContext servletContext) {
this.providerProperties = authenticationProviderProperties;
this.rootUrl = systemProperties.getRootUrl();
this.apiPath = systemProperties.getApi().getPath();
this.apiPath = systemProperties.getApi().getProxyPath();
this.servletContext = servletContext;
}
@PostConstruct
private void init() {
if (apiPath == null || "".equals(apiPath)) {
apiPath = servletContext.getContextPath();
}
}
public class HttpSecurityConfig extends WebSecurityConfigurerAdapter {
protected AuthenticationEntryPoint authenticationEntryPoint;
protected AccessDeniedHandler accessDeniedHandler;
......@@ -242,13 +249,6 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
}
}
@PostConstruct
private void init() {
if ("".equals(apiPath)) {
apiPath = servletContext.getContextPath();
}
}
@Override
protected void configure(final AuthenticationManagerBuilder auth) throws Exception {
final List<String> providers = new ArrayList<>();
......
......@@ -25,16 +25,16 @@ public class SystemProperties {
public static final String PREFIX = "system";
public static class Api {
private String path;
private String proxyPath;
private boolean indentResponseBody;
private boolean exposeErrorMessages;
public String getPath() {
return path;
public String getProxyPath() {
return proxyPath;
}
public void setPath(final String path) {
this.path = path;
public void setProxyPath(final String proxyPath) {
this.proxyPath = proxyPath;
}
public boolean isIndentResponseBody() {
......
......@@ -24,6 +24,7 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import javax.annotation.PostConstruct;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
......@@ -113,10 +114,7 @@ public class AuthenticationController extends AbstractController {
public AuthenticationController(final SystemProperties systemProperties,
final AuthenticationProviderProperties authenticationProviderProperties) {
apiPath = systemProperties.getApi().getPath();
if ("".equals(apiPath)) {
apiPath = servletContext.getContextPath();
}
apiPath = systemProperties.getApi().getProxyPath();
guestProperties = authenticationProviderProperties.getGuest();
registeredProperties = authenticationProviderProperties.getRegistered();
ldapProperties = authenticationProviderProperties.getLdap();
......@@ -125,6 +123,13 @@ public class AuthenticationController extends AbstractController {
oauthProperties = authenticationProviderProperties.getOauth();
}
@PostConstruct
private void init() {
if (apiPath == null || "".equals(apiPath)) {
apiPath = servletContext.getContextPath();
}
}
@PostMapping({ "/login", "/doLogin" })
public void doLogin(
@RequestParam("type") final String type,
......@@ -256,7 +261,7 @@ public class AuthenticationController extends AbstractController {
final List<ServiceDescription> services = new ArrayList<>();
/* The first parameter is replaced by the backend, the second one by the frondend */
final String dialogUrl = apiPath + "/auth/dialog?type={0}&successurl='{0}'";
final String dialogUrl = apiPath + "/v2/auth/dialog?type={0}&successurl='{0}'";
if (guestProperties.isEnabled()) {
final ServiceDescription sdesc = new ServiceDescription(
......
......@@ -20,6 +20,8 @@ package de.thm.arsnova.controller.v2;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.PostConstruct;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -43,6 +45,7 @@ public class ConfigurationController extends AbstractController {
private static final Logger logger = LoggerFactory
.getLogger(ConfigurationController.class);
private ServletContext servletContext;
private String apiPath;
private String socketioPath;
......@@ -156,9 +159,17 @@ public class ConfigurationController extends AbstractController {
@Value("${features.content-pool.session-levels.en}")
private String ppLevelsEn;
public ConfigurationController(final SystemProperties systemProperties) {
apiPath = systemProperties.getApi().getPath();
public ConfigurationController(final SystemProperties systemProperties, final ServletContext servletContext) {
apiPath = systemProperties.getApi().getProxyPath();
socketioPath = systemProperties.getSocketio().getProxyPath();
this.servletContext = servletContext;
}
@PostConstruct
private void init() {
if (apiPath == null || "".equals(apiPath)) {
apiPath = servletContext.getContextPath();
}
}
@GetMapping
......@@ -169,12 +180,7 @@ public class ConfigurationController extends AbstractController {
final Map<String, String> publicPool = new HashMap<>();
final Map<String, Object> splashscreen = new HashMap<>();
/* The API path could be unknown to the client in case the request was forwarded */
if ("".equals(apiPath)) {
apiPath = request.getContextPath();
}
config.put("apiPath", apiPath);
config.put("apiPath", apiPath + "/v2");
if (!"".equals(socketioPath)) {
config.put("socketioPath", socketioPath);
......
......@@ -12,7 +12,7 @@ arsnova:
# the backend behind a proxy server, you might need to set this path
# manually.
api:
path: /api
proxy-path: ~
# Database
couchdb:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment