Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main' into storeidentity
Browse files Browse the repository at this point in the history
Signed-off-by: sBouzols <[email protected]>
sBouzols committed Oct 10, 2024

Verified

This commit was signed with the committer’s verified signature.
edubart Eduardo Bart
2 parents 3756acb + d317f17 commit 9f47a70
Showing 20 changed files with 64 additions and 518 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@
<parent>
<groupId>com.powsybl</groupId>
<artifactId>powsybl-parent-ws</artifactId>
<version>15</version>
<version>20</version>
<relativePath/>
</parent>

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

<properties>
<gridsuite-dependencies.version>31</gridsuite-dependencies.version>
<gridsuite-dependencies.version>34</gridsuite-dependencies.version>

<nimbus-jose-jwt.version>8.14</nimbus-jose-jwt.version>
<oauth2-oidc-sdk.version>7.3</oauth2-oidc-sdk.version>
11 changes: 1 addition & 10 deletions src/main/java/org/gridsuite/gateway/GatewayConfig.java
Original file line number Diff line number Diff line change
@@ -6,7 +6,6 @@
*/
package org.gridsuite.gateway;

import org.gridsuite.gateway.endpoints.CgmesGlServer;
import org.gridsuite.gateway.endpoints.*;
import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
@@ -34,34 +33,26 @@ public RouteLocator myRoutes(RouteLocatorBuilder builder, ApplicationContext con
return builder.routes()
.route(p -> context.getBean(StudyServer.class).getRoute(p))
.route(p -> context.getBean(CaseServer.class).getRoute(p))
.route(p -> context.getBean(MergeServer.class).getRoute(p))
.route(p -> context.getBean(StudyNotificationServer.class).getRoute(p))
.route(p -> context.getBean(MergeNotificationServer.class).getRoute(p))
.route(p -> context.getBean(DirectoryNotificationServer.class).getRoute(p))
.route(p -> context.getBean(ContingencyServer.class).getRoute(p))
.route(p -> context.getBean(ConfigServer.class).getRoute(p))
.route(p -> context.getBean(ConfigNotificationServer.class).getRoute(p))
.route(p -> context.getBean(DirectoryServer.class).getRoute(p))
.route(p -> context.getBean(ExploreServer.class).getRoute(p))
.route(p -> context.getBean(CgmesBoundaryServer.class).getRoute(p))
.route(p -> context.getBean(DynamicMappingServer.class).getRoute(p))
.route(p -> context.getBean(FilterServer.class).getRoute(p))
.route(p -> context.getBean(ReportServer.class).getRoute(p))
.route(p -> context.getBean(NetworkModificationServer.class).getRoute(p))
.route(p -> context.getBean(NetworkConversionServer.class).getRoute(p))
.route(p -> context.getBean(OdreServer.class).getRoute(p))
.route(p -> context.getBean(GeoDataServer.class).getRoute(p))
.route(p -> context.getBean(UserAdminServer.class).getRoute(p))
.route(p -> context.getBean(CgmesGlServer.class).getRoute(p))
.route(p -> context.getBean(SensitivityAnalysisServer.class).getRoute(p))
.route(p -> context.getBean(LoadFlowServer.class).getRoute(p))
.route(p -> context.getBean(SecurityAnalysisServer.class).getRoute(p))
.route(p -> context.getBean(DynamicSimulationServer.class).getRoute(p))
.route(p -> context.getBean(CaseImportServer.class).getRoute(p))
.route(p -> context.getBean(VoltageInitServer.class).getRoute(p))
.route(p -> context.getBean(ShortCircuitServer.class).getRoute(p))
.route(p -> context.getBean(StateEstimationServer.class).getRoute(p))
.route(p -> context.getBean(StateEstimationOrchestratorServer.class).getRoute(p))
.route(p -> context.getBean(SpreadsheetConfigServer.class).getRoute(p))
.build();
}
}
3 changes: 3 additions & 0 deletions src/main/java/org/gridsuite/gateway/ServiceURIsConfig.java
Original file line number Diff line number Diff line change
@@ -111,6 +111,9 @@ public class ServiceURIsConfig {
@Value("${gridsuite.services.state-estimation-orchestrator-server.base-uri:http://state-estimation-orchestrator-server/}")
String stateEstimationOrchestratorServerBaseUri;

@Value("${gridsuite.services.spreadsheet-config-server.base-uri:http://spreadsheet-config-server/}")
String spreadsheetConfigServerBaseUri;

@Value("${gridsuite.services.user-identity-server.base-uri:http://user-identity-server/}")
String userIdentityServerBaseUri;
}

This file was deleted.

This file was deleted.

35 changes: 0 additions & 35 deletions src/main/java/org/gridsuite/gateway/endpoints/CgmesGlServer.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -6,14 +6,9 @@
*/
package org.gridsuite.gateway.endpoints;

import lombok.NonNull;
import org.gridsuite.gateway.dto.AccessControlInfos;
import org.springframework.http.HttpMethod;
import org.springframework.http.server.RequestPath;
import org.springframework.http.server.reactive.ServerHttpRequest;

import java.util.*;
import java.util.stream.Collectors;

import static org.springframework.http.HttpMethod.*;

@@ -28,56 +23,7 @@ public interface EndPointElementServer extends EndPointServer {
PUT, POST, DELETE
);

static UUID getUuid(String uuid) {
try {
return UUID.fromString(uuid);
} catch (IllegalArgumentException e) {
return null;
}
}

