Skip to content

Commit 1640a1f

Browse files
committed
Polish ServerAuthenticationConverter
Fix package tangles Issue: gh-5338
1 parent 68d836d commit 1640a1f

File tree

8 files changed

+93
-38
lines changed

8 files changed

+93
-38
lines changed

config/src/main/java/org/springframework/security/config/web/server/ServerHttpSecurity.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,6 @@
7171
import org.springframework.security.web.server.MatcherSecurityWebFilterChain;
7272
import org.springframework.security.web.server.SecurityWebFilterChain;
7373
import org.springframework.security.web.server.ServerAuthenticationEntryPoint;
74-
import org.springframework.security.web.server.ServerFormLoginAuthenticationConverter;
75-
import org.springframework.security.web.server.ServerHttpBasicAuthenticationConverter;
7674
import org.springframework.security.web.server.WebFilterExchange;
7775
import org.springframework.security.web.server.authentication.AuthenticationWebFilter;
7876
import org.springframework.security.web.server.authentication.HttpBasicServerAuthenticationEntryPoint;
@@ -82,6 +80,8 @@
8280
import org.springframework.security.web.server.authentication.ServerAuthenticationEntryPointFailureHandler;
8381
import org.springframework.security.web.server.authentication.ServerAuthenticationFailureHandler;
8482
import org.springframework.security.web.server.authentication.ServerAuthenticationSuccessHandler;
83+
import org.springframework.security.web.server.authentication.ServerFormLoginAuthenticationConverter;
84+
import org.springframework.security.web.server.authentication.ServerHttpBasicAuthenticationConverter;
8585
import org.springframework.security.web.server.authentication.logout.LogoutWebFilter;
8686
import org.springframework.security.web.server.authentication.logout.ServerLogoutHandler;
8787
import org.springframework.security.web.server.authentication.logout.ServerLogoutSuccessHandler;

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

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616
package org.springframework.security.web.server;
1717

18-
import org.springframework.security.web.server.authentication.ServerAuthenticationConverter;
1918
import org.springframework.util.Assert;
2019
import reactor.core.publisher.Mono;
2120

