Skip to content
This repository has been archived by the owner on Jul 18, 2024. It is now read-only.

Commit

Permalink
Merge pull request #65 from catenax-ng/main
Browse files Browse the repository at this point in the history
Feat: Implement EDC with Generic Endpoint
  • Loading branch information
nicoprow authored Jan 4, 2024
2 parents 5a8893a + d032176 commit e4864ec
Show file tree
Hide file tree
Showing 44 changed files with 2,161 additions and 512 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

# Changelog

## [1.3.0] - [unreleased]

### Changed
- BPDM endpoints changed for requesting EDC when available
- Logic mapping changed between Gate Pool and Country Risk DTO

### Added
- Added mapping for generic Endpoint
- Added mapping for Pool lsa types

## [1.2.3] - 2023-11-30

### Fixes
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
</parent>
<groupId>org.eclipse.tractusx</groupId>
<artifactId>value-added-service</artifactId>
<version>1.2.3</version>
<version>1.3.0</version>
<name>vas-country-risk-backend</name>
<description>Project to Validate Country Risks Score</description>
<properties>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/********************************************************************************
* Copyright (c) 2022,2023 BMW Group AG
* Copyright (c) 2022,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.valueaddedservice.config;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.security.oauth2.client.AuthorizedClientServiceOAuth2AuthorizedClientManager;
import org.springframework.security.oauth2.client.OAuth2AuthorizedClientProvider;
import org.springframework.security.oauth2.client.OAuth2AuthorizedClientProviderBuilder;
import org.springframework.security.oauth2.client.OAuth2AuthorizedClientService;
import org.springframework.security.oauth2.client.registration.ClientRegistrationRepository;
import org.springframework.security.oauth2.client.web.reactive.function.client.ServletOAuth2AuthorizedClientExchangeFilterFunction;
import org.springframework.web.reactive.function.client.WebClient;

@Configuration
public class GateWebClientConfiguration {

@Value("${security.enabled}")
private boolean isSecurityEnabled;

@Value("${vas.gateClient.name}")
private String clientName;

@Bean
@Qualifier("gateWebClient")
@ConditionalOnProperty(prefix = "security", name = "enabled", havingValue = "true")
public WebClient gateWebClient(ClientRegistrationRepository clientRegistrationRepository, OAuth2AuthorizedClientService authorizedClientService) {
OAuth2AuthorizedClientProvider authorizedClientProvider = OAuth2AuthorizedClientProviderBuilder.builder().clientCredentials().build();
AuthorizedClientServiceOAuth2AuthorizedClientManager authorizedClientManager = new AuthorizedClientServiceOAuth2AuthorizedClientManager(clientRegistrationRepository, authorizedClientService);
authorizedClientManager.setAuthorizedClientProvider(authorizedClientProvider);

ServletOAuth2AuthorizedClientExchangeFilterFunction oauth = new ServletOAuth2AuthorizedClientExchangeFilterFunction(authorizedClientManager);
oauth.setDefaultClientRegistrationId(clientName);
return WebClient.builder()
.apply(oauth.oauth2Configuration())
.defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
.build();
}

@Bean
@Qualifier("gateWebClient")
@ConditionalOnProperty(prefix = "security", name = "enabled", havingValue = "false")
public WebClient gateWebClientNoAuth() {
return WebClient.builder().build();

}


}

Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
********************************************************************************/
package org.eclipse.tractusx.valueaddedservice.config;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
Expand All @@ -34,18 +35,19 @@
import org.springframework.web.reactive.function.client.WebClient;

