16
16
17
17
package org .springframework .security .web .server ;
18
18
19
+ import java .nio .charset .Charset ;
19
20
import java .nio .charset .StandardCharsets ;
20
21
import java .util .Base64 ;
21
22
import java .util .function .Function ;
26
27
import org .springframework .http .server .reactive .ServerHttpRequest ;
27
28
import org .springframework .security .authentication .UsernamePasswordAuthenticationToken ;
28
29
import org .springframework .security .core .Authentication ;
30
+ import org .springframework .util .Assert ;
29
31
import org .springframework .util .StringUtils ;
30
32
import org .springframework .web .server .ServerWebExchange ;
31
33
@@ -44,6 +46,8 @@ public class ServerHttpBasicAuthenticationConverter implements Function<ServerWe
44
46
45
47
public static final String BASIC = "Basic " ;
46
48
49
+ private Charset credentialsCharset = StandardCharsets .UTF_8 ;
50
+
47
51
@ Override
48
52
@ Deprecated
49
53
public Mono <Authentication > apply (ServerWebExchange exchange ) {
@@ -53,7 +57,7 @@ public Mono<Authentication> apply(ServerWebExchange exchange) {
53
57
return Mono .empty ();
54
58
}
55
59
String credentials = (authorization .length () <= BASIC .length ()) ? "" : authorization .substring (BASIC .length ());
56
- String decoded = new String (base64Decode (credentials ), StandardCharsets . UTF_8 );
60
+ String decoded = new String (base64Decode (credentials ), this . credentialsCharset );
57
61
String [] parts = decoded .split (":" , 2 );
58
62
if (parts .length != 2 ) {
59
63
return Mono .empty ();
@@ -70,4 +74,13 @@ private byte[] base64Decode(String value) {
70
74
}
71
75
}
72
76
77
+ public Charset getCredentialsCharset () {
78
+ return this .credentialsCharset ;
79
+ }
80
+
81
+ public void setCredentialsCharset (Charset credentialsCharset ) {
82
+ Assert .notNull (credentialsCharset , "credentialsCharset cannot be null" );
83
+ this .credentialsCharset = credentialsCharset ;
84
+ }
85
+
73
86
}
0 commit comments