File tree Expand file tree Collapse file tree 2 files changed +10
-2
lines changed
main/java/org/springframework/security/web/server/transport
test/java/org/springframework/security/web/server/transport Expand file tree Collapse file tree 2 files changed +10
-2
lines changed Original file line number Diff line number Diff line change 17
17
package org .springframework .security .web .server .transport ;
18
18
19
19
import java .net .URI ;
20
+ import java .util .Optional ;
20
21
21
22
import reactor .core .publisher .Mono ;
22
23
@@ -101,8 +102,9 @@ private URI createRedirectUri(ServerWebExchange exchange) {
101
102
UriComponentsBuilder .fromUri (exchange .getRequest ().getURI ());
102
103
103
104
if (port > 0 ) {
104
- port = this .portMapper .lookupHttpsPort (port );
105
- builder .port (port );
105
+ builder .port (Optional .ofNullable (this .portMapper .lookupHttpsPort (port ))
106
+ .orElseThrow (() -> new IllegalStateException (
107
+ "HTTP Port '" + port + "' does not have a corresponding HTTPS Port" )));
106
108
}
107
109
108
110
return builder .scheme ("https" ).build ().toUri ();
Original file line number Diff line number Diff line change @@ -112,6 +112,12 @@ public void filterWhenRequestIsInsecureThenPortMapperRemapsPort() {
112
112
verify (portMapper ).lookupHttpsPort (314 );
113
113
}
114
114
115
+ @ Test
116
+ public void filterWhenRequestIsInsecureAndNoPortMappingThenThrowsIllegalState () {
117
+ ServerWebExchange exchange = get ("http://localhost:1234" );
118
+ assertThatCode (() -> this .filter .filter (exchange , this .chain ).block ())
119
+ .isInstanceOf (IllegalStateException .class );
120
+ }
115
121
116
122
@ Test
117
123
public void filterWhenInsecureRequestHasAPathThenRedirects () {
You can’t perform that action at this time.
0 commit comments