|
@@ -16,6 +16,8 @@
|
|
|
|
|
|
package org.springframework.security.web.server;
|
|
package org.springframework.security.web.server;
|
|
|
|
|
|
|
|
+import java.nio.charset.Charset;
|
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
import java.util.Base64;
|
|
import java.util.Base64;
|
|
import java.util.function.Function;
|
|
import java.util.function.Function;
|
|
|
|
|
|
@@ -25,6 +27,7 @@ import org.springframework.http.HttpHeaders;
|
|
import org.springframework.http.server.reactive.ServerHttpRequest;
|
|
import org.springframework.http.server.reactive.ServerHttpRequest;
|
|
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
|
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
|
import org.springframework.security.core.Authentication;
|
|
import org.springframework.security.core.Authentication;
|
|
|
|
+import org.springframework.util.Assert;
|
|
import org.springframework.util.StringUtils;
|
|
import org.springframework.util.StringUtils;
|
|
import org.springframework.web.server.ServerWebExchange;
|
|
import org.springframework.web.server.ServerWebExchange;
|
|
|
|
|
|
@@ -43,6 +46,8 @@ public class ServerHttpBasicAuthenticationConverter implements Function<ServerWe
|
|
|
|
|
|
public static final String BASIC = "Basic ";
|
|
public static final String BASIC = "Basic ";
|
|
|
|
|
|
|
|
+ private Charset credentialsCharset = StandardCharsets.UTF_8;
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
@Deprecated
|
|
@Deprecated
|
|
public Mono<Authentication> apply(ServerWebExchange exchange) {
|
|
public Mono<Authentication> apply(ServerWebExchange exchange) {
|
|
@@ -51,9 +56,8 @@ public class ServerHttpBasicAuthenticationConverter implements Function<ServerWe
|
|
if (!StringUtils.startsWithIgnoreCase(authorization, "basic ")) {
|
|
if (!StringUtils.startsWithIgnoreCase(authorization, "basic ")) {
|
|
return Mono.empty();
|
|
return Mono.empty();
|
|
}
|
|
}
|
|
- String credentials = (authorization.length() <= BASIC.length()) ? ""
|
|
|
|
- : authorization.substring(BASIC.length(), authorization.length());
|
|
|
|
- String decoded = new String(base64Decode(credentials));
|
|
|
|
|
|
+ String credentials = (authorization.length() <= BASIC.length()) ? "" : authorization.substring(BASIC.length());
|
|
|
|
+ String decoded = new String(base64Decode(credentials), this.credentialsCharset);
|
|
String[] parts = decoded.split(":", 2);
|
|
String[] parts = decoded.split(":", 2);
|
|
if (parts.length != 2) {
|
|
if (parts.length != 2) {
|
|
return Mono.empty();
|
|
return Mono.empty();
|
|
@@ -70,4 +74,13 @@ public class ServerHttpBasicAuthenticationConverter implements Function<ServerWe
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public Charset getCredentialsCharset() {
|
|
|
|
+ return this.credentialsCharset;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void setCredentialsCharset(Charset credentialsCharset) {
|
|
|
|
+ Assert.notNull(credentialsCharset, "credentialsCharset cannot be null");
|
|
|
|
+ this.credentialsCharset = credentialsCharset;
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|