Skip to content

Commit 5e8c681

Browse files
committed
Merge branch '6.0.x'
2 parents 6f5172d + 3fbb64d commit 5e8c681

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

web/src/test/java/org/springframework/security/web/authentication/SimpleUrlAuthenticationSuccessHandlerTests.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,11 +16,15 @@
1616

1717
package org.springframework.security.web.authentication;
1818

19+
import jakarta.servlet.http.HttpSession;
1920
import org.junit.jupiter.api.Test;
2021

2122
import org.springframework.mock.web.MockHttpServletRequest;
2223
import org.springframework.mock.web.MockHttpServletResponse;
24+
import org.springframework.security.authentication.BadCredentialsException;
2325
import org.springframework.security.core.Authentication;
26+
import org.springframework.security.core.AuthenticationException;
27+
import org.springframework.security.web.WebAttributes;
2428

2529
import static org.assertj.core.api.Assertions.assertThat;
2630
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
@@ -108,4 +112,20 @@ public void setTargetUrlParameterEmptyTargetUrlParameter() {
108112
assertThatIllegalArgumentException().isThrownBy(() -> ash.setTargetUrlParameter(" "));
109113
}
110114

115+
@Test
116+
public void shouldRemoveAuthenticationAttributeWhenOnAuthenticationSuccess() throws Exception {
117+
SimpleUrlAuthenticationSuccessHandler ash = new SimpleUrlAuthenticationSuccessHandler();
118+
MockHttpServletRequest request = new MockHttpServletRequest();
119+
MockHttpServletResponse response = new MockHttpServletResponse();
120+
HttpSession session = request.getSession();
121+
assertThat(session).isNotNull();
122+
session.setAttribute(WebAttributes.AUTHENTICATION_EXCEPTION,
123+
new BadCredentialsException("Invalid credentials"));
124+
assertThat(session.getAttribute(WebAttributes.AUTHENTICATION_EXCEPTION)).isNotNull();
125+
assertThat(session.getAttribute(WebAttributes.AUTHENTICATION_EXCEPTION))
126+
.isInstanceOf(AuthenticationException.class);
127+
ash.onAuthenticationSuccess(request, response, mock(Authentication.class));
128+
assertThat(session.getAttribute(WebAttributes.AUTHENTICATION_EXCEPTION)).isNull();
129+
}
130+
111131
}

0 commit comments

Comments
 (0)