@@ -32,31 +31,22 @@
3231
*
3332
* @author Rob Winch
3433
* @since 5.0
34+
* @deprecated use {@link org.springframework.security.web.server.authentication.ServerFormLoginAuthenticationConverter}
35+
* instead.
3536
*/
37+
@Deprecated
3638
public class ServerFormLoginAuthenticationConverter implements
37-
ServerAuthenticationConverter,
3839
Function<ServerWebExchange, Mono<Authentication>> {
3940

4041
private String usernameParameter = "username";
4142

4243
private String passwordParameter = "password";
4344

44-
@Override
45-
public Mono<Authentication> convert(ServerWebExchange exchange) {
46-
return exchange.getFormData()
47-
.map( data -> createAuthentication(data));
48-
}
49-
50-
/**
51-
* Alias for {@link #convert(ServerWebExchange)}
52-
* @param exchange the {@link ServerWebExchange} to use
53-
* @return the {@link Authentication}
54-
* @deprecated Use {@link #convert(ServerWebExchange)}
55-
*/
5645
@Override
5746
@Deprecated
5847
public Mono<Authentication> apply(ServerWebExchange exchange) {
59-
return convert(exchange);
48+
return exchange.getFormData()
49+
.map( data -> createAuthentication(data));
6050
}
6151

6252
private UsernamePasswordAuthenticationToken createAuthentication(

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

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import org.springframework.http.server.reactive.ServerHttpRequest;
2323
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
2424
import org.springframework.security.core.Authentication;
25-
import org.springframework.security.web.server.authentication.ServerAuthenticationConverter;
2625
import org.springframework.web.server.ServerWebExchange;
2726

2827
import reactor.core.publisher.Mono;
@@ -32,15 +31,18 @@
3231
*
3332
* @author Rob Winch
3433
* @since 5.0
34+
* @deprecated Use {@link org.springframework.security.web.server.authentication.ServerHttpBasicAuthenticationConverter}
35+
* instead.
3536
*/
37+
@Deprecated
3638
public class ServerHttpBasicAuthenticationConverter implements
37-
ServerAuthenticationConverter,
3839
Function<ServerWebExchange, Mono<Authentication>> {
3940

4041
public static final String BASIC = "Basic ";
4142

4243
@Override
43-
public Mono<Authentication> convert(ServerWebExchange exchange) {
44+
@Deprecated
45+
public Mono<Authentication> apply(ServerWebExchange exchange) {
4446
ServerHttpRequest request = exchange.getRequest();
4547

4648
String authorization = request.getHeaders().getFirst(HttpHeaders.AUTHORIZATION);
@@ -49,7 +51,7 @@ public Mono<Authentication> convert(ServerWebExchange exchange) {
4951
}
5052

5153
String credentials = authorization.length() <= BASIC.length() ?
52-
"" : authorization.substring(BASIC.length(), authorization.length());
54+
"" : authorization.substring(BASIC.length(), authorization.length());
5355
byte[] decodedCredentials = base64Decode(credentials);
5456
String decodedAuthz = new String(decodedCredentials);
5557
String[] userParts = decodedAuthz.split(":");
@@ -64,18 +66,6 @@ public Mono<Authentication> convert(ServerWebExchange exchange) {
6466
return Mono.just(new UsernamePasswordAuthenticationToken(username, password));
6567
}
6668

67-
/**
68-
* Alias for {@link #convert(ServerWebExchange)}
69-
* @param exchange the {@link ServerWebExchange} to use
70-
* @return the {@link Authentication}
71-
* @deprecated Use {@link #convert(ServerWebExchange)}
72-
*/
73-
@Override
74-
@Deprecated
75-
public Mono<Authentication> apply(ServerWebExchange exchange) {
76-
return convert(exchange);
77-
}
78-
7969
private byte[] base64Decode(String value) {
8070
try {
8171
return Base64.getDecoder().decode(value);

web/src/main/java/org/springframework/security/web/server/authentication/AuthenticationWebFilter.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import org.springframework.security.core.AuthenticationException;
2323
import org.springframework.security.core.context.ReactiveSecurityContextHolder;
2424
import org.springframework.security.core.context.SecurityContextImpl;
25-
import org.springframework.security.web.server.ServerHttpBasicAuthenticationConverter;
2625
import org.springframework.security.web.server.WebFilterExchange;
2726
import org.springframework.security.web.server.context.NoOpServerSecurityContextRepository;
2827
import org.springframework.security.web.server.context.ServerSecurityContextRepository;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright 2002-2018 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.security.web.server.authentication;
17+
18+
import org.springframework.security.core.Authentication;
19+
import org.springframework.web.server.ServerWebExchange;
20+
import reactor.core.publisher.Mono;
21+
22+
/**
23+
* Converts a ServerWebExchange into a UsernamePasswordAuthenticationToken from the form
24+
* data HTTP parameters.
25+
*
26+
* @author Rob Winch
27+
* @since 5.1
28+
*/
29+
@SuppressWarnings("deprecation")
30+
public class ServerFormLoginAuthenticationConverter
31+
extends org.springframework.security.web.server.ServerFormLoginAuthenticationConverter
32+
implements ServerAuthenticationConverter {
33+
34+
@Override
35+
public Mono<Authentication> convert(ServerWebExchange exchange) {
36+
return apply(exchange);
37+
}
38+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright 2002-2018 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.security.web.server.authentication;
17+
18+
import org.springframework.security.core.Authentication;
19+
import org.springframework.web.server.ServerWebExchange;
20+
import reactor.core.publisher.Mono;
21+
22+
/**
23+
* Converts from a {@link ServerWebExchange} to an {@link Authentication} that can be authenticated.
24+
*
25+
* @author Rob Winch
26+
* @since 5.1
27+
*/
28+
@SuppressWarnings("deprecation")
29+
public class ServerHttpBasicAuthenticationConverter
30+
extends org.springframework.security.web.server.ServerHttpBasicAuthenticationConverter
31+
implements ServerAuthenticationConverter {
32+
33+
34+
@Override
35+
public Mono<Authentication> convert(ServerWebExchange exchange) {
36+
return apply(exchange);
37+
}
38+
}

web/src/test/java/org/springframework/security/web/server/ServerFormLoginAuthenticationConverterTests.java renamed to web/src/test/java/org/springframework/security/web/server/authentication/ServerFormLoginAuthenticationConverterTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 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.
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.security.web.server;
17+
package org.springframework.security.web.server.authentication;
1818

1919
import org.junit.Before;
2020
import org.junit.Test;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 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.
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.security.web.server;
17+
package org.springframework.security.web.server.authentication;
1818

1919
import org.junit.Test;
2020
import org.springframework.http.HttpHeaders;

0 commit comments

Comments
 (0)