From d1bf845c8015e11cd5c4bb93ecdc414879ee9cc5 Mon Sep 17 00:00:00 2001 From: Lauren Ward Date: Thu, 15 Apr 2021 15:30:29 -0600 Subject: [PATCH 1/6] Update commandline properties to reflect format support by latest Spring and maven plugins --- README.md | 6 +++++- .../springdocs/config/CorsOriginUpdater.java | 13 +++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index f60dfc4..fd0ca4c 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ are used to configure these various services, as explained below. The Content Service can be started locally using the following command: ~~~ -~/spring-docs/spring-docs/$ mvn spring-boot:run [-Dspring.profiles.active=, [, google-classification]] +~/spring-docs/spring-docs/$ mvn spring-boot:run [-Dspring-boot.run.profiles=, [, google-classification]] ~~~ ### Database Profiles @@ -83,6 +83,10 @@ Document classification can be enabled by adding the `google-classification` to By default the application is configured to allow any client to connect. You can specify the environment variable `SPRINGDOCS_ALLOW_HOST` to specify the host to allow, restricting all others. +~~~ +~/spring-docs/spring-docs/$ mvn spring-boot:run -Dspring-boot.run.jvmArguments="-DSPRINGDOCS_ALLOW_HOST=http://localhost:8080" +~~~ + ## Running the UI Service The user interface service can be started using the following command: diff --git a/spring-docs/src/main/java/com/github/paulcwarren/springdocs/config/CorsOriginUpdater.java b/spring-docs/src/main/java/com/github/paulcwarren/springdocs/config/CorsOriginUpdater.java index 3210f85..a83f5c1 100644 --- a/spring-docs/src/main/java/com/github/paulcwarren/springdocs/config/CorsOriginUpdater.java +++ b/spring-docs/src/main/java/com/github/paulcwarren/springdocs/config/CorsOriginUpdater.java @@ -1,5 +1,7 @@ package com.github.paulcwarren.springdocs.config; +import static java.lang.String.format; + import java.lang.annotation.Annotation; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; @@ -8,6 +10,10 @@ import java.util.List; import java.util.Map; +import org.springframework.boot.system.SystemProperties; +import org.springframework.web.bind.annotation.CrossOrigin; +import org.springframework.web.bind.annotation.RequestMethod; + import com.github.paulcwarren.springdocs.repositories.JpaDocumentRepository; import com.github.paulcwarren.springdocs.repositories.MongoDocumentRepository; import com.github.paulcwarren.springdocs.stores.FsDocumentStore; @@ -15,18 +21,13 @@ import com.github.paulcwarren.springdocs.stores.JpaDocumentStore; import com.github.paulcwarren.springdocs.stores.S3DocumentStore; -import org.springframework.web.bind.annotation.CrossOrigin; -import org.springframework.web.bind.annotation.RequestMethod; - -import static java.lang.String.format; - public class CorsOriginUpdater { private static Method method = null; static { - String allowedHost = System.getenv("SPRINGDOCS_ALLOW_HOST"); + String allowedHost = SystemProperties.get("SPRINGDOCS_ALLOW_HOST"); if (allowedHost != null) { From ca370caf43272239b7dfbe29e84faacb436d3677 Mon Sep 17 00:00:00 2001 From: Lauren Ward Date: Thu, 15 Apr 2021 15:31:20 -0600 Subject: [PATCH 2/6] Configure CORS globally for demo application --- .../config/SpringSecurityConfig.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/spring-docs/src/main/java/com/github/paulcwarren/springdocs/config/SpringSecurityConfig.java b/spring-docs/src/main/java/com/github/paulcwarren/springdocs/config/SpringSecurityConfig.java index 16dcf69..609e962 100644 --- a/spring-docs/src/main/java/com/github/paulcwarren/springdocs/config/SpringSecurityConfig.java +++ b/spring-docs/src/main/java/com/github/paulcwarren/springdocs/config/SpringSecurityConfig.java @@ -1,5 +1,8 @@ package com.github.paulcwarren.springdocs.config; +import java.util.Arrays; +import java.util.Collections; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -10,6 +13,9 @@ import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; import org.springframework.security.config.http.SessionCreationPolicy; +import org.springframework.web.cors.CorsConfiguration; +import org.springframework.web.cors.UrlBasedCorsConfigurationSource; +import org.springframework.web.filter.CorsFilter; /** * Base security configuration provides Authentication object required by @@ -37,6 +43,24 @@ public AuthenticationEntryPoint getBasicAuthEntryPoint() { return new AuthenticationEntryPoint(); } + + /** + * Enable calls from client app + * @return + */ + @Bean + public CorsFilter corsFilter() { + final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); + final CorsConfiguration config = new CorsConfiguration(); + config.setAllowCredentials(true); + // Don't do this in production, use a proper list of allowed origins + config.setAllowedOrigins(Collections.singletonList("http://localhost:8080")); + config.setAllowedHeaders(Arrays.asList("Origin", "Content-Type", "Accept")); + config.setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "OPTIONS", "DELETE", "PATCH")); + source.registerCorsConfiguration("/**", config); + return new CorsFilter(source); + } + @Override protected void configure(HttpSecurity http) throws Exception { From 89a49bf35a33ba56bc586c63f001b735393fd432 Mon Sep 17 00:00:00 2001 From: Lauren Ward Date: Thu, 15 Apr 2021 15:56:25 -0600 Subject: [PATCH 3/6] Add additional property options for user visibility --- spring-docs/src/main/resources/application.properties | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/spring-docs/src/main/resources/application.properties b/spring-docs/src/main/resources/application.properties index 53c9715..a665dd6 100644 --- a/spring-docs/src/main/resources/application.properties +++ b/spring-docs/src/main/resources/application.properties @@ -1,12 +1,19 @@ server.port=9090 #debug=true +# Set active profile in property file for IDE runtime +# spring.profiles.active=postgres,fs + +# Disable full text search by default +spring.content.elasticsearch.autoindex=false + +# JP hibernate options create, create-drop, validate, and update spring.jpa.hibernate.ddl-auto=update #spring.content.s3.bucket=spring-docs #logging.level.org.springframework.web=DEBUG #logging.level.com.emc.ecs.connector.spring=DEBUG -logging.level.internal.org.springframework.content.rest.controllers=DEBUG +#logging.level.internal.org.springframework.content.rest.controllers=DEBUG # Control root location of file store spring.content.fs.filesystemRoot=/tmp/spring-content-store @@ -24,4 +31,4 @@ spring.jpa.database-platform=org.hibernate.dialect.H2Dialect # Log SQL #logging.level.org.hibernate.SQL=DEBUG -#logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE \ No newline at end of file +#logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE From e1cf3779e2bc3676f1ea72a9bc32e249128e03a8 Mon Sep 17 00:00:00 2001 From: Lauren Ward Date: Fri, 16 Apr 2021 13:40:56 -0600 Subject: [PATCH 4/6] Add comments about commenting elasticsearch imports to support Solr --- spring-docs/pom.xml | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/spring-docs/pom.xml b/spring-docs/pom.xml index 3cff91c..e8e1d13 100644 --- a/spring-docs/pom.xml +++ b/spring-docs/pom.xml @@ -22,10 +22,10 @@ UTF-8 UTF-8 1.8 - 1.2.0 + 1.2.2 - + org.springframework.boot spring-boot-starter-web @@ -107,15 +107,21 @@ spring-content-renditions-boot-starter ${spring.content.version} - + + com.github.paulcwarren spring-content-elasticsearch ${spring.content.version} - + + + com.github.paulcwarren + spring-content-solr + ${spring.content.version} + org.elasticsearch.client elasticsearch-rest-high-level-client - + com.github.paulcwarren @@ -175,6 +181,23 @@ 1.24.1 + + + org.apache.solr + solr-solrj + 7.7.3 + + + org.codehaus.woodstox + wstx-asl + + + log4j + log4j + + + + com.github.paulcwarren From 761f26e1fc9857de666045a00437bb452a8e9111 Mon Sep 17 00:00:00 2001 From: Lauren Ward Date: Fri, 16 Apr 2021 13:41:38 -0600 Subject: [PATCH 5/6] Add support for spring.content.fs.directoryFormat property --- .../springdocs/config/store/FsConfig.java | 34 +++++++++++++++---- .../src/main/resources/application.properties | 12 +++++-- 2 files changed, 37 insertions(+), 9 deletions(-) diff --git a/spring-docs/src/main/java/com/github/paulcwarren/springdocs/config/store/FsConfig.java b/spring-docs/src/main/java/com/github/paulcwarren/springdocs/config/store/FsConfig.java index 71d44bb..c0b073c 100644 --- a/spring-docs/src/main/java/com/github/paulcwarren/springdocs/config/store/FsConfig.java +++ b/spring-docs/src/main/java/com/github/paulcwarren/springdocs/config/store/FsConfig.java @@ -1,8 +1,8 @@ package com.github.paulcwarren.springdocs.config.store; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; + import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; import org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfiguration; import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration; import org.springframework.content.fs.config.EnableFilesystemStores; @@ -19,23 +19,45 @@ @Profile("fs") public class FsConfig { - private static final Log logger = LogFactory.getLog(FsConfig.class); - - @Bean - public FilesystemStoreConfigurer configurer() { + @Bean + @ConditionalOnExpression("'${spring.content.fs.directoryFormat}'=='flat'") + public FilesystemStoreConfigurer flatConfigurer() { return new FilesystemStoreConfigurer() { @Override public void configureFilesystemStoreConverters(ConverterRegistry registry) { registry.addConverter(new Converter() { + // Single Directory @Override public String convert(String source) { // Standard UID format return String.format("%s", source.toString()); } + + }); + } + }; + } + + @Bean + @ConditionalOnExpression("'${spring.content.fs.directoryFormat}'=='hierarchy'") + public FilesystemStoreConfigurer hierarchyConfigurer() { + return new FilesystemStoreConfigurer() { + + @Override + public void configureFilesystemStoreConverters(ConverterRegistry registry) { + registry.addConverter(new Converter() { + + // Directory hierarchy + @Override + public String convert(String source) { + // Standard UID format + return String.format("/%s", source.toString().replaceAll("-", "")).replaceAll("..", "$0/"); + } }); } }; } + } diff --git a/spring-docs/src/main/resources/application.properties b/spring-docs/src/main/resources/application.properties index a665dd6..45d17c4 100644 --- a/spring-docs/src/main/resources/application.properties +++ b/spring-docs/src/main/resources/application.properties @@ -1,6 +1,9 @@ server.port=9090 #debug=true +# Solar URL +solr.url=http://localhost:8983/solr/solr + # Set active profile in property file for IDE runtime # spring.profiles.active=postgres,fs @@ -8,7 +11,7 @@ server.port=9090 spring.content.elasticsearch.autoindex=false # JP hibernate options create, create-drop, validate, and update -spring.jpa.hibernate.ddl-auto=update +spring.jpa.hibernate.ddl-auto=create-drop #spring.content.s3.bucket=spring-docs #logging.level.org.springframework.web=DEBUG @@ -19,6 +22,9 @@ spring.jpa.hibernate.ddl-auto=update spring.content.fs.filesystemRoot=/tmp/spring-content-store spring.content.rest.fullyQualifiedLinks=false +# hierarchy or flat +spring.content.fs.directoryFormat=flat + # Control file upload size spring.servlet.multipart.max-file-size=100MB @@ -26,8 +32,8 @@ spring.servlet.multipart.max-file-size=100MB #spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults=false #spring.jpa.database-platform=org.hibernate.dialect.PostgreSQL9Dialect -spring.jpa.properties.hibernate.temp.use_jdbc_metadata_default=false -spring.jpa.database-platform=org.hibernate.dialect.H2Dialect +#spring.jpa.properties.hibernate.temp.use_jdbc_metadata_default=false +#spring.jpa.database-platform=org.hibernate.dialect.H2Dialect # Log SQL #logging.level.org.hibernate.SQL=DEBUG From e5bceb75fb871f69c288cb97996bba9c947260cd Mon Sep 17 00:00:00 2001 From: Lauren Ward Date: Fri, 16 Apr 2021 15:36:45 -0600 Subject: [PATCH 6/6] Remove unused packages --- .../springdocs/config/store/ElasticsearchConfig.java | 3 --- spring-docs/src/main/resources/application.properties | 4 ++-- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/spring-docs/src/main/java/com/github/paulcwarren/springdocs/config/store/ElasticsearchConfig.java b/spring-docs/src/main/java/com/github/paulcwarren/springdocs/config/store/ElasticsearchConfig.java index 536b859..8589ddf 100644 --- a/spring-docs/src/main/java/com/github/paulcwarren/springdocs/config/store/ElasticsearchConfig.java +++ b/spring-docs/src/main/java/com/github/paulcwarren/springdocs/config/store/ElasticsearchConfig.java @@ -3,9 +3,6 @@ import org.apache.http.HttpHost; import org.elasticsearch.client.RestClient; import org.elasticsearch.client.RestHighLevelClient; -import pl.allegro.tech.embeddedelasticsearch.EmbeddedElastic; - -import org.springframework.content.elasticsearch.EnableElasticsearchFulltextIndexing; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; diff --git a/spring-docs/src/main/resources/application.properties b/spring-docs/src/main/resources/application.properties index 45d17c4..4b32555 100644 --- a/spring-docs/src/main/resources/application.properties +++ b/spring-docs/src/main/resources/application.properties @@ -32,8 +32,8 @@ spring.servlet.multipart.max-file-size=100MB #spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults=false #spring.jpa.database-platform=org.hibernate.dialect.PostgreSQL9Dialect -#spring.jpa.properties.hibernate.temp.use_jdbc_metadata_default=false -#spring.jpa.database-platform=org.hibernate.dialect.H2Dialect +spring.jpa.properties.hibernate.temp.use_jdbc_metadata_default=false +spring.jpa.database-platform=org.hibernate.dialect.H2Dialect # Log SQL #logging.level.org.hibernate.SQL=DEBUG