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/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 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) { 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 { 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/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 53c9715..4b32555 100644 --- a/spring-docs/src/main/resources/application.properties +++ b/spring-docs/src/main/resources/application.properties @@ -1,17 +1,30 @@ server.port=9090 #debug=true -spring.jpa.hibernate.ddl-auto=update +# Solar URL +solr.url=http://localhost:8983/solr/solr + +# 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=create-drop #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 spring.content.rest.fullyQualifiedLinks=false +# hierarchy or flat +spring.content.fs.directoryFormat=flat + # Control file upload size spring.servlet.multipart.max-file-size=100MB @@ -24,4 +37,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