Skip to content

Commit 01c49c1

Browse files
springboot 3.1.2 (#88)
Signed-off-by: Abdelsalem <[email protected]> Co-authored-by: HARPER Jon <[email protected]>
1 parent 53de7d7 commit 01c49c1

File tree

4 files changed

+34
-37
lines changed

4 files changed

+34
-37
lines changed

pom.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<parent>
1414
<groupId>com.powsybl</groupId>
1515
<artifactId>powsybl-parent-ws</artifactId>
16-
<version>12</version>
16+
<version>15</version>
1717
<relativePath/>
1818
</parent>
1919

@@ -42,7 +42,7 @@
4242
</developers>
4343

4444
<properties>
45-
<gridsuite-dependencies.version>25</gridsuite-dependencies.version>
45+
<gridsuite-dependencies.version>26</gridsuite-dependencies.version>
4646

4747
<nimbus-jose-jwt.version>8.14</nimbus-jose-jwt.version>
4848
<oauth2-oidc-sdk.version>7.3</oauth2-oidc-sdk.version>
@@ -59,8 +59,8 @@
5959
<artifactId>spring-boot-maven-plugin</artifactId>
6060
</plugin>
6161
<plugin>
62-
<groupId>pl.project13.maven</groupId>
63-
<artifactId>git-commit-id-plugin</artifactId>
62+
<groupId>io.github.git-commit-id</groupId>
63+
<artifactId>git-commit-id-maven-plugin</artifactId>
6464
</plugin>
6565
</plugins>
6666
</build>

src/main/java/org/gridsuite/gateway/endpoints/EndPointElementServer.java

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,17 @@
1515
import java.util.*;
1616
import java.util.stream.Collectors;
1717

18+
import static org.springframework.http.HttpMethod.*;
19+
1820
/**
1921
* @author Slimane Amar <slimane.amar at rte-france.com>
2022
*/
2123
public interface EndPointElementServer extends EndPointServer {
2224

2325
String QUERY_PARAM_IDS = "ids";
2426

25-
Set<HttpMethod> ALLOWED_HTTP_METHODS = Set.of(HttpMethod.GET, HttpMethod.HEAD,
26-
HttpMethod.PUT, HttpMethod.POST, HttpMethod.DELETE
27+
Set<HttpMethod> ALLOWED_HTTP_METHODS = Set.of(GET, HEAD,
28+
PUT, POST, DELETE
2729
);
2830

2931
static UUID getUuid(String uuid) {
@@ -60,27 +62,22 @@ default Optional<AccessControlInfos> getAccessControlInfos(@NonNull ServerHttpRe
6062
UUID elementUuid = getElementUuidIfExist(path);
6163

6264
// /<elements>/{elementUuid} or /<elements>/**?id=
63-
switch (Objects.requireNonNull(request.getMethod())) {
64-
case HEAD:
65-
case GET: {
66-
if (elementUuid != null) {
67-
return Optional.of(AccessControlInfos.create(List.of(elementUuid)));
65+
HttpMethod httpMethod = Objects.requireNonNull(request.getMethod());
66+
if (httpMethod.equals(HEAD) || httpMethod.equals(GET)) {
67+
if (elementUuid != null) {
68+
return Optional.of(AccessControlInfos.create(List.of(elementUuid)));
69+
} else {
70+
if (request.getQueryParams().get(QUERY_PARAM_IDS) == null) {
71+
return Optional.empty();
6872
} else {
69-
if (request.getQueryParams().get(QUERY_PARAM_IDS) == null) {
70-
return Optional.empty();
71-
} else {
72-
List<String> ids = request.getQueryParams().get(QUERY_PARAM_IDS);
73-
List<UUID> elementUuids = ids.stream().map(EndPointElementServer::getUuid).filter(Objects::nonNull).collect(Collectors.toList());
74-
return elementUuids.size() == ids.size() ? Optional.of(AccessControlInfos.create(elementUuids)) : Optional.empty();
75-
}
73+
List<String> ids = request.getQueryParams().get(QUERY_PARAM_IDS);
74+
List<UUID> elementUuids = ids.stream().map(EndPointElementServer::getUuid).filter(Objects::nonNull).collect(Collectors.toList());
75+
return elementUuids.size() == ids.size() ? Optional.of(AccessControlInfos.create(elementUuids)) : Optional.empty();
7676
}
7777
}
78-
case POST: // Only sub elements (elements only via explore server)
79-
case PUT:
80-
case DELETE:
81-
return elementUuid == null ? Optional.empty() : Optional.of(AccessControlInfos.create(List.of(elementUuid)));
82-
default:
83-
return Optional.empty();
78+
} else if (httpMethod.equals(POST) || httpMethod.equals(PUT) || httpMethod.equals(DELETE)) {
79+
return elementUuid == null ? Optional.empty() : Optional.of(AccessControlInfos.create(List.of(elementUuid)));
8480
}
81+
return Optional.empty();
8582
}
8683
}

src/main/java/org/gridsuite/gateway/filters/ElementAccessControllerGlobalPreFilter.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import org.springframework.context.ApplicationContext;
2121
import org.springframework.core.Ordered;
2222
import org.springframework.http.HttpHeaders;
23-
import org.springframework.http.HttpStatus;
23+
import org.springframework.http.HttpStatusCode;
2424
import org.springframework.http.server.RequestPath;
2525
import org.springframework.http.server.reactive.ServerHttpRequest;
2626
import org.springframework.stereotype.Component;
@@ -37,6 +37,7 @@
3737
import static org.gridsuite.gateway.GatewayConfig.END_POINT_SERVICE_NAME;
3838
import static org.gridsuite.gateway.GatewayConfig.HEADER_USER_ID;
3939
import static org.gridsuite.gateway.endpoints.EndPointElementServer.QUERY_PARAM_IDS;
40+
import static org.springframework.http.HttpStatus.*;
4041

4142
/**
4243
* @author Slimane Amar <slimane.amar at rte-france.com>
@@ -91,11 +92,11 @@ public Mono<Void> filter(@NonNull ServerWebExchange exchange, @NonNull GatewayFi
9192

9293
// Is a method allowed ?
9394
if (!endPointElementServer.isAllowedMethod(exchange.getRequest().getMethod())) {
94-
return completeWithCode(exchange, HttpStatus.FORBIDDEN);
95+
return completeWithCode(exchange, FORBIDDEN);
9596
}
9697

9798
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());
99100
}
100101

101102
private Mono<Void> isAccessAllowed(ServerWebExchange exchange, GatewayFilterChain chain, AccessControlInfos accessControlInfos) {
@@ -111,16 +112,15 @@ private Mono<Void> isAccessAllowed(ServerWebExchange exchange, GatewayFilterChai
111112
)
112113
.header(HEADER_USER_ID, Objects.requireNonNull(httpHeaders.get(HEADER_USER_ID)).get(0))
113114
.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);
123122
}
123+
return response.createException().flatMap(Mono::error);
124124
})
125125
.publishOn(Schedulers.boundedElastic())
126126
.log(ROOT_CATEGORY_REACTOR, Level.FINE);

src/test/java/org/gridsuite/gateway/TokenValidationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import org.springframework.beans.factory.annotation.Value;
2525
import org.springframework.boot.test.context.SpringBootTest;
2626
import org.springframework.boot.test.context.TestConfiguration;
27-
import org.springframework.boot.web.server.LocalServerPort;
27+
import org.springframework.boot.test.web.server.LocalServerPort;
2828
import org.springframework.cloud.contract.wiremock.AutoConfigureWireMock;
2929
import org.springframework.cloud.contract.wiremock.WireMockConfigurationCustomizer;
3030
import org.springframework.context.annotation.Bean;

0 commit comments

Comments
 (0)