Skip to content

Presales 2007 #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions csv-preview-cae/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@
</dependency>
<dependency>
<groupId>com.coremedia.cms</groupId>
<artifactId>cae-contentbeanservices-api</artifactId>
<artifactId>cae-contentbeanservices</artifactId>
</dependency>
<dependency>
<groupId>com.coremedia.cms</groupId>
<artifactId>cap-unified-api</artifactId>
</dependency>
<dependency>
<groupId>com.coremedia.cms</groupId>
<artifactId>cae-linkservices-api</artifactId>
<artifactId>cae-linkservices</artifactId>
</dependency>
<dependency>
<groupId>com.coremedia.cms</groupId>
Expand Down Expand Up @@ -72,10 +72,6 @@
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.coremedia.csv.cae.utils;

import org.springframework.context.annotation.Bean;
import org.springframework.core.annotation.Order;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
Expand All @@ -9,8 +8,6 @@
import org.springframework.web.cors.CorsConfigurationSource;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;

import java.util.Arrays;

/**
* There are Spring 403 issues that crop up when doing post requests with Spring Enabled Web Security. These revolve
* around CSRF tokens to validate against cross-site vulnerabilities. For the CSV Reporter, which is being called via
Expand All @@ -22,15 +19,14 @@ public class CSVWebSecurityConfiguration extends WebSecurityConfigurerAdapter {

@Override
protected void configure(HttpSecurity http) throws Exception {
http.cors().and().csrf().disable();
http.csrf().disable();
http.headers().disable();
http.cors().configurationSource(corsConfigurationSource());
}

@Bean
CorsConfigurationSource corsConfigurationSource() {
CorsConfiguration configuration = new CorsConfiguration();
configuration.setAllowedOrigins(Arrays.asList("*"));
configuration.setAllowedMethods(Arrays.asList("*"));
configuration.setAllowedHeaders(Arrays.asList("*"));
configuration.applyPermitDefaultValues();
configuration.setAllowCredentials(true);
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", configuration);
Expand Down
8 changes: 4 additions & 4 deletions csv-studio-component/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@
<artifactId>jakarta.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
<!-- <dependency>-->
<!-- <groupId>javax.ws.rs</groupId>-->
<!-- <artifactId>jsr311-api</artifactId>-->
<!-- </dependency>-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.coremedia.csv.studio;

import com.coremedia.cap.content.ContentRepository;
import com.coremedia.rest.cap.CapRestServiceBaseConfiguration;
import com.coremedia.rest.cap.CapRestServiceSearchConfiguration;
import com.coremedia.rest.cap.content.search.CapObjectFormat;
import com.coremedia.rest.cap.content.search.SearchService;
import com.coremedia.rest.linking.LinkResolver;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.PropertySource;

import java.util.List;

@Configuration
@Import({
CapRestServiceBaseConfiguration.class,
CapRestServiceSearchConfiguration.class
})
@PropertySource("classpath:/com/coremedia/csv/studio/csv-defaults.properties")
class CSVConfiguration {

@Bean
public CSVExportResource csvExportResource(CSVFileRetriever csvFileRetriever, ContentRepository contentRepository, SearchService searchService, CapObjectFormat capObjectFormat, LinkResolver linkResolver) {
List<String> authorizedGroups = List.of("reporter");
return new CSVExportResource(csvFileRetriever, contentRepository, searchService, capObjectFormat, true, authorizedGroups, linkResolver);
}

@Bean
public CSVFileRetriever csvFileRetriever(@Value("${studio.previewUrlPrefix}") String previewUrlPrefix, @Value("${studio.previewRestUrlPrefix}") String previewRestUrlPrefix) {
return new CSVFileRetriever(previewUrlPrefix, previewRestUrlPrefix);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,91 +38,47 @@ public class CSVExportResource {
/**
* Sends a request for a CSV file to the preview CAE.
*/
private CSVFileRetriever csvFileRetriever;
private final CSVFileRetriever csvFileRetriever;

/**
* The content repository from which to retrieve content.
*/
private ContentRepository contentRepository;
private final ContentRepository contentRepository;

/**
* The search service with which to search for content.
*/
private SearchService searchService;
private final SearchService searchService;

