|
|
|
@ -314,7 +314,7 @@ public class AuthenticationFilterTests { |
|
|
|
SecurityContextHolder.setContext(new SecurityContextImpl(existingAuthn)); |
|
|
|
SecurityContextHolder.setContext(new SecurityContextImpl(existingAuthn)); |
|
|
|
given(this.authenticationConverter.convert(any())).willReturn(existingAuthn); |
|
|
|
given(this.authenticationConverter.convert(any())).willReturn(existingAuthn); |
|
|
|
given(this.authenticationManager.authenticate(any())) |
|
|
|
given(this.authenticationManager.authenticate(any())) |
|
|
|
.willReturn(new TestingAuthenticationToken("user", "password", "TEST")); |
|
|
|
.willReturn(new TestingAuthenticationToken(existingAuthn.getName(), "password", "TEST")); |
|
|
|
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/"); |
|
|
|
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/"); |
|
|
|
MockHttpServletResponse response = new MockHttpServletResponse(); |
|
|
|
MockHttpServletResponse response = new MockHttpServletResponse(); |
|
|
|
FilterChain chain = new MockFilterChain(); |
|
|
|
FilterChain chain = new MockFilterChain(); |
|
|
|
@ -326,6 +326,27 @@ public class AuthenticationFilterTests { |
|
|
|
.containsExactlyInAnyOrder(ROLE_EXISTING, "TEST"); |
|
|
|
.containsExactlyInAnyOrder(ROLE_EXISTING, "TEST"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// gh-18112
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void doFilterWhenDifferentPrincipalThenDoesNotCombine() throws Exception { |
|
|
|
|
|
|
|
String ROLE_EXISTING = "ROLE_EXISTING"; |
|
|
|
|
|
|
|
TestingAuthenticationToken existingAuthn = new TestingAuthenticationToken("username", "password", |
|
|
|
|
|
|
|
ROLE_EXISTING); |
|
|
|
|
|
|
|
SecurityContextHolder.setContext(new SecurityContextImpl(existingAuthn)); |
|
|
|
|
|
|
|
given(this.authenticationConverter.convert(any())).willReturn(existingAuthn); |
|
|
|
|
|
|
|
TestingAuthenticationToken expected = new TestingAuthenticationToken(existingAuthn.getName() + "different", |
|
|
|
|
|
|
|
"password", "TEST"); |
|
|
|
|
|
|
|
given(this.authenticationManager.authenticate(any())).willReturn(expected); |
|
|
|
|
|
|
|
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/"); |
|
|
|
|
|
|
|
MockHttpServletResponse response = new MockHttpServletResponse(); |
|
|
|
|
|
|
|
FilterChain chain = new MockFilterChain(); |
|
|
|
|
|
|
|
AuthenticationFilter filter = new AuthenticationFilter(this.authenticationManager, |
|
|
|
|
|
|
|
this.authenticationConverter); |
|
|
|
|
|
|
|
filter.doFilter(request, response, chain); |
|
|
|
|
|
|
|
Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); |
|
|
|
|
|
|
|
assertThat(authentication).isEqualTo(expected); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* This is critical to avoid adding duplicate GrantedAuthority instances with the |
|
|
|
* This is critical to avoid adding duplicate GrantedAuthority instances with the |
|
|
|
* same' authority when the issuedAt is too old and a new instance is requested. |
|
|
|
* same' authority when the issuedAt is too old and a new instance is requested. |
|
|
|
|