Skip to content

Commit 15aa072

Browse files
committed
Merge pull request 'Improve properties' (#51) from bug/25757 into develop
2 parents 341ce28 + 3d46ee1 commit 15aa072

11 files changed

Lines changed: 32 additions & 31 deletions

src/main/java/eu/openanalytics/containerproxy/ContainerProxyApplication.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
package eu.openanalytics.containerproxy;
2222

2323
import com.fasterxml.jackson.datatype.jsr353.JSR353Module;
24-
import eu.openanalytics.containerproxy.service.AppRecoveryService;
2524
import eu.openanalytics.containerproxy.util.ProxyMappingManager;
2625
import io.undertow.Handlers;
26+
import io.undertow.server.handlers.SameSiteCookieHandler;
2727
import io.undertow.servlet.api.ServletSessionConfig;
2828
import io.undertow.servlet.api.SessionManagerFactory;
2929
import org.apache.logging.log4j.LogManager;
@@ -76,8 +76,8 @@ public class ContainerProxyApplication {
7676

7777
private final Logger log = LogManager.getLogger(getClass());
7878

79-
@Inject
80-
private AppRecoveryService appRecoveryService;
79+
private static final String PROP_PROXY_SAME_SITE_COOKIE = "proxy.same-site-cookie";
80+
private static final String SAME_SITE_COOKIE_DEFAULT_VALUE = "Lax";
8181

8282
public static void main(String[] args) {
8383
SpringApplication app = new SpringApplication(ContainerProxyApplication.class);
@@ -105,7 +105,7 @@ public void init() {
105105
log.warn("WARNING: Using server.use-forward-headers will not work in this ShinyProxy release, you need to change your configuration to use another property. See https://shinyproxy.io/documentation/security/#forward-headers on how to change your configuration.");
106106
}
107107

108-
String sameSiteCookie = environment.getProperty("proxy.same-site-cookie", "Lax");
108+
String sameSiteCookie = environment.getProperty(PROP_PROXY_SAME_SITE_COOKIE, SAME_SITE_COOKIE_DEFAULT_VALUE);
109109
log.debug("Setting sameSiteCookie policy to {}" , sameSiteCookie);
110110
defaultCookieSerializer.setSameSite(sameSiteCookie);
111111
}
@@ -118,15 +118,18 @@ public UndertowServletWebServerFactory servletContainer() {
118118
UndertowServletWebServerFactory factory = new UndertowServletWebServerFactory();
119119
factory.addDeploymentInfoCustomizers(info -> {
120120
info.setPreservePathOnForward(false); // required for the /api/route/{id}/ endpoint to work properly
121-
if (Boolean.valueOf(environment.getProperty("logging.requestdump", "false"))) {
122-
info.addOuterHandlerChainWrapper(defaultHandler -> Handlers.requestDump(defaultHandler));
121+
if (Boolean.parseBoolean(environment.getProperty("logging.requestdump", "false"))) {
122+
info.addOuterHandlerChainWrapper(Handlers::requestDump);
123123
}
124-
info.addInnerHandlerChainWrapper(defaultHandler -> {
125-
return mappingManager.createHttpHandler(defaultHandler);
126-
});
124+
info.addInnerHandlerChainWrapper(defaultHandler -> mappingManager.createHttpHandler(defaultHandler));
125+
126+
String sameSiteCookie = environment.getProperty(PROP_PROXY_SAME_SITE_COOKIE, SAME_SITE_COOKIE_DEFAULT_VALUE);
127+
log.debug("Setting sameSiteCookie policy for session cookies to {}" , sameSiteCookie);
128+
info.addOuterHandlerChainWrapper(defaultHandler -> new SameSiteCookieHandler(defaultHandler, sameSiteCookie, null, true, true, true));
129+
127130
ServletSessionConfig sessionConfig = new ServletSessionConfig();
128131
sessionConfig.setHttpOnly(true);
129-
sessionConfig.setSecure(Boolean.valueOf(environment.getProperty("server.secureCookies", "false")));
132+
sessionConfig.setSecure(Boolean.parseBoolean(environment.getProperty("server.secure-cookies", "false")));
130133
info.setServletSessionConfig(sessionConfig);
131134
if (sessionManagerFactory != null) {
132135
info.setSessionManagerFactory(sessionManagerFactory);

src/main/java/eu/openanalytics/containerproxy/security/WebSecurityConfig.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import org.springframework.context.annotation.Bean;
2929
import org.springframework.context.annotation.Configuration;
3030
import org.springframework.core.env.Environment;
31-
import org.springframework.http.HttpStatus;
3231
import org.springframework.security.access.AccessDeniedException;
3332
import org.springframework.security.authentication.AuthenticationEventPublisher;
3433
import org.springframework.security.authentication.AuthenticationManager;
@@ -42,7 +41,6 @@
4241
import org.springframework.security.web.access.AccessDeniedHandler;
4342
import org.springframework.security.web.access.AccessDeniedHandlerImpl;
4443
import org.springframework.security.web.authentication.www.BasicAuthenticationFilter;
45-
import org.springframework.security.web.csrf.InvalidCsrfTokenException;
4644
import org.springframework.security.web.csrf.MissingCsrfTokenException;
4745
import org.springframework.security.web.header.writers.StaticHeadersWriter;
4846
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
@@ -124,7 +122,7 @@ public void handle(HttpServletRequest request, HttpServletResponse response, Acc
124122
// Always set header: X-Content-Type-Options=nosniff
125123
http.headers().contentTypeOptions();
126124

127-
String frameOptions = environment.getProperty("server.frameOptions", "disable");
125+
String frameOptions = environment.getProperty("server.frame-options", "disable");
128126
switch (frameOptions.toUpperCase()) {
129127
case "DISABLE":
130128
http.headers().frameOptions().disable();

src/main/java/eu/openanalytics/containerproxy/service/AppRecoveryService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
@Service
5454
public class AppRecoveryService {
5555

56-
protected static final String PROPERTY_RECOVER_RUNNING_APPS = "proxy.recover_running_apps";
56+
protected static final String PROPERTY_RECOVER_RUNNING_PROXIES = "proxy.recover_running_proxies";
5757

5858
private final Logger log = LogManager.getLogger(AppRecoveryService.class);
5959

@@ -79,7 +79,7 @@ public class AppRecoveryService {
7979

8080
@EventListener(ApplicationReadyEvent.class)
8181
public void recoverRunningApps() throws Exception {
82-
if (Boolean.parseBoolean(environment.getProperty(PROPERTY_RECOVER_RUNNING_APPS, "false"))) {
82+
if (Boolean.parseBoolean(environment.getProperty(PROPERTY_RECOVER_RUNNING_PROXIES, "false"))) {
8383
log.info("Recovery of running apps enabled");
8484

8585
Map<String, Proxy> proxies = new HashMap();

src/main/java/eu/openanalytics/containerproxy/service/ProxyService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,11 @@ public class ProxyService {
106106

107107
private boolean stopAppsOnShutdown;
108108

109-
private static final String PROPERTY_STOP_APPS_ON_SHUTDOWN = "proxy.stop_apps_on_shutdown";
109+
private static final String PROPERTY_STOP_PROXIES_ON_SHUTDOWN = "proxy.stop_proxies_on_shutdown";
110110

111111
@PostConstruct
112112
public void init() {
113-
stopAppsOnShutdown = Boolean.parseBoolean(environment.getProperty(PROPERTY_STOP_APPS_ON_SHUTDOWN, "true"));
113+
stopAppsOnShutdown = Boolean.parseBoolean(environment.getProperty(PROPERTY_STOP_PROXIES_ON_SHUTDOWN, "true"));
114114
}
115115

116116
@PreDestroy

src/test/resources/application-app-recovery_docker-swarm.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
proxy:
2-
recover_running_apps: true
3-
stop_apps_on_shutdown: false
2+
recover_running_proxies: true
3+
stop_proxies_on_shutdown: false
44

55
authentication: simple
66
containerBackend: docker-swarm

src/test/resources/application-app-recovery_docker-swarm_2.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
proxy:
22
titlle: Yet Another Instance
3-
recover_running_apps: true
4-
stop_apps_on_shutdown: false
3+
recover_running_proxies: true
4+
stop_proxies_on_shutdown: false
55

66
authentication: simple
77
containerBackend: docker-swarm

src/test/resources/application-app-recovery_docker.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
proxy:
2-
recover_running_apps: true
3-
stop_apps_on_shutdown: false
2+
recover_running_proxies: true
3+
stop_proxies_on_shutdown: false
44

55
authentication: simple
66
container-backend: docker

src/test/resources/application-app-recovery_docker_2.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
proxy:
22
titlle: Yet Another Instance
3-
recover_running_apps: true
4-
stop_apps_on_shutdown: false
3+
recover_running_proxies: true
4+
stop_proxies_on_shutdown: false
55

66
authentication: simple
77
container-backend: docker

src/test/resources/application-app-recovery_kubernetes.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
proxy:
2-
recover_running_apps: true
3-
stop_apps_on_shutdown: false
2+
recover_running_proxies: true
3+
stop_proxies_on_shutdown: false
44

55
authentication: simple
66
container-backend: kubernetes

src/test/resources/application-app-recovery_kubernetes_2.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
proxy:
22
titlle: Yet Another Instance
3-
recover_running_apps: true
4-
stop_apps_on_shutdown: false
3+
recover_running_proxies: true
4+
stop_proxies_on_shutdown: false
55

66
authentication: simple
77
container-backend: kubernetes

0 commit comments

Comments
 (0)