You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by mm...@apache.org on 2021/03/18 15:11:28 UTC
[syncope] branch master updated: Auto-configure session tracking
modes (#247)
This is an automated email from the ASF dual-hosted git repository.
mmoayyed pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/syncope.git
The following commit(s) were added to refs/heads/master by this push:
new f37a931 Auto-configure session tracking modes (#247)
f37a931 is described below
commit f37a93139370ec0c0752d5b901a0bb33b1b16a37
Author: Misagh Moayyed <mi...@gmail.com>
AuthorDate: Thu Mar 18 18:41:16 2021 +0330
Auto-configure session tracking modes (#247)
---
.../syncope/wa/starter/SyncopeWAApplication.java | 24 +++++++++++++++++++++-
.../apache/syncope/wa/starter/AbstractTest.java | 5 +++++
2 files changed, 28 insertions(+), 1 deletion(-)
diff --git a/wa/starter/src/main/java/org/apache/syncope/wa/starter/SyncopeWAApplication.java b/wa/starter/src/main/java/org/apache/syncope/wa/starter/SyncopeWAApplication.java
index f5bad0e..7aa8a93 100644
--- a/wa/starter/src/main/java/org/apache/syncope/wa/starter/SyncopeWAApplication.java
+++ b/wa/starter/src/main/java/org/apache/syncope/wa/starter/SyncopeWAApplication.java
@@ -45,10 +45,12 @@ import org.springframework.boot.autoconfigure.jersey.JerseyAutoConfiguration;
import org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration;
import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
+import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
+import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.event.EventListener;
@@ -56,10 +58,15 @@ import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;
import org.springframework.transaction.annotation.EnableTransactionManagement;
+import org.springframework.web.WebApplicationInitializer;
+
+import javax.servlet.SessionTrackingMode;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;
+import java.util.Set;
+import java.util.stream.Collectors;
@PropertySource("classpath:wa.properties")
@PropertySource(value = "file:${conf.directory}/wa.properties", ignoreResourceNotFound = true)
@@ -77,7 +84,7 @@ import java.util.Date;
DataSourceTransactionManagerAutoConfiguration.class,
RedisRepositoriesAutoConfiguration.class
})
-@EnableConfigurationProperties(CasConfigurationProperties.class)
+@EnableConfigurationProperties({CasConfigurationProperties.class, ServerProperties.class})
@EnableAsync
@EnableAspectJAutoProxy(proxyTargetClass = true)
@EnableTransactionManagement(proxyTargetClass = true)
@@ -89,6 +96,9 @@ public class SyncopeWAApplication extends SpringBootServletInitializer {
@Autowired
private SchedulerFactoryBean scheduler;
+ @Autowired
+ private ServerProperties serverProperties;
+
@Value("${contextRefreshDelay:15}")
private long contextRefreshDelay;
@@ -111,6 +121,18 @@ public class SyncopeWAApplication extends SpringBootServletInitializer {
scheduleJobToRefreshContext();
}
+ @Bean
+ public WebApplicationInitializer syncopeWebApplicationInitializer() {
+ return servletContext -> {
+ Set<SessionTrackingMode> trackingModes = serverProperties.getServlet().getSession().getTrackingModes().
+ stream().
+ map(mode -> SessionTrackingMode.valueOf(mode.name())).
+ collect(Collectors.toSet());
+ servletContext.setSessionTrackingModes(trackingModes);
+ LOG.debug("Set session tracking modes to {}", trackingModes);
+ };
+ }
+
private void scheduleJobToRefreshContext() {
try {
Date date = Date.from(LocalDateTime.now().plusSeconds(this.contextRefreshDelay).
diff --git a/wa/starter/src/test/java/org/apache/syncope/wa/starter/AbstractTest.java b/wa/starter/src/test/java/org/apache/syncope/wa/starter/AbstractTest.java
index ff336c0..0c80241 100644
--- a/wa/starter/src/test/java/org/apache/syncope/wa/starter/AbstractTest.java
+++ b/wa/starter/src/test/java/org/apache/syncope/wa/starter/AbstractTest.java
@@ -19,9 +19,13 @@
package org.apache.syncope.wa.starter;
import java.util.UUID;
+
+import org.springframework.boot.autoconfigure.web.ServerProperties;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.boot.web.server.LocalServerPort;
+import org.springframework.boot.web.servlet.server.Session;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.test.context.ContextConfiguration;
@@ -35,6 +39,7 @@ import org.springframework.test.context.ContextConfiguration;
"cas.sso.allow-missing-service-parameter=true"
})
@ContextConfiguration(initializers = ZookeeperTestingServer.class)
+@EnableConfigurationProperties(ServerProperties.class)
public abstract class AbstractTest {
@LocalServerPort
- -
T o u n s u b s c r i b e , e m a i l c o m m i t s - u n s u b s c r i b e @ s y n c o p e . a p a c h e . o r g