Adapt to spring-session-core and its changes
* Chief artifact changed maven coordinates * `SessionRepository` API changed
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -430,7 +430,7 @@
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.session</groupId>
|
||||
<artifactId>spring-session</artifactId>
|
||||
<artifactId>spring-session-core</artifactId>
|
||||
<version>${spring-session.version}</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
@@ -71,6 +71,7 @@ public class MongoOperationsSessionRepository
|
||||
this.mongoOperations = mongoOperations;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MongoSession createSession() {
|
||||
|
||||
MongoSession session = new MongoSession();
|
||||
@@ -82,13 +83,15 @@ public class MongoOperationsSessionRepository
|
||||
return session;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(MongoSession session) {
|
||||
|
||||
DBObject sessionDbObject = convertToDBObject(session);
|
||||
this.mongoOperations.save(sessionDbObject, this.collectionName);
|
||||
}
|
||||
|
||||
public MongoSession getSession(String id) {
|
||||
@Override
|
||||
public MongoSession findById(String id) {
|
||||
|
||||
Document sessionWrapper = findSession(id);
|
||||
|
||||
@@ -99,7 +102,7 @@ public class MongoOperationsSessionRepository
|
||||
MongoSession session = convertToSession(sessionWrapper);
|
||||
|
||||
if (session.isExpired()) {
|
||||
delete(id);
|
||||
deleteById(id);
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -115,6 +118,7 @@ public class MongoOperationsSessionRepository
|
||||
* @param indexValue the value of the index to search for.
|
||||
* @return sessions map
|
||||
*/
|
||||
@Override
|
||||
public Map<String, MongoSession> findByIndexNameAndIndexValue(String indexName, String indexValue) {
|
||||
|
||||
HashMap<String, MongoSession> result = new HashMap<String, MongoSession>();
|
||||
@@ -135,7 +139,8 @@ public class MongoOperationsSessionRepository
|
||||
return result;
|
||||
}
|
||||
|
||||
public void delete(String id) {
|
||||
@Override
|
||||
public void deleteById(String id) {
|
||||
this.mongoOperations.remove(findSession(id), this.collectionName);
|
||||
}
|
||||
|
||||
|
||||
@@ -121,7 +121,7 @@ public class MongoOperationsSessionRepositoryTest {
|
||||
TypeDescriptor.valueOf(MongoSession.class))).willReturn(session);
|
||||
|
||||
// when
|
||||
MongoSession retrievedSession = this.repository.getSession(sessionId);
|
||||
MongoSession retrievedSession = this.repository.findById(sessionId);
|
||||
|
||||
// then
|
||||
assertThat(retrievedSession).isEqualTo(session);
|
||||
@@ -143,7 +143,7 @@ public class MongoOperationsSessionRepositoryTest {
|
||||
TypeDescriptor.valueOf(MongoSession.class))).willReturn(session);
|
||||
|
||||
// when
|
||||
this.repository.getSession(sessionId);
|
||||
this.repository.findById(sessionId);
|
||||
|
||||
// then
|
||||
verify(this.mongoOperations).remove(any(Document.class),
|
||||
@@ -161,7 +161,7 @@ public class MongoOperationsSessionRepositoryTest {
|
||||
eq(MongoOperationsSessionRepository.DEFAULT_COLLECTION_NAME))).willReturn(sessionDocument);
|
||||
|
||||
// when
|
||||
this.repository.delete(sessionId);
|
||||
this.repository.deleteById(sessionId);
|
||||
|
||||
// then
|
||||
verify(this.mongoOperations).remove(any(Document.class),
|
||||
|
||||
@@ -79,17 +79,17 @@ abstract public class AbstractMongoRepositoryITest extends AbstractITest {
|
||||
|
||||
this.repository.save(toSave);
|
||||
|
||||
Session session = this.repository.getSession(toSave.getId());
|
||||
Session session = this.repository.findById(toSave.getId());
|
||||
|
||||
assertThat(session.getId()).isEqualTo(toSave.getId());
|
||||
assertThat(session.getAttributeNames()).isEqualTo(toSave.getAttributeNames());
|
||||
assertThat(session.<String>getAttribute(expectedAttributeName))
|
||||
.isEqualTo(toSave.getAttribute(expectedAttributeName));
|
||||
|
||||
this.repository.delete(toSave.getId());
|
||||
this.repository.deleteById(toSave.getId());
|
||||
|
||||
String id = toSave.getId();
|
||||
assertThat(this.repository.getSession(id)).isNull();
|
||||
assertThat(this.repository.findById(id)).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -99,19 +99,19 @@ abstract public class AbstractMongoRepositoryITest extends AbstractITest {
|
||||
toSave.setAttribute("a", "b");
|
||||
|
||||
this.repository.save(toSave);
|
||||
toSave = this.repository.getSession(toSave.getId());
|
||||
toSave = this.repository.findById(toSave.getId());
|
||||
|
||||
toSave.setAttribute("1", "2");
|
||||
|
||||
this.repository.save(toSave);
|
||||
toSave = this.repository.getSession(toSave.getId());
|
||||
toSave = this.repository.findById(toSave.getId());
|
||||
|
||||
Session session = this.repository.getSession(toSave.getId());
|
||||
Session session = this.repository.findById(toSave.getId());
|
||||
assertThat(session.getAttributeNames().size()).isEqualTo(2);
|
||||
assertThat(session.<String>getAttribute("a")).isEqualTo(Optional.of("b"));
|
||||
assertThat(session.<String>getAttribute("1")).isEqualTo(Optional.of("2"));
|
||||
|
||||
this.repository.delete(toSave.getId());
|
||||
this.repository.deleteById(toSave.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -129,7 +129,7 @@ abstract public class AbstractMongoRepositoryITest extends AbstractITest {
|
||||
assertThat(findByPrincipalName).hasSize(1);
|
||||
assertThat(findByPrincipalName.keySet()).containsOnly(toSave.getId());
|
||||
|
||||
this.repository.delete(toSave.getId());
|
||||
this.repository.deleteById(toSave.getId());
|
||||
|
||||
findByPrincipalName = this.repository.findByIndexNameAndIndexValue(INDEX_NAME,
|
||||
principalName);
|
||||
@@ -168,7 +168,7 @@ abstract public class AbstractMongoRepositoryITest extends AbstractITest {
|
||||
|
||||
this.repository.save(toSave);
|
||||
|
||||
toSave = this.repository.getSession(toSave.getId());
|
||||
toSave = this.repository.findById(toSave.getId());
|
||||
|
||||
toSave.setAttribute("other", "value");
|
||||
this.repository.save(toSave);
|
||||
@@ -231,7 +231,7 @@ abstract public class AbstractMongoRepositoryITest extends AbstractITest {
|
||||
|
||||
this.repository.save(toSave);
|
||||
|
||||
MongoSession getSession = this.repository.getSession(toSave.getId());
|
||||
MongoSession getSession = this.repository.findById(toSave.getId());
|
||||
getSession.setAttribute(INDEX_NAME, null);
|
||||
this.repository.save(getSession);
|
||||
|
||||
@@ -251,7 +251,7 @@ abstract public class AbstractMongoRepositoryITest extends AbstractITest {
|
||||
|
||||
this.repository.save(toSave);
|
||||
|
||||
MongoSession getSession = this.repository.getSession(toSave.getId());
|
||||
MongoSession getSession = this.repository.findById(toSave.getId());
|
||||
|
||||
getSession.setAttribute(INDEX_NAME, principalNameChanged);
|
||||
this.repository.save(getSession);
|
||||
@@ -281,7 +281,7 @@ abstract public class AbstractMongoRepositoryITest extends AbstractITest {
|
||||
assertThat(findByPrincipalName).hasSize(1);
|
||||
assertThat(findByPrincipalName.keySet()).containsOnly(toSave.getId());
|
||||
|
||||
this.repository.delete(toSave.getId());
|
||||
this.repository.deleteById(toSave.getId());
|
||||
|
||||
findByPrincipalName = this.repository.findByIndexNameAndIndexValue(INDEX_NAME,
|
||||
getSecurityName());
|
||||
@@ -355,7 +355,7 @@ abstract public class AbstractMongoRepositoryITest extends AbstractITest {
|
||||
|
||||
this.repository.save(toSave);
|
||||
|
||||
MongoSession getSession = this.repository.getSession(toSave.getId());
|
||||
MongoSession getSession = this.repository.findById(toSave.getId());
|
||||
|
||||
getSession.setAttribute(SPRING_SECURITY_CONTEXT, this.changedContext);
|
||||
this.repository.save(getSession);
|
||||
@@ -382,7 +382,7 @@ abstract public class AbstractMongoRepositoryITest extends AbstractITest {
|
||||
|
||||
// then
|
||||
MongoSession expiredSessionFromDb = this.repository
|
||||
.getSession(expiredSession.getId());
|
||||
.findById(expiredSession.getId());
|
||||
assertThat(expiredSessionFromDb).isNull();
|
||||
}
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ public class MongoRepositoryJdkSerializationITest extends AbstractMongoRepositor
|
||||
|
||||
this.repository.save(toSave);
|
||||
|
||||
MongoSession getSession = this.repository.getSession(toSave.getId());
|
||||
MongoSession getSession = this.repository.findById(toSave.getId());
|
||||
getSession.setAttribute(INDEX_NAME, null);
|
||||
this.repository.save(getSession);
|
||||
|
||||
@@ -66,7 +66,7 @@ public class MongoRepositoryJdkSerializationITest extends AbstractMongoRepositor
|
||||
|
||||
this.repository.save(toSave);
|
||||
|
||||
toSave = this.repository.getSession(toSave.getId());
|
||||
toSave = this.repository.findById(toSave.getId());
|
||||
|
||||
toSave.setAttribute("other", "value");
|
||||
this.repository.save(toSave);
|
||||
|
||||
Reference in New Issue
Block a user