Align SessionsEndpoint with Spring Session API improvements

This commit aligns SessionsEndpoint with
FindByIndexNameSessionRepository API improvements that simplifies
retrieval of sessions by principal name.

Closes gh-14124
This commit is contained in:
Vedran Pavic 2018-08-17 18:04:38 +02:00 committed by Stephane Nicoll
parent 94d45c7361
commit 644ab5f3e4
4 changed files with 8 additions and 16 deletions

View File

@ -89,9 +89,7 @@ public class SessionsEndpointDocumentationTests
sessions.put(sessionOne.getId(), sessionOne);
sessions.put(sessionTwo.getId(), sessionTwo);
sessions.put(sessionThree.getId(), sessionThree);
given(this.sessionRepository.findByIndexNameAndIndexValue(
FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME, "alice"))
.willReturn(sessions);
given(this.sessionRepository.findByPrincipalName("alice")).willReturn(sessions);
this.mockMvc.perform(get("/actuator/sessions").param("username", "alice"))
.andExpect(status().isOk())
.andDo(document("sessions/username",

View File

@ -52,9 +52,7 @@ public class SessionsEndpoint {
@ReadOperation
public SessionsReport sessionsForUsername(String username) {
Map<String, ? extends Session> sessions = this.sessionRepository
.findByIndexNameAndIndexValue(
FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME,
username);
.findByPrincipalName(username);
return new SessionsReport(sessions);
}

View File

@ -48,9 +48,8 @@ public class SessionsEndpointTests {
@Test
public void sessionsForUsername() {
given(this.repository.findByIndexNameAndIndexValue(
FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME, "user"))
.willReturn(Collections.singletonMap(session.getId(), session));
given(this.repository.findByPrincipalName("user"))
.willReturn(Collections.singletonMap(session.getId(), session));
List<SessionDescriptor> result = this.endpoint.sessionsForUsername("user")
.getSessions();
assertThat(result).hasSize(1);

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 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.
@ -58,9 +58,7 @@ public class SessionsEndpointWebIntegrationTests {
@Test
public void sessionsForUsernameNoResults() {
given(repository.findByIndexNameAndIndexValue(
FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME, "user"))
.willReturn(Collections.emptyMap());
given(repository.findByPrincipalName("user")).willReturn(Collections.emptyMap());
client.get()
.uri((builder) -> builder.path("/actuator/sessions")
.queryParam("username", "user").build())
@ -70,9 +68,8 @@ public class SessionsEndpointWebIntegrationTests {
@Test
public void sessionsForUsernameFound() {
given(repository.findByIndexNameAndIndexValue(
FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME, "user"))
.willReturn(Collections.singletonMap(session.getId(), session));
given(repository.findByPrincipalName("user"))
.willReturn(Collections.singletonMap(session.getId(), session));
client.get()
.uri((builder) -> builder.path("/actuator/sessions")
.queryParam("username", "user").build())