default UUID getElementUuidIfExist(@NonNull RequestPath path) {
return (path.elements().size() > 5) ? getUuid(path.elements().get(5).value()) : null;
}

default boolean isAllowedMethod(HttpMethod httpMethod) {
return ALLOWED_HTTP_METHODS.contains(httpMethod);
}

default Set<String> getUncontrolledRootPaths() {
return Set.of();
}

default boolean isNotControlledRootPath(String rootPath) {
return getUncontrolledRootPaths().contains(rootPath);
}

@Override
default boolean hasElementsAccessControl() {
return true;
}

default Optional<AccessControlInfos> getAccessControlInfos(@NonNull ServerHttpRequest request) {
RequestPath path = Objects.requireNonNull(request.getPath());
UUID elementUuid = getElementUuidIfExist(path);

// /<elements>/{elementUuid} or /<elements>/**?id=
HttpMethod httpMethod = Objects.requireNonNull(request.getMethod());
if (httpMethod.equals(HEAD) || httpMethod.equals(GET)) {
if (elementUuid != null) {
return Optional.of(AccessControlInfos.create(List.of(elementUuid)));
} else {
if (request.getQueryParams().get(QUERY_PARAM_IDS) == null) {
return Optional.empty();
} else {
List<String> ids = request.getQueryParams().get(QUERY_PARAM_IDS);
List<UUID> elementUuids = ids.stream().map(EndPointElementServer::getUuid).filter(Objects::nonNull).collect(Collectors.toList());
return elementUuids.size() == ids.size() ? Optional.of(AccessControlInfos.create(elementUuids)) : Optional.empty();
}
}
} else if (httpMethod.equals(POST) || httpMethod.equals(PUT) || httpMethod.equals(DELETE)) {
return elementUuid == null ? Optional.empty() : Optional.of(AccessControlInfos.create(List.of(elementUuid)));
}
return Optional.empty();
}
}
67 changes: 0 additions & 67 deletions src/main/java/org/gridsuite/gateway/endpoints/ExploreServer.java
Original file line number Diff line number Diff line change
@@ -6,24 +6,15 @@
*/
package org.gridsuite.gateway.endpoints;

import lombok.NonNull;
import org.gridsuite.gateway.ServiceURIsConfig;
import org.gridsuite.gateway.dto.AccessControlInfos;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpMethod;
import org.springframework.http.server.RequestPath;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.stereotype.Component;

import java.util.*;

/**
* @author Slimane Amar <slimane.amar at rte-france.com>
*/
@Component(value = ExploreServer.ENDPOINT_NAME)
public class ExploreServer implements EndPointElementServer {
private static final Logger LOGGER = LoggerFactory.getLogger(ExploreServer.class);

public static final String ENDPOINT_NAME = "explore";

@@ -36,11 +27,6 @@ public ExploreServer(ServiceURIsConfig servicesURIsConfig) {
this.servicesURIsConfig = servicesURIsConfig;
}

@Override
public UUID getElementUuidIfExist(@NonNull RequestPath path) {
return (path.elements().size() > 7) ? EndPointElementServer.getUuid(path.elements().get(7).value()) : null;
}

@Override
public String getEndpointBaseUri() {
return servicesURIsConfig.getExploreServerBaseUri();
@@ -50,57 +36,4 @@ public String getEndpointBaseUri() {
public String getEndpointName() {
return ENDPOINT_NAME;
}

@Override
public boolean hasElementsAccessControl() {
return true;
}

private UUID getUniqueOptionalUuidFromParam(@NonNull ServerHttpRequest request, @NonNull String queryParamName) {
List<String> ids = request.getQueryParams().get(queryParamName);
if (ids != null && ids.size() != 1) {
throw new IllegalArgumentException("There must be only one " + queryParamName);
}
if (ids != null) {
UUID uuid = EndPointElementServer.getUuid(ids.get(0));
if (uuid == null) {
throw new IllegalArgumentException(queryParamName + " must be an UUID");
}
return uuid;
}
return null;
}

@Override
public Optional<AccessControlInfos> getAccessControlInfos(@NonNull ServerHttpRequest request) {
RequestPath path = Objects.requireNonNull(request.getPath());
UUID elementUuid = getElementUuidIfExist(path);
if (Objects.requireNonNull(request.getMethod()) != HttpMethod.POST) {
return EndPointElementServer.super.getAccessControlInfos(request);
}
// Elements creation
if (elementUuid != null) {
return Optional.of(AccessControlInfos.create(List.of(elementUuid)));
}
try {
List<UUID> uuidsToControl = new ArrayList<>();
UUID duplicateFromUuid = getUniqueOptionalUuidFromParam(request, QUERY_PARAM_DUPLICATE_FROM_ID);
if (duplicateFromUuid != null) {
uuidsToControl.add(duplicateFromUuid);
}
UUID parentDirectoryUuid = getUniqueOptionalUuidFromParam(request, QUERY_PARAM_PARENT_DIRECTORY_ID);
if (parentDirectoryUuid != null) {
uuidsToControl.add(parentDirectoryUuid);
}
if (uuidsToControl.isEmpty()) {
// At least one of the param is required
return Optional.empty();
}
// Check resources access
return Optional.of(AccessControlInfos.create(uuidsToControl));
} catch (IllegalArgumentException e) {
LOGGER.error(e.getMessage());
return Optional.empty();
}
}
}
35 changes: 0 additions & 35 deletions src/main/java/org/gridsuite/gateway/endpoints/GeoDataServer.java

This file was deleted.

Loading

0 comments on commit 9f47a70

Please sign in to comment.