Skip to content
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

Using an embedded tomcat to start the application #8797

Merged
merged 29 commits into from Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
d6446b1
[DSC-963] Create new project to run dspace with embedded tomcat
LucaGiamminonni Mar 9, 2023
0400b38
[DSC-963] Fixed test configuration
LucaGiamminonni Mar 10, 2023
dcde7db
[DSC-963] Fixed dspace pom
LucaGiamminonni Mar 10, 2023
5d592df
[DSC-963] Improved tests configuration
LucaGiamminonni Mar 10, 2023
2819b6f
[DSC-963] Fixed dspace-server-webapp pom
LucaGiamminonni Mar 10, 2023
1bbd478
[DSC-963] Fixed Sword tests
LucaGiamminonni Mar 10, 2023
944f4a1
[DSC-963] Fixed dspace pom
LucaGiamminonni Mar 10, 2023
882485b
[DSC-963] Set default servlet context path on application-test.proper…
LucaGiamminonni Mar 10, 2023
c82588a
[DSC-963] Improved TestApplication configuration
LucaGiamminonni Mar 10, 2023
aff1de4
[DSC-963] Added @Order on AdminRestPermissionEvaluatorPlugin
LucaGiamminonni Mar 13, 2023
b3a3acf
[DSC-963] Minor improvements
LucaGiamminonni Mar 13, 2023
abb17db
[DSC-963] Fixed ItemRestRepositoryIT and GenericAuthorizationFeatureI…
LucaGiamminonni Mar 13, 2023
08c5478
[DSC-963] Fixed SubmissionCCLicenseUrlRepositoryIT tests
LucaGiamminonni Mar 14, 2023
12cb9a8
[DSC-963] Refactoring to maintain server module
LucaGiamminonni Mar 14, 2023
4b72466
[DSC-963] Configured spring boot maven plugin
LucaGiamminonni Mar 14, 2023
313a1d8
[DSC-963] Suppress checkstyle warning
LucaGiamminonni Mar 15, 2023
c6e00a1
[DSC-963] Fixed webjars classpath
LucaGiamminonni Mar 23, 2023
3767ae8
[DSC-963] Fixed porting on main
LucaGiamminonni Apr 20, 2023
fe621b3
[DSC-963] Fixed GenericAuthorizationFeatureIT tests
LucaGiamminonni Apr 20, 2023
3fd93df
[DSC-963] Added missing applicationContext set on DefaultMethodSecuri…
LucaGiamminonni Apr 20, 2023
ced1c79
[DSC-963] Removed duplicated @EnableGlobalMethodSecurity
LucaGiamminonni Apr 20, 2023
b35b837
[DSC-963] Fixed checkstyle
LucaGiamminonni Apr 20, 2023
c1d6090
[DSC-963] Fixes dspace-server-webapp target folder
vins01-4science Dec 27, 2023
b2eb057
Merge remote-tracking branch 'origin/main' into DSC-963_main
vins01-4science Dec 28, 2023
0ee727e
[DSC-963] Update to 8.0-SNAPSHOT
vins01-4science Dec 28, 2023
6ea5293
[DSC-963] Fixes testResources generation
vins01-4science Dec 28, 2023
21b8c1b
[DSC-963] Fixes server unpacking
vins01-4science Dec 28, 2023
bb0693f
[DSC-963] Fixes resource copy and filtering
vins01-4science Dec 29, 2023
c0d68ee
[DSC-963] Addresses changes of the PR#8797
vins01-4science Jan 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
98 changes: 74 additions & 24 deletions dspace-server-webapp/pom.xml
Expand Up @@ -2,7 +2,6 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.dspace</groupId>
<artifactId>dspace-server-webapp</artifactId>
<packaging>war</packaging>
<name>DSpace Server Webapp</name>
<description>
DSpace Server Webapp (Spring Boot)
Expand All @@ -25,23 +24,82 @@

