Skip to content

Commit 946e24e

Browse files
author
Steve Riesenberg
committed
Polish gh-10911
1 parent 2b6bc5d commit 946e24e

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

web/src/main/java/org/springframework/security/web/server/ServerHttpBasicAuthenticationConverter.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,14 @@ private byte[] base64Decode(String value) {
7474
}
7575
}
7676

77-
public Charset getCredentialsCharset() {
78-
return this.credentialsCharset;
79-
}
80-
81-
public void setCredentialsCharset(Charset credentialsCharset) {
77+
/**
78+
* Sets the {@link Charset} used to decode the Base64-encoded bytes of the basic
79+
* authentication credentials. The default is <code>UTF_8</code>.
80+
* @param credentialsCharset the {@link Charset} used to decode the Base64-encoded
81+
* bytes of the basic authentication credentials
82+
* @since 5.7
83+
*/
84+
public final void setCredentialsCharset(Charset credentialsCharset) {
8285
Assert.notNull(credentialsCharset, "credentialsCharset cannot be null");
8386
this.credentialsCharset = credentialsCharset;
8487
}

web/src/test/java/org/springframework/security/web/server/authentication/ServerHttpBasicAuthenticationConverterTests.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2022 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.
@@ -28,6 +28,7 @@
2828
import org.springframework.security.core.Authentication;
2929

3030
import static org.assertj.core.api.Assertions.assertThat;
31+
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
3132

3233
/**
3334
* @author Rob Winch
@@ -39,6 +40,12 @@ public class ServerHttpBasicAuthenticationConverterTests {
3940

4041
MockServerHttpRequest.BaseBuilder<?> request = MockServerHttpRequest.get("/");
4142

43+
@Test
44+
public void setCredentialsCharsetWhenNullThenThrowsIllegalArgumentException() {
45+
assertThatIllegalArgumentException().isThrownBy(() -> this.converter.setCredentialsCharset(null))
46+
.withMessage("credentialsCharset cannot be null");
47+
}
48+
4249
@Test
4350
public void applyWhenNoAuthorizationHeaderThenEmpty() {
4451
Mono<Authentication> result = apply(this.request);

0 commit comments

Comments
 (0)