Skip to content

Commit

Permalink
Fix 3.2 DT issues with subprotocol body
Browse files Browse the repository at this point in the history
  • Loading branch information
sachinargade123 committed Nov 27, 2023
1 parent 121baa0 commit 1d3b3c7
Show file tree
Hide file tree
Showing 13 changed files with 108 additions and 110 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## [2.2.2] - 2023-11-21
### Added
- Added oauth security for sde public api.
- BPN url add API path.

### Fixed
- Correct dataplane endpoint for digital twin.
- DSP endpoint path for digital-twin edc url.

## [2.2.1] - 2023-11-27
### Fix
- Update PCF schema fields for SDE
Expand Down
6 changes: 3 additions & 3 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ For more details, please refer configuration section from [README.md](README.md)
```
### RUN SDE Backend Locally
#### Prerequisites
- JDK18
- Postgres 11.9.13
- JDK17
- Postgres 12.12.10

#### Steps
1. Clone the GitHub Repository - https://github.com/eclipse-tractusx/managed-simple-data-exchanger-backend.
2. Get your instance of postgres running (Create **dftdb** new database).
3. Setup your project environment to JDK 18.
3. Setup your project environment to JDK 17.
4. Provide require application configuration in application.properties as specified in step configuration.properties.
5. Start the SDE spring boot application from your IDE using main class or use spring CLI.

Expand Down
2 changes: 1 addition & 1 deletion NOTICE.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ SPDX-License-Identifier: Apache-2.0
The project maintains the following source code repositories
in the GitHub organization https://github.com/eclipse-tractusx:

* https://github.com/eclipse-tractusx/dft-backend
* https://github.com/eclipse-tractusx/managed-simple-data-exchanger-backend


## Third-party Content
Expand Down
41 changes: 39 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,15 @@ Listed below are configuration keys needed to get the `sde-backend` up and runni
| digital-twins.authentication.clientSecret | X | your secrete | Digital twin registry secrete |
| digital-twins.authentication.grantType | X | client_credentials | Default value, no need to change |
| edc.hostname | X | https://example.provider-connector.com | Your EDC provider connector url |
| edc.managementpath | X | default | edc provider management path |
| edc.apiKeyHeader | X | x-api-key | Your connector api key |
| edc.apiKey | X | yourpass | Your connector apikey value |
| edc.consumer.hostname | X | https://example.consumer-connector.com | Your EDC consumer connector |
| edc.consumer.apikeyheader | X | x-api-key | Your connector api key |
| edc.consumer.apikey | X | yourpass | Your connector apikey value |
| edc.consumer.datauri | X | /api/v1/ids/data | IDS endpoint path |
| edc.consumer.protocol.path | X | default | edc consumer protocol path |
| edc.consumer.managementpath | X | default | edc consumer management path |
| dft.hostname | X | https://example.sdehost.com | Your SDE hostname |
| dft.apiKeyHeader | X | API_KEY | Your default key |
| dft.apiKey | X | yourpass | Your default key password |
Expand All @@ -77,7 +80,22 @@ Listed below are configuration keys needed to get the `sde-backend` up and runni
| connector.discovery.clientId | X | default | client ID for connector discovery |
| connector.discovery.clientSecret | X | default | password for connector discovery |
| portal.backend.hostname | X | default | Portal backend svc URL based on BPN|
| springdoc.api-docs.path | X | /api-docs | swagger API path |
| springdoc.api-docs.path | X | default | swagger API path |
| bpndiscovery.hostname | X | default | bpn discovery hostname |
| discovery.authentication.url | X | default | discovery authentication url |
| discovery.clientId | X | default | discovery clientId |
| discovery.clientSecret | X | default | discovery clientSecret |
| discovery.grantType | X | default | discovery grantType |
| partner.pool.hostname | X | default | partner pool hostname |
| partner.pool.authentication.url | X | default | partner pool authentication url |
| partner.pool.clientId | X | default | partner pool clientId |
| partner.pool.clientSecret | X | default | partner pool clientSecret |
| partner.pool.grantType | X | default | partner pool grantType |
| portal.backend.hostname | X | default | portal backend hostname |
| portal.backend.authentication.url | X | default | portal authentication url |
| portal.backend.clientId | X | default | portal clientId |
| portal.backend.clientSecret | X | default | portal clientSecret |
| portal.backend.grantType | X | default | portal grantType |

#### Example Configuration/application.properties

Expand Down Expand Up @@ -170,6 +188,24 @@ portal.backend.authentication.url=default
portal.backend.clientId=default
portal.backend.clientSecret=default
portal.backend.grantType=default
bpndiscovery.hostname=default
discovery.authentication.url=default
discovery.clientId=default
discovery.clientSecret=default
discovery.grantType=default
edc.consumer.protocol.path=default
edc.consumer.managementpath=default
edc.managementpath=default
partner.pool.hostname=default
partner.pool.authentication.url=default
partner.pool.clientId=default
partner.pool.clientSecret=default
partner.pool.grantType=default
portal.backend.hostname=default
portal.backend.authentication.url=default
portal.backend.clientId=default
portal.backend.clientSecret=default
portal.backend.grantType=default
```

