20
20
import org .springframework .context .ApplicationContext ;
21
21
import org .springframework .core .Ordered ;
22
22
import org .springframework .http .HttpHeaders ;
23
- import org .springframework .http .HttpStatus ;
23
+ import org .springframework .http .HttpStatusCode ;
24
24
import org .springframework .http .server .RequestPath ;
25
25
import org .springframework .http .server .reactive .ServerHttpRequest ;
26
26
import org .springframework .stereotype .Component ;
37
37
import static org .gridsuite .gateway .GatewayConfig .END_POINT_SERVICE_NAME ;
38
38
import static org .gridsuite .gateway .GatewayConfig .HEADER_USER_ID ;
39
39
import static org .gridsuite .gateway .endpoints .EndPointElementServer .QUERY_PARAM_IDS ;
40
+ import static org .springframework .http .HttpStatus .*;
40
41
41
42
/**
42
43
* @author Slimane Amar <slimane.amar at rte-france.com>
@@ -91,11 +92,11 @@ public Mono<Void> filter(@NonNull ServerWebExchange exchange, @NonNull GatewayFi
91
92
92
93
// Is a method allowed ?
93
94
if (!endPointElementServer .isAllowedMethod (exchange .getRequest ().getMethod ())) {
94
- return completeWithCode (exchange , HttpStatus . FORBIDDEN );
95
+ return completeWithCode (exchange , FORBIDDEN );
95
96
}
96
97
97
98
Optional <AccessControlInfos > accessControlInfos = endPointElementServer .getAccessControlInfos (exchange .getRequest ());
98
- return accessControlInfos .isEmpty () ? completeWithCode (exchange , HttpStatus . FORBIDDEN ) : isAccessAllowed (exchange , chain , accessControlInfos .get ());
99
+ return accessControlInfos .isEmpty () ? completeWithCode (exchange , FORBIDDEN ) : isAccessAllowed (exchange , chain , accessControlInfos .get ());
99
100
}
100
101
101
102
private Mono <Void > isAccessAllowed (ServerWebExchange exchange , GatewayFilterChain chain , AccessControlInfos accessControlInfos ) {
@@ -111,16 +112,15 @@ private Mono<Void> isAccessAllowed(ServerWebExchange exchange, GatewayFilterChai
111
112
)
112
113
.header (HEADER_USER_ID , Objects .requireNonNull (httpHeaders .get (HEADER_USER_ID )).get (0 ))
113
114
.exchangeToMono (response -> {
114
- switch (response .statusCode ()) {
115
- case OK :
116
- return chain .filter (exchange );
117
- case NOT_FOUND :
118
- return completeWithCode (exchange , HttpStatus .NOT_FOUND );
119
- case FORBIDDEN :
120
- return completeWithCode (exchange , HttpStatus .FORBIDDEN );
121
- default :
122
- return response .createException ().flatMap (Mono ::error );
115
+ HttpStatusCode httpStatusCode = response .statusCode ();
116
+ if (httpStatusCode .equals (OK )) {
117
+ return chain .filter (exchange );
118
+ } else if (httpStatusCode .equals (NOT_FOUND )) {
119
+ return completeWithCode (exchange , NOT_FOUND );
120
+ } else if (httpStatusCode .equals (FORBIDDEN )) {
121
+ return completeWithCode (exchange , FORBIDDEN );
123
122
}
123
+ return response .createException ().flatMap (Mono ::error );
124
124
})
125
125
.publishOn (Schedulers .boundedElastic ())
126
126
.log (ROOT_CATEGORY_REACTOR , Level .FINE );
0 commit comments