Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions web/spring-security-web.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
id 'io.spring.convention.spring-module'
id 'security-nullability'
id 'compile-warnings-error'
id 'javadoc-warnings-error'
id 'test-compile-target-jdk25'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class OneTimeTokenAuthenticationConverter implements AuthenticationConver
this.logger.debug("No token found in request");
return null;
}
return OneTimeTokenAuthenticationToken.unauthenticated(token);
return new OneTimeTokenAuthenticationToken(token);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
* @author Luke Taylor
* @since 2.0
*/
@SuppressWarnings("removal")
public class JdbcTokenRepositoryImpl extends JdbcDaoSupport implements PersistentTokenRepository {

/** Default SQL for creating the database table to store the tokens */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ public Mono<Authentication> convert(ServerWebExchange exchange) {
if (isFormEncodedRequest(exchange.getRequest())) {
return exchange.getFormData()
.flatMap((data) -> Mono.justOrEmpty(data.getFirst(TOKEN)))
.map((data) -> OneTimeTokenAuthenticationToken.unauthenticated(data));
.map(OneTimeTokenAuthenticationToken::new);
}
String token = resolveTokenFromRequest(exchange.getRequest());
if (!StringUtils.hasText(token)) {
return Mono.empty();
}
return Mono.just(OneTimeTokenAuthenticationToken.unauthenticated(token));
return Mono.just(new OneTimeTokenAuthenticationToken(token));
}

private @Nullable String resolveTokenFromRequest(ServerHttpRequest request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import java.io.IOException;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;

import jakarta.servlet.ServletException;
Expand Down Expand Up @@ -52,16 +51,13 @@ public class DelegatingAuthenticationEntryPointTests {

private DelegatingAuthenticationEntryPoint daep;

private LinkedHashMap<RequestMatcher, AuthenticationEntryPoint> entryPoints;

private AuthenticationEntryPoint defaultEntryPoint;

private HttpServletRequest request = new MockHttpServletRequest();

@BeforeEach
public void before() {
this.defaultEntryPoint = mock(AuthenticationEntryPoint.class);
this.entryPoints = new LinkedHashMap<>();
}

@Test
Expand All @@ -70,9 +66,8 @@ public void testDefaultEntryPoint() throws Exception {
AuthenticationEntryPoint firstAEP = mock(AuthenticationEntryPoint.class);
RequestMatcher firstRM = mock(RequestMatcher.class);
given(firstRM.matches(this.request)).willReturn(false);
this.entryPoints.put(firstRM, firstAEP);
this.daep = new DelegatingAuthenticationEntryPoint(this.entryPoints);
this.daep.setDefaultEntryPoint(this.defaultEntryPoint);
this.daep = new DelegatingAuthenticationEntryPoint(this.defaultEntryPoint,
new RequestMatcherEntry<>(firstRM, firstAEP));
this.daep.commence(this.request, null, null);
verify(this.defaultEntryPoint).commence(this.request, null, null);
verify(firstAEP, never()).commence(this.request, null, null);
Expand All @@ -86,10 +81,8 @@ public void testFirstEntryPoint() throws Exception {
AuthenticationEntryPoint secondAEP = mock(AuthenticationEntryPoint.class);
RequestMatcher secondRM = mock(RequestMatcher.class);
given(firstRM.matches(this.request)).willReturn(true);
this.entryPoints.put(firstRM, firstAEP);
this.entryPoints.put(secondRM, secondAEP);
this.daep = new DelegatingAuthenticationEntryPoint(this.entryPoints);
this.daep.setDefaultEntryPoint(this.defaultEntryPoint);
this.daep = new DelegatingAuthenticationEntryPoint(this.defaultEntryPoint,
new RequestMatcherEntry<>(firstRM, firstAEP), new RequestMatcherEntry<>(secondRM, secondAEP));
this.daep.commence(this.request, null, null);
verify(firstAEP).commence(this.request, null, null);
verify(secondAEP, never()).commence(this.request, null, null);
Expand All @@ -106,10 +99,8 @@ public void testSecondEntryPoint() throws Exception {
RequestMatcher secondRM = mock(RequestMatcher.class);
given(firstRM.matches(this.request)).willReturn(false);
given(secondRM.matches(this.request)).willReturn(true);
this.entryPoints.put(firstRM, firstAEP);
this.entryPoints.put(secondRM, secondAEP);
this.daep = new DelegatingAuthenticationEntryPoint(this.entryPoints);
this.daep.setDefaultEntryPoint(this.defaultEntryPoint);
this.daep = new DelegatingAuthenticationEntryPoint(this.defaultEntryPoint,
new RequestMatcherEntry<>(firstRM, firstAEP), new RequestMatcherEntry<>(secondRM, secondAEP));
this.daep.commence(this.request, null, null);
verify(secondAEP).commence(this.request, null, null);
verify(firstAEP, never()).commence(this.request, null, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.authentication.ott.OneTimeTokenAuthenticationToken;
import org.springframework.security.authentication.ott.OneTimeTokenAuthentication;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.web.servlet.MockServletContext;

Expand Down Expand Up @@ -120,7 +120,7 @@ void doFilterWhenInvalidTokenThenUnauthorized() throws ServletException, IOExcep
@SuppressWarnings("removal")
void doFilterWhenValidThenRedirectsToSavedRequest() throws ServletException, IOException {
given(this.authenticationManager.authenticate(any()))
.willReturn(OneTimeTokenAuthenticationToken.authenticated("username", AuthorityUtils.NO_AUTHORITIES));
.willReturn(new OneTimeTokenAuthentication("username", AuthorityUtils.NO_AUTHORITIES));
this.filter.doFilter(
post("/login/ott").param("token", "some-token-value").buildRequest(new MockServletContext()),
this.response, this.chain);
Expand Down
Loading