mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-07-10 04:13:31 +00:00
HttpSessionOAuth2AuthorizationRequestRepository removes empty Map from session
Fixes gh-5263
This commit is contained in:
parent
49b63e260d
commit
4cc5705ae5
@ -77,7 +77,11 @@ public final class HttpSessionOAuth2AuthorizationRequestRepository implements Au
|
|||||||
}
|
}
|
||||||
Map<String, OAuth2AuthorizationRequest> authorizationRequests = this.getAuthorizationRequests(request);
|
Map<String, OAuth2AuthorizationRequest> authorizationRequests = this.getAuthorizationRequests(request);
|
||||||
OAuth2AuthorizationRequest originalRequest = authorizationRequests.remove(stateParameter);
|
OAuth2AuthorizationRequest originalRequest = authorizationRequests.remove(stateParameter);
|
||||||
|
if (!authorizationRequests.isEmpty()) {
|
||||||
request.getSession().setAttribute(this.sessionAttributeName, authorizationRequests);
|
request.getSession().setAttribute(this.sessionAttributeName, authorizationRequests);
|
||||||
|
} else {
|
||||||
|
request.getSession().removeAttribute(this.sessionAttributeName);
|
||||||
|
}
|
||||||
return originalRequest;
|
return originalRequest;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -242,6 +242,28 @@ public class HttpSessionOAuth2AuthorizationRequestRepositoryTests {
|
|||||||
assertThat(loadedAuthorizationRequest).isNull();
|
assertThat(loadedAuthorizationRequest).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// gh-5263
|
||||||
|
@Test
|
||||||
|
public void removeAuthorizationRequestWhenSavedThenRemovedFromSession() {
|
||||||
|
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||||
|
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||||
|
|
||||||
|
OAuth2AuthorizationRequest authorizationRequest = createAuthorizationRequest().build();
|
||||||
|
|
||||||
|
this.authorizationRequestRepository.saveAuthorizationRequest(
|
||||||
|
authorizationRequest, request, response);
|
||||||
|
|
||||||
|
request.addParameter(OAuth2ParameterNames.STATE, authorizationRequest.getState());
|
||||||
|
OAuth2AuthorizationRequest removedAuthorizationRequest =
|
||||||
|
this.authorizationRequestRepository.removeAuthorizationRequest(request);
|
||||||
|
|
||||||
|
String sessionAttributeName = HttpSessionOAuth2AuthorizationRequestRepository.class.getName() +
|
||||||
|
".AUTHORIZATION_REQUEST";
|
||||||
|
|
||||||
|
assertThat(removedAuthorizationRequest).isNotNull();
|
||||||
|
assertThat(request.getSession().getAttribute(sessionAttributeName)).isNull();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void removeAuthorizationRequestWhenNotSavedThenNotRemoved() {
|
public void removeAuthorizationRequestWhenNotSavedThenNotRemoved() {
|
||||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user