@Configuration
public class WebClientConfiguration {
public class PoolWebClientConfiguration {

@Value("${security.enabled}")
private boolean isSecurityEnabled;

@Value("${vas.clientName}")
@Value("${vas.poolClient.name}")
private String clientName;


@Bean
@Qualifier("poolWebClient")
@ConditionalOnProperty(prefix = "security", name = "enabled", havingValue = "true")
public WebClient webClient(ClientRegistrationRepository clientRegistrationRepository, OAuth2AuthorizedClientService authorizedClientService) {
public WebClient poolWebClient(ClientRegistrationRepository clientRegistrationRepository, OAuth2AuthorizedClientService authorizedClientService) {
OAuth2AuthorizedClientProvider authorizedClientProvider = OAuth2AuthorizedClientProviderBuilder.builder().clientCredentials().build();
AuthorizedClientServiceOAuth2AuthorizedClientManager authorizedClientManager = new AuthorizedClientServiceOAuth2AuthorizedClientManager(clientRegistrationRepository, authorizedClientService);
authorizedClientManager.setAuthorizedClientProvider(authorizedClientProvider);
Expand All @@ -59,8 +61,9 @@ public WebClient webClient(ClientRegistrationRepository clientRegistrationReposi
}

@Bean
@Qualifier("poolWebClient")
@ConditionalOnProperty(prefix = "security", name = "enabled", havingValue = "false")
public WebClient webClientNoAuth() {
public WebClient poolWebClientNoAuth() {
return WebClient.builder().build();

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public SecurityFilterChain securityFilterChain(final HttpSecurity httpSecurity)
.sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and()
.authorizeHttpRequests()
.requestMatchers("/error","/api/dashboard/**","/api/sharing/**")
.requestMatchers("/error","/api/dashboard/**","/api/sharing/**","/api/edc/**")
.authenticated()
.requestMatchers("/v3/api-docs/**", "/swagger-ui.html", "/swagger-ui/**","/management/**")
.permitAll()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ private VasConstants() {
public static final String CSV_ROLE_TYPE_COMPANY = "Company";

public static final String CSV_ROLE_COMPANY_ADMIN = "Company Admin";
public static final String CSV_ROLE_READ_SUPPLIER = "read_suppliers";
public static final String CSV_ROLE_READ_CUSTOMER = "read_customers";
public static final String CSV_ROLE_READ_SUPPLIER = "Supplier";
public static final String CSV_ROLE_READ_CUSTOMER = "Customer";


public static final String REQUEST_COMPANY_NAME = "companyName";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/********************************************************************************
* Copyright (c) 2022,2023 BMW Group AG
* Copyright (c) 2022,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.valueaddedservice.domain.enumeration;

public enum AddressType {
LegalAndSiteMainAddress,
LegalAddress,
SiteMainAddress,
AdditionalAddress
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/********************************************************************************
* Copyright (c) 2022,2023 BMW Group AG
* Copyright (c) 2022,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.valueaddedservice.domain.enumeration;

public enum BusinessPartnerRole {
SUPPLIER,
CUSTOMER
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ public class AuthPropertiesDTO implements Serializable {
@JsonProperty("isAdmin")
private Boolean isAdmin = false;


@Schema(example = "16a5s4qewqwhqwjhehjv")
@NotNull
@JsonProperty("edcToken")
private String edcToken = "";;

public List<String> getRoles(String clientId){
LinkedHashMap list = (LinkedHashMap) resourceAccess;
LinkedHashMap clientResources = list.get(clientId) != null ? (LinkedHashMap) list.get(clientId):new LinkedHashMap();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/********************************************************************************
* Copyright (c) 2022,2023 BMW Group AG
* Copyright (c) 2022,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.valueaddedservice.dto.bpdm;

import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import lombok.*;
import org.eclipse.tractusx.valueaddedservice.dto.bpdm.deserializers.AlternativePostalAddressDtoDeserializer;
import org.eclipse.tractusx.valueaddedservice.dto.bpdm.gate.GateGeoCoordinateDto;
import org.eclipse.tractusx.valueaddedservice.dto.bpdm.pool.PoolAdministrativeAreaLevel;

@Getter
@Setter
@ToString
@AllArgsConstructor
@NoArgsConstructor
@JsonDeserialize(using = AlternativePostalAddressDtoDeserializer.class)
public class AlternativePostalAddressDto {
private GateGeoCoordinateDto geographicCoordinates;
private String country;
private PoolAdministrativeAreaLevel administrativeAreaLevel1;
private String simpleAdministrativeAreaLevel1;
private PoolAdministrativeAreaLevel administrativeAreaLevel2;
private String simpleAdministrativeAreaLevel2;
private PoolAdministrativeAreaLevel administrativeAreaLevel3;
private String simpleAdministrativeAreaLevel3;
private String postalCode;
private String city;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/********************************************************************************
* Copyright (c) 2022,2023 BMW Group AG
* Copyright (c) 2022,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.valueaddedservice.dto.bpdm;

import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.eclipse.tractusx.valueaddedservice.dto.bpdm.deserializers.PhysicalPostalAddressDtoDeserializer;
import org.eclipse.tractusx.valueaddedservice.dto.bpdm.gate.GateGeoCoordinateDto;
import org.eclipse.tractusx.valueaddedservice.dto.bpdm.gate.GateStreetDto;
import org.eclipse.tractusx.valueaddedservice.dto.bpdm.pool.PoolAdministrativeAreaLevel;

@Getter
@Setter
@ToString

@JsonDeserialize(using = PhysicalPostalAddressDtoDeserializer.class)
public class PhysicalPostalAddressDto {
private GateGeoCoordinateDto geographicCoordinates;
private String country;

private PoolAdministrativeAreaLevel administrativeAreaLevel1;
private String simpleAdministrativeAreaLevel1;

private PoolAdministrativeAreaLevel administrativeAreaLevel2;
private String simpleAdministrativeAreaLevel2;

private PoolAdministrativeAreaLevel administrativeAreaLevel3;
private String simpleAdministrativeAreaLevel3;

private String postalCode;
private String city;
private String district;
private GateStreetDto street;
private String companyPostalCode;
private String industrialZone;
private String building;
private String floor;
private String door;
}
Loading

0 comments on commit e4864ec

Please sign in to comment.