From 987ee2e67a474a35c851032b43245795dfec590a Mon Sep 17 00:00:00 2001 From: Steve Riesenberg Date: Thu, 17 Mar 2022 12:32:48 -0500 Subject: [PATCH] Polish gh-10911 --- .../ServerHttpBasicAuthenticationConverter.java | 13 ++++++++----- ...ServerHttpBasicAuthenticationConverterTests.java | 9 ++++++++- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/web/src/main/java/org/springframework/security/web/server/ServerHttpBasicAuthenticationConverter.java b/web/src/main/java/org/springframework/security/web/server/ServerHttpBasicAuthenticationConverter.java index 89097721f8..7494fefa90 100644 --- a/web/src/main/java/org/springframework/security/web/server/ServerHttpBasicAuthenticationConverter.java +++ b/web/src/main/java/org/springframework/security/web/server/ServerHttpBasicAuthenticationConverter.java @@ -74,11 +74,14 @@ public class ServerHttpBasicAuthenticationConverter implements FunctionUTF_8. + * @param credentialsCharset the {@link Charset} used to decode the Base64-encoded + * bytes of the basic authentication credentials + * @since 5.7 + */ + public final void setCredentialsCharset(Charset credentialsCharset) { Assert.notNull(credentialsCharset, "credentialsCharset cannot be null"); this.credentialsCharset = credentialsCharset; } diff --git a/web/src/test/java/org/springframework/security/web/server/authentication/ServerHttpBasicAuthenticationConverterTests.java b/web/src/test/java/org/springframework/security/web/server/authentication/ServerHttpBasicAuthenticationConverterTests.java index da76c0112d..d735311a7f 100644 --- a/web/src/test/java/org/springframework/security/web/server/authentication/ServerHttpBasicAuthenticationConverterTests.java +++ b/web/src/test/java/org/springframework/security/web/server/authentication/ServerHttpBasicAuthenticationConverterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2022 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. @@ -28,6 +28,7 @@ import org.springframework.security.authentication.UsernamePasswordAuthenticatio import org.springframework.security.core.Authentication; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; /** * @author Rob Winch @@ -39,6 +40,12 @@ public class ServerHttpBasicAuthenticationConverterTests { MockServerHttpRequest.BaseBuilder request = MockServerHttpRequest.get("/"); + @Test + public void setCredentialsCharsetWhenNullThenThrowsIllegalArgumentException() { + assertThatIllegalArgumentException().isThrownBy(() -> this.converter.setCredentialsCharset(null)) + .withMessage("credentialsCharset cannot be null"); + } + @Test public void applyWhenNoAuthorizationHeaderThenEmpty() { Mono result = apply(this.request);