<!-- Default resource delimiter for Spring Boot, so it doesn't clash with Spring ${} placeholders-->
<resource.delimiter>@</resource.delimiter>
<!-- Define our starting class for our Spring Boot Application -->
<start-class>org.dspace.app.rest.Application</start-class>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<attachClasses>true</attachClasses>
<!-- Filter the web.xml (needed for IDE compatibility/debugging) -->
<filteringDeploymentDescriptors>true</filteringDeploymentDescriptors>
</configuration>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.1.0</version>
<executions>
<execution>
<phase>prepare-package</phase>
<phase>initialize</phase>
<goals>
<goal>read-project-properties</goal>
</goals>
<configuration>
<files>
<file>${root.basedir}/dspace/config/dspace.cfg</file>
<file>${root.basedir}/dspace/config/local.cfg</file>
</files>
<quiet>true</quiet>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>testEnvironment</id>
<phase>process-resources</phase>
<goals>
<goal>testResources</goal>
</goals>
<configuration>
<resources>
<resource>
<directory>${basedir}/src/test/resources</directory>
</resource>
</resources>
</configuration>
</execution>
<execution>
<id>webappFiltering</id>
<phase>process-resources</phase>
<goals>
<goal>resources</goal>
</goals>
<configuration>
<resources>
<resource>
<directory>${basedir}/src/main/resources</directory>
<includes>
<include>**/*application*.properties</include>
<include>**/*dspace*.properties</include>
</includes>
<filtering>true</filtering>
</resource>
<resource>
<directory>${basedir}/src/main/resources</directory>
<excludes>
<exclude>**/*application*.properties</exclude>
<exclude>**/*dspace*.properties</exclude>
</excludes>
<includes>
<include>**/*.properties</include>
</includes>
</resource>
<resource>
<directory>${basedir}/src/main/resources</directory>
<includes>
<include>**/static/**</include>
<include>**/spring/**</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
Expand All @@ -66,11 +124,11 @@
<exclude>**/src/test/resources/**</exclude>
<exclude>**/src/test/data/**</exclude>
<!--Skip license check of third party files included/customized from HAL Browser -->
<exclude>src/main/webapp/index.html</exclude>
<exclude>src/main/webapp/login.html</exclude>
<exclude>src/main/webapp/styles.css</exclude>
<exclude>src/main/webapp/js/hal/**</exclude>
<exclude>src/main/webapp/js/vendor/**</exclude>
<exclude>src/main/resources/static/index.html</exclude>
<exclude>src/main/resources/static/login.html</exclude>
<exclude>src/main/resources/static/styles.css</exclude>
<exclude>src/main/resources/static/js/hal/**</exclude>
<exclude>src/main/resources/static/js/vendor/**</exclude>
</excludes>
</configuration>
</plugin>
Expand Down Expand Up @@ -253,12 +311,6 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
<version>${spring-boot.version}</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down Expand Up @@ -484,12 +536,10 @@
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path-assert</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
Expand Down
Expand Up @@ -17,8 +17,6 @@
import org.dspace.app.rest.parameter.resolver.SearchFilterResolver;
import org.dspace.app.rest.utils.ApplicationConfig;
import org.dspace.app.rest.utils.DSpaceAPIRequestLoggingFilter;
import org.dspace.app.rest.utils.DSpaceConfigurationInitializer;
import org.dspace.app.rest.utils.DSpaceKernelInitializer;
import org.dspace.app.sitemap.GenerateSitemaps;
import org.dspace.app.solrdatabaseresync.SolrDatabaseResyncCli;
import org.dspace.app.util.DSpaceContextListener;
Expand All @@ -27,11 +25,9 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.hateoas.server.LinkRelationProvider;
import org.springframework.lang.NonNull;
Expand All @@ -46,24 +42,18 @@
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
* Define the Spring Boot Application settings itself. This class takes the place
* of a web.xml file, and configures all Filters/Listeners as methods (see below).
* <p>
* NOTE: Requires a Servlet 3.0 container, e.g. Tomcat 7.0 or above.
* <p>
* NOTE: This extends SpringBootServletInitializer in order to allow us to build
* a deployable WAR file with Spring Boot. See:
* http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#howto-create-a-deployable-war-file
* Main configuration for the dspace web module.
*
* @author Andrea Bollini (andrea.bollini at 4science.it)
* @author Tim Donohue
* @author Luca Giamminonni (luca.giamminonni at 4science.it)
*/
@SpringBootApplication
@EnableScheduling
@EnableCaching
public class Application extends SpringBootServletInitializer {
@Configuration
public class WebApplication {

private static final Logger log = LoggerFactory.getLogger(Application.class);
private static final Logger log = LoggerFactory.getLogger(WebApplication.class);

@Autowired
private ApplicationConfig configuration;
Expand All @@ -86,26 +76,6 @@ public void sendGoogleAnalyticsEvents() {
googleAsyncEventListener.sendCollectedEvents();
}

/**
* Override the default SpringBootServletInitializer.configure() method,
* passing it this Application class.
* <p>
* This is necessary to allow us to build a deployable WAR, rather than
* always relying on embedded Tomcat.
* <p>
* See: http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#howto-create-a-deployable-war-file
*
* @param application
* @return
*/
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
// Pass this Application class, and our initializers for DSpace Kernel and Configuration
// NOTE: Kernel must be initialized before Configuration
return application.sources(Application.class)
.initializers(new DSpaceKernelInitializer(), new DSpaceConfigurationInitializer());
}

/**
* Register the "DSpaceContextListener" so that it is loaded
* for this Application.
Expand Down Expand Up @@ -253,7 +223,7 @@ public void addResourceHandlers(ResourceHandlerRegistry registry) {
// Make all other Webjars available off the /webjars path
registry
.addResourceHandler("/webjars/**")
.addResourceLocations("/webjars/");
.addResourceLocations("/webjars/", "classpath:/META-INF/resources/webjars/");
}

@Override
Expand Down
Expand Up @@ -21,6 +21,8 @@
import org.dspace.app.rest.model.hateoas.DSpaceResource;
import org.dspace.app.rest.utils.Utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.data.domain.Pageable;
import org.springframework.hateoas.IanaLinkRelations;
import org.springframework.hateoas.Link;
Expand All @@ -33,6 +35,7 @@
* @author Tom Desair (tom dot desair at atmire dot com)
*/
@Component
@Order(Ordered.HIGHEST_PRECEDENCE)
public class DSpaceResourceHalLinkFactory extends HalLinkFactory<DSpaceResource, RestResourceController> {

@Autowired
Expand Down
Expand Up @@ -30,16 +30,19 @@
@Component
public class ExternalSourceItemUriListHandler extends ExternalSourceEntryItemUriListHandler<Item> {

private Pattern pattern = Pattern.compile("\\/api\\/core\\/items\\/(.*)");

@Autowired
private ItemService itemService;

@Override
@SuppressWarnings("rawtypes")
public boolean supports(List<String> uriList, String method,Class clazz) {
if (clazz != Item.class) {
if (clazz != Item.class || uriList.size() != 1) {
return false;
}
return true;

return pattern.matcher(uriList.get(0)).find();
}

@Override
Expand All @@ -61,7 +64,6 @@ public boolean validate(Context context, HttpServletRequest request, List<String
private Item getObjectFromUriList(Context context, List<String> uriList) {
Item item = null;
String url = uriList.get(0);
Pattern pattern = Pattern.compile("\\/api\\/core\\/items\\/(.*)");
Matcher matcher = pattern.matcher(url);
if (!matcher.find()) {
throw new DSpaceBadRequestException("The uri: " + url + " doesn't resolve to an item");
Expand Down
Expand Up @@ -20,6 +20,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.security.core.Authentication;
import org.springframework.stereotype.Component;

Expand All @@ -29,6 +31,7 @@
* the authenticated EPerson is allowed to perform the requested action.
*/
@Component
@Order(value = Ordered.HIGHEST_PRECEDENCE)
public class AdminRestPermissionEvaluatorPlugin extends RestObjectPermissionEvaluatorPlugin {

private static final Logger log = LoggerFactory.getLogger(RestObjectPermissionEvaluatorPlugin.class);
Expand Down
Expand Up @@ -8,6 +8,7 @@
package org.dspace.app.rest.security;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.access.PermissionEvaluator;
import org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler;
Expand All @@ -22,10 +23,13 @@ public class MethodSecurityConfig extends GlobalMethodSecurityConfiguration {
@Autowired
private PermissionEvaluator dSpacePermissionEvaluator;

@Autowired
private ApplicationContext applicationContext;

@Override
protected MethodSecurityExpressionHandler createExpressionHandler() {
DefaultMethodSecurityExpressionHandler expressionHandler =
new DefaultMethodSecurityExpressionHandler();
DefaultMethodSecurityExpressionHandler expressionHandler = new DefaultMethodSecurityExpressionHandler();
expressionHandler.setApplicationContext(applicationContext);
expressionHandler.setPermissionEvaluator(dSpacePermissionEvaluator);
return expressionHandler;
}
Expand Down
Expand Up @@ -20,7 +20,6 @@
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.builders.WebSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
Expand All @@ -41,7 +40,6 @@
@EnableWebSecurity
@Configuration
@EnableConfigurationProperties(SecurityProperties.class)
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter {

public static final String ADMIN_GRANT = "ADMIN";
Expand Down
Expand Up @@ -38,6 +38,11 @@
# interact with or read its configuration from dspace.cfg.
dspace.dir=${dspace.dir}

########################
# Servlet context path configuration for spring boot application running with embedded tomcat
#
server.servlet.context-path=/server

########################
# Jackson serialization settings
#
Expand Down
@@ -0,0 +1,22 @@
/**
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
*
* http://www.dspace.org/license/
*/
package org.dspace.app;

import org.dspace.app.rest.WebApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
* Spring boot application for integration tests.
*
* @author Luca Giamminonni (luca.giamminonni at 4science.it)
*
*/
@SpringBootApplication(scanBasePackageClasses = WebApplication.class)
public class TestApplication {

}