Add Session.changeSessionId

This commit is contained in:
Rob Winch
2017-07-20 15:03:18 -05:00
parent 2aa71ffb6d
commit be2604ca69
29 changed files with 576 additions and 169 deletions

View File

@@ -455,6 +455,88 @@ public class RedisOperationsSessionRepositoryITests extends AbstractITests {
assertThat(findByPrincipalName.keySet()).containsOnly(toSave.getId());
}
@Test
public void changeSessionIdWhenOnlyChangeId() throws Exception {
String attrName = "changeSessionId";
String attrValue = "changeSessionId-value";
RedisSession toSave = this.repository.createSession();
toSave.setAttribute(attrName, attrValue);
this.repository.save(toSave);
RedisSession findById = this.repository.findById(toSave.getId());
assertThat(findById.<String>getAttribute(attrName)).isEqualTo(attrValue);
String originalFindById = findById.getId();
String changeSessionId = findById.changeSessionId();
this.repository.save(findById);
assertThat(this.repository.findById(originalFindById)).isNull();
RedisSession findByChangeSessionId = this.repository.findById(changeSessionId);
assertThat(findByChangeSessionId.<String>getAttribute(attrName)).isEqualTo(attrValue);
}
@Test
public void changeSessionIdWhenChangeTwice() throws Exception {
RedisSession toSave = this.repository.createSession();
this.repository.save(toSave);
String originalId = toSave.getId();
String changeId1 = toSave.changeSessionId();
String changeId2 = toSave.changeSessionId();
this.repository.save(toSave);
assertThat(this.repository.findById(originalId)).isNull();
assertThat(this.repository.findById(changeId1)).isNull();
assertThat(this.repository.findById(changeId2)).isNotNull();
}
@Test
public void changeSessionIdWhenSetAttributeOnChangedSession() throws Exception {
String attrName = "changeSessionId";
String attrValue = "changeSessionId-value";
RedisSession toSave = this.repository.createSession();
this.repository.save(toSave);
RedisSession findById = this.repository.findById(toSave.getId());
findById.setAttribute(attrName, attrValue);
String originalFindById = findById.getId();
String changeSessionId = findById.changeSessionId();
this.repository.save(findById);
assertThat(this.repository.findById(originalFindById)).isNull();
RedisSession findByChangeSessionId = this.repository.findById(changeSessionId);
assertThat(findByChangeSessionId.<String>getAttribute(attrName)).isEqualTo(attrValue);
}
@Test
public void changeSessionIdWhenHasNotSaved() throws Exception {
String attrName = "changeSessionId";
String attrValue = "changeSessionId-value";
RedisSession toSave = this.repository.createSession();
String originalId = toSave.getId();
toSave.changeSessionId();
this.repository.save(toSave);
assertThat(this.repository.findById(toSave.getId())).isNotNull();
assertThat(this.repository.findById(originalId)).isNull();
}
private String getSecurityName() {
return this.context.getAuthentication().getName();
}