Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014-2021 the original author or authors.
* Copyright 2014-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -37,6 +37,7 @@
import org.springframework.data.redis.core.RedisOperations;
import org.springframework.data.redis.serializer.JdkSerializationRedisSerializer;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.serializer.SerializationException;
import org.springframework.data.redis.util.ByteUtils;
import org.springframework.session.DelegatingIndexResolver;
import org.springframework.session.FindByIndexNameSessionRepository;
Expand Down Expand Up @@ -454,7 +455,15 @@ public Map<String, RedisSession> findByIndexNameAndIndexValue(String indexName,
* @return the Redis session
*/
private RedisSession getSession(String id, boolean allowExpired) {
Map<Object, Object> entries = getSessionBoundHashOperations(id).entries();
Map<Object, Object> entries;
try {
entries = getSessionBoundHashOperations(id).entries();
}
catch (SerializationException ex) {
// An error deserializing is equivalent to not having any information at all.
logger.warn("exception getting session " + id, ex);
return null;
}
if (entries.isEmpty()) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014-2019 the original author or authors.
* Copyright 2014-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -43,6 +43,7 @@
import org.springframework.data.redis.core.RedisOperations;
import org.springframework.data.redis.serializer.JdkSerializationRedisSerializer;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.serializer.SerializationException;
import org.springframework.session.FindByIndexNameSessionRepository;
import org.springframework.session.FlushMode;
import org.springframework.session.MapSession;
Expand Down Expand Up @@ -394,6 +395,15 @@ void getSessionExpired() {
assertThat(this.redisRepository.findById(expiredId)).isNull();
}

@Test
void getSessionIncompatible() {
String incompatibleId = "incompatible";

given(this.redisOperations.boundHashOps(getKey(incompatibleId))).willReturn(this.boundHashOperations);
given(this.boundHashOperations.entries()).willThrow(new SerializationException("arbitrary exception"));
assertThat(this.redisRepository.findById(incompatibleId)).isNull();
}

@Test
@SuppressWarnings("unchecked")
void findByPrincipalNameExpired() {
Expand Down