Session Optional<T> getAttribute -> T getAttribute

Issue gh-819
This commit is contained in:
Rob Winch
2017-06-30 10:07:58 -05:00
parent ab3e280993
commit 8ef36e4f3e
19 changed files with 120 additions and 167 deletions

View File

@@ -22,7 +22,6 @@ import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.TimeUnit;
@@ -327,7 +326,7 @@ public class HazelcastSessionRepository implements
return this.delegate.getMaxInactiveInterval();
}
public <T> Optional<T> getAttribute(String attributeName) {
public <T> T getAttribute(String attributeName) {
return this.delegate.getAttribute(attributeName);
}

View File

@@ -16,11 +16,8 @@
package org.springframework.session.hazelcast;
import java.util.Optional;
import com.hazelcast.query.extractor.ValueCollector;
import com.hazelcast.query.extractor.ValueExtractor;
import org.springframework.expression.Expression;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.session.FindByIndexNameSessionRepository;
@@ -58,16 +55,16 @@ public class PrincipalNameExtractor extends ValueExtractor<MapSession, String> {
private SpelExpressionParser parser = new SpelExpressionParser();
public String resolvePrincipal(Session session) {
Optional<String> principalName = session.getAttribute(
String principalName = session.getAttribute(
FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME);
if (principalName.isPresent()) {
return principalName.get();
if (principalName != null) {
return principalName;
}
Optional<Object> authentication = session.getAttribute(SPRING_SECURITY_CONTEXT);
if (authentication.isPresent()) {
Object authentication = session.getAttribute(SPRING_SECURITY_CONTEXT);
if (authentication != null) {
Expression expression = this.parser
.parseExpression("authentication?.name");
return expression.getValue(authentication.get(), String.class);
return expression.getValue(authentication, String.class);
}
return null;
}

View File

@@ -272,7 +272,7 @@ public class HazelcastSessionRepositoryTests {
HazelcastSession session = this.repository.findById(saved.getId());
assertThat(session.getId()).isEqualTo(saved.getId());
assertThat(session.<String>getAttribute("savedName").orElse(null)).isEqualTo("savedValue");
assertThat(session.<String>getAttribute("savedName")).isEqualTo("savedValue");
verify(this.sessions, times(1)).get(eq(saved.getId()));
}