Implement support for Spring Session's repository customiers.

Resolves #105.
This commit is contained in:
Greg Turnquist
2019-09-27 11:28:34 -05:00
parent ebac581036
commit 1c7d5e5d91
4 changed files with 92 additions and 0 deletions

View File

@@ -16,8 +16,11 @@
package org.springframework.session.data.mongo.config.annotation.web.http;
import java.time.Duration;
import java.util.List;
import java.util.stream.Collectors;
import org.springframework.beans.factory.BeanClassLoaderAware;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.EmbeddedValueResolverAware;
import org.springframework.context.annotation.Bean;
@@ -28,6 +31,7 @@ import org.springframework.core.serializer.support.DeserializingConverter;
import org.springframework.core.serializer.support.SerializingConverter;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.session.config.SessionRepositoryCustomizer;
import org.springframework.session.config.annotation.web.http.SpringHttpSessionConfiguration;
import org.springframework.session.data.mongo.AbstractMongoSessionConverter;
import org.springframework.session.data.mongo.JdkMongoSessionConverter;
@@ -51,6 +55,7 @@ public class MongoHttpSessionConfiguration extends SpringHttpSessionConfiguratio
private Integer maxInactiveIntervalInSeconds;
private String collectionName;
private StringValueResolver embeddedValueResolver;
private List<SessionRepositoryCustomizer<MongoIndexedSessionRepository>> sessionRepositoryCustomizers;
private ClassLoader classLoader;
@Bean
@@ -72,6 +77,9 @@ public class MongoHttpSessionConfiguration extends SpringHttpSessionConfiguratio
repository.setCollectionName(this.collectionName);
}
this.sessionRepositoryCustomizers
.forEach(sessionRepositoryCustomizer -> sessionRepositoryCustomizer.customize(repository));
return repository;
}
@@ -105,6 +113,12 @@ public class MongoHttpSessionConfiguration extends SpringHttpSessionConfiguratio
this.mongoSessionConverter = mongoSessionConverter;
}
@Autowired(required = false)
public void setSessionRepositoryCustomizers(
ObjectProvider<SessionRepositoryCustomizer<MongoIndexedSessionRepository>> sessionRepositoryCustomizers) {
this.sessionRepositoryCustomizers = sessionRepositoryCustomizers.orderedStream().collect(Collectors.toList());
}
@Override
public void setBeanClassLoader(ClassLoader classLoader) {
this.classLoader = classLoader;

View File

@@ -16,8 +16,11 @@
package org.springframework.session.data.mongo.config.annotation.web.reactive;
import java.time.Duration;
import java.util.List;
import java.util.stream.Collectors;
import org.springframework.beans.factory.BeanClassLoaderAware;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.EmbeddedValueResolverAware;
import org.springframework.context.annotation.Bean;
@@ -29,6 +32,7 @@ import org.springframework.core.serializer.support.SerializingConverter;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.data.mongodb.core.ReactiveMongoOperations;
import org.springframework.session.config.ReactiveSessionRepositoryCustomizer;
import org.springframework.session.config.annotation.web.server.SpringWebSessionConfiguration;
import org.springframework.session.data.mongo.AbstractMongoSessionConverter;
import org.springframework.session.data.mongo.JdkMongoSessionConverter;
@@ -50,6 +54,7 @@ public class ReactiveMongoWebSessionConfiguration extends SpringWebSessionConfig
private Integer maxInactiveIntervalInSeconds;
private String collectionName;
private StringValueResolver embeddedValueResolver;
private List<ReactiveSessionRepositoryCustomizer<ReactiveMongoSessionRepository>> sessionRepositoryCustomizers;
@Autowired(required = false) private MongoOperations mongoOperations;
private ClassLoader classLoader;
@@ -80,6 +85,9 @@ public class ReactiveMongoWebSessionConfiguration extends SpringWebSessionConfig
repository.setBlockingMongoOperations(this.mongoOperations);
}
this.sessionRepositoryCustomizers
.forEach(sessionRepositoryCustomizer -> sessionRepositoryCustomizer.customize(repository));
return repository;
}
@@ -132,4 +140,10 @@ public class ReactiveMongoWebSessionConfiguration extends SpringWebSessionConfig
public void setCollectionName(String collectionName) {
this.collectionName = collectionName;
}
@Autowired(required = false)
public void setSessionRepositoryCustomizers(
ObjectProvider<ReactiveSessionRepositoryCustomizer<ReactiveMongoSessionRepository>> sessionRepositoryCustomizers) {
this.sessionRepositoryCustomizers = sessionRepositoryCustomizers.orderedStream().collect(Collectors.toList());
}
}