From 94d2d0b8a47dc44744ba0a64aabadc011836f5c0 Mon Sep 17 00:00:00 2001 From: Max Batischev Date: Sat, 8 Feb 2025 14:17:30 +0300 Subject: [PATCH] Polish AbstractAuthenticationTargetUrlRequestHandler Signed-off-by: Max Batischev --- .../AbstractAuthenticationTargetUrlRequestHandler.java | 4 +++- ...bstractAuthenticationTargetUrlRequestHandlerTests.java | 8 +++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/web/src/main/java/org/springframework/security/web/authentication/AbstractAuthenticationTargetUrlRequestHandler.java b/web/src/main/java/org/springframework/security/web/authentication/AbstractAuthenticationTargetUrlRequestHandler.java index 55e8a796032..9e54c69843d 100644 --- a/web/src/main/java/org/springframework/security/web/authentication/AbstractAuthenticationTargetUrlRequestHandler.java +++ b/web/src/main/java/org/springframework/security/web/authentication/AbstractAuthenticationTargetUrlRequestHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2025 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. @@ -195,8 +195,10 @@ protected String getTargetUrlParameter() { /** * Allows overriding of the behaviour when redirecting to a target URL. + * @param redirectStrategy {@link RedirectStrategy} to use */ public void setRedirectStrategy(RedirectStrategy redirectStrategy) { + Assert.notNull(redirectStrategy, "redirectStrategy cannot be null"); this.redirectStrategy = redirectStrategy; } diff --git a/web/src/test/java/org/springframework/security/web/authentication/AbstractAuthenticationTargetUrlRequestHandlerTests.java b/web/src/test/java/org/springframework/security/web/authentication/AbstractAuthenticationTargetUrlRequestHandlerTests.java index 3c721567ea1..be049e28854 100644 --- a/web/src/test/java/org/springframework/security/web/authentication/AbstractAuthenticationTargetUrlRequestHandlerTests.java +++ b/web/src/test/java/org/springframework/security/web/authentication/AbstractAuthenticationTargetUrlRequestHandlerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2025 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. @@ -25,6 +25,7 @@ import org.springframework.mock.web.MockHttpServletResponse; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; /** * @author Dayan Kodippily @@ -108,4 +109,9 @@ void returnDefaultTargetUrlIfUseRefererIsFalse() { assertThat(this.handler.determineTargetUrl(this.request, this.response)).isEqualTo(DEFAULT_TARGET_URL); } + @Test + void setRedirectStrategyWhenGivenNullThenThrowsException() { + assertThatIllegalArgumentException().isThrownBy(() -> this.handler.setRedirectStrategy(null)); + } + }