11/**
22 * ContainerProxy
33 *
4- * Copyright (C) 2016-2020 Open Analytics
4+ * Copyright (C) 2016-2021 Open Analytics
55 *
66 * ===========================================================================
77 *
3131import org .springframework .boot .actuate .health .HealthIndicator ;
3232import org .springframework .boot .actuate .redis .RedisHealthIndicator ;
3333import org .springframework .boot .autoconfigure .SpringBootApplication ;
34+ import org .springframework .boot .autoconfigure .condition .ConditionalOnProperty ;
3435import org .springframework .boot .web .embedded .undertow .UndertowServletWebServerFactory ;
3536import org .springframework .boot .web .server .PortInUseException ;
3637import org .springframework .boot .web .servlet .FilterRegistrationBean ;
3738import org .springframework .context .annotation .Bean ;
3839import org .springframework .context .annotation .ComponentScan ;
3940import org .springframework .core .env .Environment ;
4041import org .springframework .data .redis .connection .RedisConnectionFactory ;
41- import org .springframework .session .data .redis .config .ConfigureRedisAction ;
42+ import org .springframework .security .core .session .SessionRegistry ;
43+ import org .springframework .security .web .session .HttpSessionEventPublisher ;
44+ import org .springframework .session .FindByIndexNameSessionRepository ;
45+ import org .springframework .session .Session ;
46+ import org .springframework .session .web .http .DefaultCookieSerializer ;
47+ import org .springframework .session .security .SpringSessionBackedSessionRegistry ;
4248import org .springframework .web .filter .FormContentFilter ;
4349
4450import javax .annotation .PostConstruct ;
@@ -62,6 +68,9 @@ public class ContainerProxyApplication {
6268 @ Inject
6369 private ProxyMappingManager mappingManager ;
6470
71+ @ Inject
72+ private DefaultCookieSerializer defaultCookieSerializer ;
73+
6574 private final Logger log = LogManager .getLogger (getClass ());
6675
6776 public static void main (String [] args ) {
@@ -86,8 +95,12 @@ public static void main(String[] args) {
8695 @ PostConstruct
8796 public void init () {
8897 if (environment .getProperty ("server.use-forward-headers" ) != null ) {
89- log .warn ("WARNING: Using server.use-forward-headers will not work in this ShinyProxy release. See https://shinyproxy.io/documentation/security/#https-ssl--tls on how to change your configuration." );
98+ 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." );
9099 }
100+
101+ String sameSiteCookie = environment .getProperty ("proxy.same-site-cookie" , "Lax" );
102+ log .debug ("Setting sameSiteCookie policy to {}" , sameSiteCookie );
103+ defaultCookieSerializer .setSameSite (sameSiteCookie );
91104 }
92105
93106 @ Bean
@@ -134,16 +147,6 @@ public JSR353Module jsr353Module() {
134147 return new JSR353Module ();
135148 }
136149
137- /**
138- * Compatibility with AWS ElastiCache
139- *
140- * @return
141- */
142- @ Bean
143- public static ConfigureRedisAction configureRedisAction () {
144- return ConfigureRedisAction .NO_OP ;
145- }
146-
147150 @ Bean
148151 public HealthIndicator redisSessionHealthIndicator (RedisConnectionFactory rdeRedisConnectionFactory ) {
149152 if (Objects .equals (environment .getProperty ("spring.session.store-type" ), "redis" )) {
@@ -166,11 +169,27 @@ public Health health() {
166169 }
167170 }
168171
172+ /**
173+ * This Bean ensures that User Session are properly expired when using Redis for session storage.
174+ */
175+ @ Bean
176+ @ ConditionalOnProperty (name = "spring.session.store-type" , havingValue = "redis" )
177+ public <S extends Session > SessionRegistry sessionRegistry (FindByIndexNameSessionRepository <S > sessionRepository ) {
178+ return new SpringSessionBackedSessionRegistry <S >(sessionRepository );
179+ }
180+
181+ @ Bean
182+ public HttpSessionEventPublisher httpSessionEventPublisher () {
183+ return new HttpSessionEventPublisher ();
184+ }
185+
169186 private static void setDefaultProperties (SpringApplication app ) {
170187 Properties properties = new Properties ();
171188
172189 // use in-memory session storage by default. Can be overwritten in application.yml
173190 properties .put ("spring.session.store-type" , "none" );
191+ // required for proper working of the SP_USER_INITIATED_LOGOUT session attribute in the UserService
192+ properties .put ("spring.session.redis.flush-mode" , "IMMEDIATE" );
174193
175194 // disable multi-part handling by Spring. We don't need this anywhere in the application.
176195 // When enabled this will cause problems when proxying file-uploads to the shiny apps.
@@ -181,6 +200,22 @@ private static void setDefaultProperties(SpringApplication app) {
181200
182201 properties .put ("spring.application.name" , "ContainerProxy" );
183202
203+ // Metrics configuration
204+ // ====================
205+
206+ // disable all supported exporters by default
207+ // Note: if we upgrade to Spring Boot 2.4.0 we can use properties.put("management.metrics.export.defaults.enabled", "false");
208+ properties .put ("management.metrics.export.prometheus.enabled" , "false" );
209+ properties .put ("management.metrics.export.influx.enabled" , "false" );
210+ // set actuator to port 9090 (can be overwritten)
211+ properties .put ("management.server.port" , "9090" );
212+ // enable prometheus endpoint by default (but not the exporter)
213+ properties .put ("management.endpoint.prometheus.enabled" , "true" );
214+ // include prometheus and health endpoint in exposure
215+ properties .put ("management.endpoints.web.exposure.include" , "health,prometheus" );
216+
217+ // ====================
218+
184219 // Health configuration
185220 // ====================
186221
@@ -190,7 +225,7 @@ private static void setDefaultProperties(SpringApplication app) {
190225 properties .put ("management.health.ldap.enabled" , false );
191226 // disable default redis health endpoint since it's managed by redisSession
192227 properties .put ("management.health.redis.enabled" , "false" );
193- // enable Kubernetes porobes
228+ // enable Kubernetes probes
194229 properties .put ("management.endpoint.health.probes.enabled" , true );
195230
196231 // ====================
0 commit comments