Skip to content

Commit

Permalink
Merge pull request #64 from catenax-ng/support_edc_edr_api_use
Browse files Browse the repository at this point in the history
[feat|sde] support edr api for the consume data.
  • Loading branch information
almadigabor authored Sep 20, 2023

Verified

This commit was signed with the committer’s verified signature. The key has expired.
jcronenberg Jorik Cronenberg
2 parents c6fa04a + ca55098 commit b54be11
Showing 13 changed files with 410 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -59,6 +59,7 @@ public void doFilter(ServletRequest servletRequest, ServletResponse servletRespo
Authentication auth = SecurityContextHolder.getContext().getAuthentication();

if (url.contains("/public") && !apiKeyValue.equals(authHeaderValue)) {
log.error(url+"-"+apiKeyValue +"-"+authHeaderValue+"-"+apiKeyHeader);
log.error("**** ApiHeaderAuthFilter genreated Unauthorized response for public api *****************");
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
} else if(auth !=null && auth.getAuthorities()!=null && auth.getAuthorities().isEmpty()){
Original file line number Diff line number Diff line change
@@ -68,4 +68,20 @@ public ResponseEntity<Object> subscribeDataOffers(@Valid @RequestBody ConsumerRe
consumerControlPanelService.subscribeDataOffers(consumerRequest, processId);
return ResponseEntity.ok().body(processId);
}

@PostMapping(value = "/subscribe-download-data")
@PreAuthorize("hasPermission('','consumer_download_data')")
public ResponseEntity<Object> subscribeAndDownloadDataOffers(@Valid @RequestBody ConsumerRequest consumerRequest) {
log.info("Request recevied : /api/subscribe-download-data-edr");
return ResponseEntity.ok().body(consumerControlPanelService.subscribeAndDownloadDataOffers(consumerRequest));
}

@GetMapping(value = "/download-data")
@PreAuthorize("hasPermission('','consumer_download_data')")
public ResponseEntity<Object> downloadFileFromEDCUsingifAlreadyTransferStatusCompleted(@RequestParam String assetId)
throws Exception {
log.info("Request received : /api/download-data-using-edr");
return ok().body(consumerControlPanelService.downloadFileFromEDCUsingifAlreadyTransferStatusCompleted(assetId));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/********************************************************************************
* Copyright (c) 2023 T-Systems International GmbH
* Copyright (c) 2023 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/
INSERT INTO sde_permission (sde_permission,description)
VALUES ('consumer_download_data','Allows consumer user to download data');

INSERT INTO sde_role_permission_mapping (sde_permission,sde_role)
VALUES ('consumer_download_data','User');

INSERT INTO sde_role_permission_mapping (sde_permission,sde_role)
VALUES ('consumer_download_data','Creator');

Original file line number Diff line number Diff line change
@@ -40,6 +40,7 @@
import org.eclipse.tractusx.sde.edc.entities.request.policies.Operator;
import org.eclipse.tractusx.sde.edc.entities.request.policies.PolicyConstraintBuilderService;
import org.eclipse.tractusx.sde.edc.facilitator.ContractNegotiateManagementHelper;
import org.eclipse.tractusx.sde.edc.facilitator.EDRRequestHelper;
import org.eclipse.tractusx.sde.edc.gateways.database.ContractNegotiationInfoRepository;
import org.eclipse.tractusx.sde.edc.model.contractoffers.ContractOfferRequestFactory;
import org.eclipse.tractusx.sde.edc.model.request.ConsumerRequest;
@@ -80,6 +81,9 @@ class ConsumerControlPanelServiceTest {

@Autowired
private ConsumerControlPanelService consumerControlPanelService;

@MockBean
private EDRRequestHelper edrRequestHelper;

@MockBean
private ContractOfferCatalogApi contractOfferCatalogApi;
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@

import com.fasterxml.jackson.databind.JsonNode;

@FeignClient(value = "ContractOfferCatalogApi", url = "${edc.consumer.hostname}${edc.consumer.managementpath:/data/v2}", configuration = EDCDataConsumerConfiguration.class)
@FeignClient(value = "ContractOfferCatalogApi", url = "${edc.consumer.hostname}${edc.consumer.managementpath:/data}${edc.consumer.managementpath.apiversion:/v2}", configuration = EDCDataConsumerConfiguration.class)
public interface ContractOfferCatalogApi {

@PostMapping(value = "/catalog/request")
Original file line number Diff line number Diff line change
@@ -31,7 +31,7 @@
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

@FeignClient(value = "EDCFeignClientApi", url = "${edc.hostname}${edc.managementpath:/data/v2}", configuration = EDCDataProviderConfiguration.class)
@FeignClient(value = "EDCFeignClientApi", url = "${edc.hostname}${edc.managementpath:/data}${edc.managementpath.apiversion:/v2}", configuration = EDCDataProviderConfiguration.class)
public interface EDCFeignClientApi {

@GetMapping(path = "/assets/{id}")
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/********************************************************************************
* Copyright (c) 2023 T-Systems International GmbH
* Copyright (c) 2023 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/

package org.eclipse.tractusx.sde.edc.api;

import java.net.URI;
import java.util.List;
import java.util.Map;

import org.eclipse.tractusx.sde.edc.model.contractnegotiation.AcknowledgementId;
import org.eclipse.tractusx.sde.edc.model.contractnegotiation.ContractNegotiations;
import org.eclipse.tractusx.sde.edc.model.edr.EDRCachedByIdResponse;
import org.eclipse.tractusx.sde.edc.model.edr.EDRCachedResponse;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestParam;

@FeignClient(value = "EDRApiProxy", url = "placeholder")
public interface EDRApiProxy {

@PostMapping(path = "/edrs", consumes = MediaType.APPLICATION_JSON_VALUE)
AcknowledgementId edrCacheCreate(URI url, @RequestBody ContractNegotiations requestBody,
@RequestHeader Map<String, String> requestHeader);

@GetMapping(path = "/edrs", consumes = MediaType.APPLICATION_JSON_VALUE)
List<EDRCachedResponse> getEDRCachedByAsset(URI url, @RequestParam("assetId") String assetId,
@RequestHeader Map<String, String> requestHeader);

@GetMapping(path = "/edrs/{transferProcessId}")
EDRCachedByIdResponse getEDRCachedByTransferProcessId(URI url,
@PathVariable("transferProcessId") String transferProcessId,
@RequestHeader Map<String, String> requestHeader);

@GetMapping
Object getActualDataFromProviderDataPlane(URI url, @RequestHeader Map<String, String> requestHeader);

}
Original file line number Diff line number Diff line change
@@ -77,7 +77,7 @@ private AssetEntryRequest buildAsset(String submodel, String shellId, String sub
private String subModelPayloadUrl(String submodel, String uuid) {
return UriComponentsBuilder
.fromHttpUrl(dftHostname)
.path("/api/"+submodel+"/public/")
.path(submodel+"/public/")
.path(uuid)
.toUriString();
}
Original file line number Diff line number Diff line change
@@ -27,9 +27,12 @@

public class AbstractEDCStepsHelper {

@Value("${edc.consumer.hostname}${edc.consumer.managementpath:/data/v2}")
@Value("${edc.consumer.hostname}${edc.consumer.managementpath:/data}${edc.consumer.managementpath.apiversion:/v2}")
protected String consumerHost;


@Value("${edc.consumer.hostname}${edc.consumer.managementpath:/data}")
protected String consumerHostWithDataPath;

@Value("${edc.consumer.hostname}")
protected String consumerHostWithoutDataPath;

@@ -39,9 +42,12 @@ public class AbstractEDCStepsHelper {
@Value("${edc.consumer.apikey}")
private String edcApiKeyValue;

@Value("${edc.hostname}${edc.managementpath:/data/v2}")
@Value("${edc.hostname}${edc.managementpath:/data}${edc.managementpath.apiversion:/v2}")
protected String providerHost;


@Value("${edc.hostname}${edc.managementpath:/data}")
protected String providerHostWithManagementPath;

@Value("${edc.hostname}")
protected String providerHostWithoutDataPath;

Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/********************************************************************************
* Copyright (c) 2023 T-Systems International GmbH
* Copyright (c) 2023 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/

package org.eclipse.tractusx.sde.edc.facilitator;

import java.net.URI;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.eclipse.tractusx.sde.edc.api.EDRApiProxy;
import org.eclipse.tractusx.sde.edc.entities.request.policies.ActionRequest;
import org.eclipse.tractusx.sde.edc.mapper.ContractMapper;
import org.eclipse.tractusx.sde.edc.model.contractnegotiation.AcknowledgementId;
import org.eclipse.tractusx.sde.edc.model.contractnegotiation.ContractNegotiations;
import org.eclipse.tractusx.sde.edc.model.edr.EDRCachedByIdResponse;
import org.eclipse.tractusx.sde.edc.model.edr.EDRCachedResponse;
import org.springframework.stereotype.Service;

import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;

@Service
@RequiredArgsConstructor
public class EDRRequestHelper extends AbstractEDCStepsHelper {

private final EDRApiProxy edrApiProxy;
private final ContractMapper contractMapper;

@SneakyThrows
public String edrRequestInitiate(String providerUrl, String providerId, String offerId, String assetId,
ActionRequest action, Map<String, String> extensibleProperty) {

ContractNegotiations contractNegotiations = contractMapper
.prepareContractNegotiations(providerUrl + protocolPath, offerId, assetId, providerId, action);

AcknowledgementId acknowledgementId = edrApiProxy.edrCacheCreate(new URI(consumerHostWithDataPath), contractNegotiations,
getAuthHeader());
return acknowledgementId.getId();
}

@SneakyThrows
public List<EDRCachedResponse> getEDRCachedByAsset(String assetId) {
return edrApiProxy.getEDRCachedByAsset(new URI(consumerHostWithDataPath), assetId, getAuthHeader());
}

@SneakyThrows
public EDRCachedByIdResponse getEDRCachedByTransferProcessId(String transferProcessId) {
return edrApiProxy.getEDRCachedByTransferProcessId(new URI(consumerHostWithDataPath), transferProcessId, getAuthHeader());
}

@SneakyThrows
public Object getDataFromProvider(EDRCachedByIdResponse authorizationToken) {
Map<String, String> authHeader = new HashMap<>();
authHeader.put(authorizationToken.getAuthKey(), authorizationToken.getAuthCode());
return edrApiProxy.getActualDataFromProviderDataPlane(new URI(authorizationToken.getEndpoint()), authHeader);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/********************************************************************************
* Copyright (c) 2023 T-Systems International GmbH
* Copyright (c) 2023 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/

package org.eclipse.tractusx.sde.edc.model.edr;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(Include.NON_NULL)
public class EDRCachedByIdResponse {

@JsonProperty("edc:type")
private String type;

@JsonProperty("edc:authCode")
private String authCode;

@JsonProperty("edc:endpoint")
private String endpoint;

@JsonProperty("edc:id")
private String id;

@JsonProperty("edc:authKey")
private String authKey;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/********************************************************************************
* Copyright (c) 2023 T-Systems International GmbH
* Copyright (c) 2023 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/

package org.eclipse.tractusx.sde.edc.model.edr;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(Include.NON_NULL)
public class EDRCachedResponse {

@JsonProperty("@type")
private String type;

@JsonProperty("@context")
private Object context;

@JsonProperty("edc:agreementId")
private String agreementId;

@JsonProperty("edc:transferProcessId")
private String transferProcessId;

@JsonProperty("edc:assetId")
private String assetId;

@JsonProperty("edc:providerId")
private String providerId;

@JsonProperty("tx:edrState")
private String edrState;

@JsonProperty("tx:expirationDate")
private String expirationDate;

}
Loading

0 comments on commit b54be11

Please sign in to comment.