Skip to content

Commit

Permalink
Merge pull request #144 from catenax-ng/support_edc_0.4.1
Browse files Browse the repository at this point in the history
Support edc 0.4.1
  • Loading branch information
adityagajbhiye9 authored Jun 27, 2023
2 parents 49d64a9 + 74fbf71 commit a51989b
Show file tree
Hide file tree
Showing 79 changed files with 1,582 additions and 1,611 deletions.
1 change: 1 addition & 0 deletions build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@ EXPOSE 8080

CMD ["java", "-jar", "./app.jar","--spring.config.location=file:/app/configuration.properties"]


Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.oauth2.jwt.Jwt;
import org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationToken;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.header.writers.XXssProtectionHeaderWriter.HeaderValue;
import org.springframework.security.web.util.matcher.AnyRequestMatcher;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.CorsConfigurationSource;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
Expand Down Expand Up @@ -99,36 +99,36 @@ public SecurityFilterChain filterChain(HttpSecurity http, Jwt2AuthenticationConv
ServerProperties serverProperties) {

// Enable OAuth2 with custom authorities mapping
http.oauth2ResourceServer().jwt().jwtAuthenticationConverter(authenticationConverter);
http.oauth2ResourceServer(oauth -> oauth.jwt(jwt -> jwt.jwtAuthenticationConverter(authenticationConverter)));

// Enable anonymous
http.anonymous();

// Enable and configure CORS
http.cors().configurationSource(corsConfigurationSource());
http.cors(cors -> cors.configurationSource(corsConfigurationSource()));

// State-less session (state in access-token only)
http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
http.sessionManagement(
sessionManagement -> sessionManagement.sessionCreationPolicy(SessionCreationPolicy.STATELESS));

// Disable CSRF because of state-less session-management
http.csrf().disable();
http.csrf(AbstractHttpConfigurer::disable);

// Route security: authenticated to all routes but actuator and Swagger-UI
// @formatter:off
http.authorizeHttpRequests()
.requestMatchers(PUBLIC_URL).permitAll()
.anyRequest().authenticated();
// @formatter:on

http.headers().xssProtection(xssProtection -> xssProtection.headerValue(HeaderValue.ENABLED_MODE_BLOCK));

http.headers()
.contentSecurityPolicy("default-src 'self'; script-src 'self'").and()
.httpStrictTransportSecurity().requestMatcher(AnyRequestMatcher.INSTANCE);
http.authorizeHttpRequests(authz -> authz
.requestMatchers(PUBLIC_URL).permitAll()
.anyRequest().authenticated());

// @formatter:on
http.headers(headers -> headers
.xssProtection(xssProtection -> xssProtection.headerValue(HeaderValue.ENABLED_MODE_BLOCK))
.contentSecurityPolicy(policy -> policy.policyDirectives("default-src 'self'; script-src 'self'"))
.httpStrictTransportSecurity(httStrict -> httStrict.includeSubDomains(true).maxAgeInSeconds(15724800)));

return http.build();
}

@Bean
protected CorsConfigurationSource corsConfigurationSource() {
// Very permissive CORS config...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public ResponseEntity<Object> queryOnDataOffers(@RequestParam String providerUrl
if (offset == null) {
offset = 0;
}
return ok().body(consumerControlPanelService.queryOnDataOffers(providerUrl, limit, offset));
return ok().body(consumerControlPanelService.queryOnDataOffers(providerUrl, limit, offset, null));
}

@PostMapping(value = "/subscribe-data-offers")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;

import org.apache.commons.lang3.StringUtils;
import org.eclipse.tractusx.sde.common.entities.SubmodelFileRequest;
import org.eclipse.tractusx.sde.common.entities.SubmodelJsonRequest;
import org.eclipse.tractusx.sde.common.entities.csv.CsvContent;
Expand Down
4 changes: 3 additions & 1 deletion modules/sde-core/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,16 @@ digital-twins.authentication.grantType=client_credentials