/**
* The formatter for resolving URIs.
*/
private CapObjectFormat capObjectFormat;
private final CapObjectFormat capObjectFormat;

/**
* Flag indicating whether access to this endpoint should be restricted to authorized groups only
*/
private boolean restrictToAuthorizedGroups;
private final boolean restrictToAuthorizedGroups;

/**
* The groups that are authorized to access this endpoint.
*/
private List<String> authorizedGroups;
private final List<String> authorizedGroups;

/**
* Resolves URI's to Domain Objects.
*/
@Autowired
private LinkResolver linkResolver;
private final LinkResolver linkResolver;

/**
* Sets the CSV file retriever.
*
* @param csvFileRetriever the content repository to set
*/
public void setCsvFileRetriever(CSVFileRetriever csvFileRetriever) {
this.csvFileRetriever = csvFileRetriever;
}

/**
* Sets the content repository.
*
* @param contentRepository the content repository to set
*/
public void setContentRepository(ContentRepository contentRepository) {
public CSVExportResource(CSVFileRetriever csvFileRetriever, ContentRepository contentRepository, SearchService searchService, CapObjectFormat capObjectFormat, boolean restrictToAuthorizedGroups, List<String> authorizedGroups, LinkResolver linkResolver) {
this.csvFileRetriever = csvFileRetriever;
this.contentRepository = contentRepository;
}

/**
* Sets the search service.
*
* @param searchService the search service to set
*/
public void setSearchService(SearchService searchService) {
this.searchService = searchService;
}

/**
* Sets the CapObjectFormat.
*
* @param capObjectFormat the content repository to set
*/
public void setCapObjectFormat(CapObjectFormat capObjectFormat) {
this.capObjectFormat = capObjectFormat;
}

/**
* Set the flag indicating whether access to this endpoint should be restricted to authorized groups only.
*
* @param restrictToAuthorizedGroups the value to set
*/
public void setRestrictToAuthorizedGroups(boolean restrictToAuthorizedGroups) {
this.restrictToAuthorizedGroups = restrictToAuthorizedGroups;
}

/**
* Sets the authorized groups.
*
* @param authorizedGroups the authorized groups to set
*/
public void setAuthorizedGroups(List<String> authorizedGroups) {
this.authorizedGroups = authorizedGroups;
this.linkResolver = linkResolver;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import java.io.IOException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.Iterator;
import java.util.List;

Expand All @@ -25,28 +26,15 @@ public class CSVFileRetriever {
/**
* The URL of the preview CAE.
*/
private String previewUrl;
private final String previewUrl;

/**
* The URL to use for calls to the preview CAE from the studio REST API.
*/
private String previewRestUrl;
private final String previewRestUrl;

/**
* Set the URL of the preview CAE.
*
* @param previewUrl The URL of the preview CAE
*/
public void setPreviewUrl(String previewUrl) {
public CSVFileRetriever(String previewUrl, String previewRestUrl) {
this.previewUrl = previewUrl;
}

/**
* Set the URL to use for calls to the preview CAE from the studio REST API.
*
* @param previewRestUrl The URL to use for calls to the preview CAE from the studio REST API
*/
public void setPreviewRestUrl(String previewRestUrl) {
this.previewRestUrl = previewRestUrl;
}

Expand Down Expand Up @@ -74,7 +62,7 @@ public CSVFileResponse retrieveCSV(String csvTemplate, List<Content> contents) t

// Set up a POST request to the content set export endpoint
CloseableHttpClient client = HttpClients.createDefault();
String requestUrl = getPreviewUrlPrefix() + "/contentsetexport/"+ URLEncoder.encode(csvTemplate, "UTF-8");
String requestUrl = getPreviewUrlPrefix() + "/contentsetexport/"+ URLEncoder.encode(csvTemplate, StandardCharsets.UTF_8);
HttpPost httpPost = new HttpPost(requestUrl);
httpPost.setHeader("Content-Type", "application/json");
HttpEntity requestEntity = new StringEntity(contentIdsList.toString());
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.coremedia.csv.studio.CSVConfiguration
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
studio.previewUrlPrefix=http://localhost:40980/blueprint/servlet
studio.previewRestUrlPrefix=http://localhost:40980/blueprint/servlet