The above configuration we can use as for different deployment as specified here [InstallationGuide.md](InstallationGuide.md)
Expand Down Expand Up @@ -329,7 +365,8 @@ Eclipse Tractus-X product(s) installed within the image:
- Project license: [Apache License, Version 2.0] https://github.com/eclipse-tractusx/managed-simple-data-exchanger-backend/blob/main/LICENSE

**Used base image**
- [eclipse-temurin:19-jdk-jammy](https://github.com/adoptium/containers)
- [eclipse-temurin:17.0.9_9-jdk-jammy](https://github.com/adoptium/containers)
ners)
- Official Eclipse Temurin DockerHub page: https://hub.docker.com/_/eclipse-temurin
- Eclipse Temurin Project: https://projects.eclipse.org/projects/adoptium.temurin
- Additional information about the Eclipse Temurin images: https://github.com/docker-library/repo-info/tree/master/repos/eclipse-temurin
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
@EnableMethodSecurity(prePostEnabled = true)
public class SecurityConfig {

private static final String[] PUBLIC_URL = { "/ping", "/cache/**", "/*/public/**", "/api-docs/**", "/swagger-ui/**",
private static final String[] PUBLIC_URL = { "/ping", "/cache/**", "/api-docs/**", "/swagger-ui/**",
"*/swagger-ui/**", "/actuator/health/readiness", "/actuator/health/liveness", "/v3/api-docs/**" };

@Value("${keycloak.clientid}")
Expand Down
2 changes: 2 additions & 0 deletions modules/sde-core/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ edc.hostname=
edc.managementpath=/data/v2
edc.apiKeyHeader=
edc.apiKey=
edc.dsp.endpointpath=/api/v1/dsp
edc.dataplane.endpointpath=/api/public

## EDC Consumer
edc.consumer.hostname=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,17 @@
@FeignClient(value = "IBpndiscoveryExternalServiceApi", url = "${bpndiscovery.hostname}", configuration = BpndiscoveryExternalServiceApi.class)
public interface IBpndiscoveryExternalServiceApi {

@PostMapping(path = "/api/administration/connectors/bpnDiscovery")
@PostMapping(path = "/administration/connectors/bpnDiscovery")
BpnDiscoveryResponse bpnDiscoveryDataByKey(@RequestBody BpnDiscoveryRequest bpnDiscoveryKey);

@PostMapping(path = "/api/administration/connectors/bpnDiscovery/batch")
@PostMapping(path = "/administration/connectors/bpnDiscovery/batch")
List<BpnDiscoveryBatchResponse> bpnDiscoveryBatchDataByList(
@RequestBody List<BpnDiscoveryRequest> bpnDiscoveryKeyList);

@PostMapping(path = "/api/administration/connectors/bpnDiscovery/search")
@PostMapping(path = "/administration/connectors/bpnDiscovery/search")
BpnDiscoverySearchResponse bpnDiscoverySearchData(@RequestBody BpnDiscoverySearchRequest bpnDiscoverySearchRequest);

@DeleteMapping(path = "/api/administration/connectors/bpnDiscovery/{resourceId}")
@DeleteMapping(path = "/administration/connectors/bpnDiscovery/{resourceId}")
ResponseEntity<Object> deleteBpnDiscoveryData(@PathVariable String resourceId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,12 @@ public class DigitalTwinsUtility {
@Value(value = "${manufacturerId}")
public String manufacturerId;

@Value(value = "${edc.hostname}")
public String edcEndpoint;

@Value(value = "${edc.hostname}${edc.dsp.endpointpath:/api/v1/dsp}")
public String digitalTwinEdcDspEndpoint;

@Value(value = "${edc.hostname}${edc.dataplane.endpointpath:/api/public}")
public String digitalTwinEdcDataplaneEndpoint;

ObjectMapper mapper = new ObjectMapper();

private static final Map<String, List<String>> publicReadableSpecificAssetIDs = Map.of(MANUFACTURER_PART_ID,
Expand Down Expand Up @@ -112,12 +115,12 @@ public List<Endpoint> prepareDtEndpoint(String shellId, String submodelIdentific
List<Endpoint> endpoints = new ArrayList<>();
endpoints.add(Endpoint.builder().endpointInterface(CommonConstants.INTERFACE)
.protocolInformation(ProtocolInformation.builder()
.endpointAddress(edcEndpoint + CommonConstants.SUBMODEL_CONTEXT_URL)
.endpointAddress(digitalTwinEdcDataplaneEndpoint)
.endpointProtocol(CommonConstants.HTTP)
.endpointProtocolVersion(List.of(CommonConstants.ENDPOINT_PROTOCOL_VERSION))
.subProtocol(CommonConstants.SUB_PROTOCOL)
.subprotocolBody(encodedUrl("id=" + shellId + "-" + submodelIdentification) + ";dspEndpoint="
+ edcEndpoint)
.subprotocolBody("id=" + shellId + "-" + submodelIdentification + ";dspEndpoint="
+ digitalTwinEdcDspEndpoint)
.subprotocolBodyEncoding(CommonConstants.BODY_ENCODING)
.securityAttributes(List.of(new SecurityAttributes("NONE", "NONE", "NONE"))).build())
.build());
Expand All @@ -144,7 +147,7 @@ public List<Object> getSpecificAssetIds(Map<String, String> specificAssetIds, Li
specificIdentifiers.add(new KeyValuePair(entry.getKey(), entry.getValue(), externalSubjectId));
}
else {
if (keyList != null && !keyList.isEmpty()) {
if (keyList != null && !keyList.isEmpty() && !entry.getValue().isEmpty()) {

externalSubjectId = ExternalSubjectId.builder()
.type("ExternalReference").keys(keyList)
Expand Down Expand Up @@ -172,10 +175,6 @@ private List<Keys> bpnKeyRefrence(List<String> bpns) {
return Collections.emptyList();
}

private String encodedUrl(String format) {
return format.replace(":", "%3A");
}

private String getFieldFromJsonNode(JsonNode jnode, String fieldName) {
if (jnode.get(fieldName) != null)
return jnode.get(fieldName).asText();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,24 @@ public class AssetEntryRequestFactory {

@Value(value = "${dft.apiKeyHeader}")
private String apiKeyHeader;

@Value(value = "${dft.apiKey}")
private String apiKey;

@Value(value = "${dft.hostname}")
private String dftHostname;

@Value(value = "${manufacturerId}")
private String manufacturerId;

@Value(value = "${edc.hostname}")
private String edcEndpoint;

@Value(value = "${spring.security.oauth2.resourceserver.jwt.issuer-uri}/protocol/openid-connect/token")
private String idpIssuerTokenURL;

@Value(value = "${digital-twins.authentication.clientId}")
private String clientId;


public AssetEntryRequest getAssetRequest(String submodel, String assetName, String shellId, String subModelId, String uuid) {
Expand All @@ -77,7 +87,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();
}
Expand All @@ -99,14 +109,20 @@ private HashMap<String, String> getAssetProperties(String assetId, String assetN
return assetProperties;
}

private HashMap<String, String> getDataAddressProperties(String shellId, String subModelId, String endpoint) {
HashMap<String, String> dataAddressProperties = new HashMap<>();
dataAddressProperties.put("type", TYPE);
dataAddressProperties.put("baseUrl", String.format(endpoint, shellId, subModelId));
dataAddressProperties.put("name", NAME);
dataAddressProperties.put("authKey", apiKeyHeader);
dataAddressProperties.put("authCode", apiKey);
return dataAddressProperties;
}
private HashMap<String, String> getDataAddressProperties(String shellId, String subModelId, String endpoint) {
HashMap<String, String> dataAddressProperties = new HashMap<>();
dataAddressProperties.put("type", TYPE);
dataAddressProperties.put("baseUrl", String.format(endpoint, shellId, subModelId));
dataAddressProperties.put("name", NAME);
dataAddressProperties.put("oauth2:tokenUrl", idpIssuerTokenURL);
dataAddressProperties.put("oauth2:clientId", clientId);
dataAddressProperties.put("oauth2:clientSecretKey", "client-secret");
dataAddressProperties.put("proxyMethod", "true");
dataAddressProperties.put("proxyBody", "true");
dataAddressProperties.put("proxyPath", "true");
dataAddressProperties.put("proxyQueryParams", "true");
dataAddressProperties.put("contentType", ASSET_PROP_CONTENT_TYPE);
return dataAddressProperties;
}

}
Loading

0 comments on commit 1d3b3c7

Please sign in to comment.