## EDC Provider
edc.hostname=
edc.managementpath=/data/v2
edc.apiKeyHeader=
edc.apiKey=

## EDC Consumer
edc.consumer.hostname=
edc.consumer.apikeyheader=
edc.consumer.apikey=
edc.consumer.datauri=/api/v1/ids/data
edc.consumer.managementpath=/data/v2
edc.consumer.protocol.path=/api/v1/dsp

## DFT configuration for EDC
dft.hostname=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,80 +50,71 @@

import com.fasterxml.jackson.databind.ObjectMapper;

@ContextConfiguration(classes = {ConsumerController.class})
@ContextConfiguration(classes = { ConsumerController.class })
@ExtendWith(SpringExtension.class)
class ConsumerControllerTest {
@MockBean
private ConsumerControlPanelService consumerControlPanelService;
@MockBean
private ConsumerControlPanelService consumerControlPanelService;

@Autowired
private ConsumerController consumerController;
@Autowired
private ConsumerController consumerController;

@Test
void testQueryOnDataOfferWithoutOfferModel() throws Exception {
when(consumerControlPanelService.queryOnDataOffers((String) any(), anyInt(), anyInt())).thenReturn(new ArrayList<>());
MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.get("/query-data-offers")
.param("providerUrl", "foo");
MockMvcBuilders.standaloneSetup(consumerController)
.build()
.perform(requestBuilder)
.andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(MockMvcResultMatchers.content().contentType("application/json"))
.andExpect(MockMvcResultMatchers.content().string("[]"));
}
@Test
void testQueryOnDataOfferWithoutOfferModel() throws Exception {
when(consumerControlPanelService.queryOnDataOffers((String) any(), anyInt(), anyInt(), any()))
.thenReturn(new ArrayList<>());
MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.get("/query-data-offers")
.param("providerUrl", "foo");
MockMvcBuilders.standaloneSetup(consumerController).build().perform(requestBuilder)
.andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(MockMvcResultMatchers.content().contentType("application/json"))
.andExpect(MockMvcResultMatchers.content().string("[]"));
}

@Test
void testQueryOnDataOffersWithOfferModel() throws Exception {
ArrayList<QueryDataOfferModel> queryDataOfferModelList = new ArrayList<>();
queryDataOfferModelList.add(new QueryDataOfferModel());
when(consumerControlPanelService.queryOnDataOffers((String) any(), anyInt(), anyInt(), any()))
.thenReturn(queryDataOfferModelList);
MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.get("/query-data-offers")
.param("providerUrl", "foo");
MockMvcBuilders.standaloneSetup(consumerController).build().perform(requestBuilder)
.andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(MockMvcResultMatchers.content().contentType("application/json"))
.andExpect(MockMvcResultMatchers.content().string(
"[{\"connectorId\":null,\"assetId\":null,\"offerId\":null,\"connectorOfferUrl\":null,\"title\":null,\"type\":null,\"version\":null,\"description\":null,\"fileName\":null,\"fileContentType\":null,\"created\":null,\"modified\":null,\"publisher\":null,\"typeOfAccess\":null,\"bpnNumbers\":null,\"policyId\":null,\"usagePolicies\":null}]"));
}

@Test
void testSubscribeDataOffersBadRequest() throws Exception {
doNothing().when(consumerControlPanelService).subscribeDataOffers((ConsumerRequest) any(), anyString());

@Test
void testQueryOnDataOffersWithOfferModel() throws Exception {
ArrayList<QueryDataOfferModel> queryDataOfferModelList = new ArrayList<>();
queryDataOfferModelList.add(new QueryDataOfferModel());
when(consumerControlPanelService.queryOnDataOffers((String) any(), anyInt(), anyInt())).thenReturn(queryDataOfferModelList);
MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.get("/query-data-offers")
.param("providerUrl", "foo");
MockMvcBuilders.standaloneSetup(consumerController)
.build()
.perform(requestBuilder)
.andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(MockMvcResultMatchers.content().contentType("application/json"))
.andExpect(MockMvcResultMatchers.content()
.string(
"[{\"connectorId\":null,\"assetId\":null,\"offerId\":null,\"connectorOfferUrl\":null,\"title\":null,\"version\":null,\"description\":null,\"fileName\":null,\"fileContentType\":null,\"created\":null,\"modified\":null,\"publisher\":null,\"typeOfAccess\":null,\"bpnNumbers\":null,\"policyId\":null,\"usagePolicies\":null}]"));
}
ConsumerRequest consumerRequest = ConsumerRequest.builder().connectorId("42").offers(new ArrayList<>())
.policies(new ArrayList<>()).providerUrl("\"https://example.org/example\"").build();
String content = (new ObjectMapper()).writeValueAsString(consumerRequest);
MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.post("/subscribe-data-offers")
.contentType(MediaType.APPLICATION_JSON).content(content);
MockMvcBuilders.standaloneSetup(consumerController).build().perform(requestBuilder)
.andExpect(MockMvcResultMatchers.status().isBadRequest());
}

@Test
void testSubscribeDataOffersBadRequest() throws Exception {
doNothing().when(consumerControlPanelService).subscribeDataOffers((ConsumerRequest) any(), anyString());

ConsumerRequest consumerRequest = ConsumerRequest.builder().connectorId("42").offers(new ArrayList<>()).policies(new ArrayList<>()).providerUrl("\"https://example.org/example\"").build();
String content = (new ObjectMapper()).writeValueAsString(consumerRequest);
MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.post("/subscribe-data-offers")
.contentType(MediaType.APPLICATION_JSON)
.content(content);
MockMvcBuilders.standaloneSetup(consumerController)
.build()
.perform(requestBuilder)
.andExpect(MockMvcResultMatchers.status().isBadRequest());
}

//@Test
void testSubscribeDataOffers() throws Exception {
doNothing().when(consumerControlPanelService).subscribeDataOffers((ConsumerRequest) any(), anyString());
List<OfferRequest> offers = new ArrayList<>();
List<UsagePolicies> policies = new ArrayList<>();
OfferRequest mockOffer = Mockito.mock(OfferRequest.class);
offers.add(mockOffer);
UsagePolicies mockPolicy = Mockito.mock(UsagePolicies.class);
policies.add(mockPolicy);
ConsumerRequest consumerRequest = ConsumerRequest.builder().connectorId("42").offers(offers).policies(policies).providerUrl("\"https://example.org/example\"").build();
String content = (new ObjectMapper()).writeValueAsString(consumerRequest);
MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.post("/subscribe-data-offers")
.contentType(MediaType.APPLICATION_JSON)
.content(content);
MockMvcBuilders.standaloneSetup(consumerController)
.build()
.perform(requestBuilder)
.andExpect(MockMvcResultMatchers.status().isOk());
}
// @Test
void testSubscribeDataOffers() throws Exception {
doNothing().when(consumerControlPanelService).subscribeDataOffers((ConsumerRequest) any(), anyString());
List<OfferRequest> offers = new ArrayList<>();
List<UsagePolicies> policies = new ArrayList<>();
OfferRequest mockOffer = Mockito.mock(OfferRequest.class);
offers.add(mockOffer);
UsagePolicies mockPolicy = Mockito.mock(UsagePolicies.class);
policies.add(mockPolicy);
ConsumerRequest consumerRequest = ConsumerRequest.builder().connectorId("42").offers(offers).policies(policies)
.providerUrl("\"https://example.org/example\"").build();
String content = (new ObjectMapper()).writeValueAsString(consumerRequest);
MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.post("/subscribe-data-offers")
.contentType(MediaType.APPLICATION_JSON).content(content);
MockMvcBuilders.standaloneSetup(consumerController).build().perform(requestBuilder)
.andExpect(MockMvcResultMatchers.status().isOk());
}

}
Loading

0 comments on commit a51989b

Please sign in to comment.