Skip to content

Commit

Permalink
NIFI-12434 Upgraded Registry to Spring Framework 6.1.1
Browse files Browse the repository at this point in the history
- Upgraded Spring Framework from 6.0.13 to 6.1.1
- Upgraded Spring Boot from 3.1.5 to 3.2.0
- Upgraded Spring Security from 6.1.5 to 6.2.0
- Upgraded Jetty from 11.0.18 to 12.0.3
- Upgraded Servlet API from 5.0.0 to 6.0.0
- Adjusted Registry Database Tests to streamline DataSource configuration

Signed-off-by: Pierre Villard <[email protected]>

This closes apache#8087.
  • Loading branch information
exceptionfactory authored and pvillard31 committed Dec 1, 2023
1 parent f0fa38d commit 429b521
Show file tree
Hide file tree
Showing 21 changed files with 85 additions and 527 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand All @@ -33,6 +34,7 @@
* Overriding Spring Boot's normal automatic creation of a DataSource in order to use the properties
* from NiFiRegistryProperties rather than the standard application.properties/yaml.
*/
@ConditionalOnProperty("nifi.registry.db.url")
@Configuration
public class DataSourceFactory {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,13 @@
*/
package org.apache.nifi.registry.db;

import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
import org.springframework.test.context.transaction.TransactionalTestExecutionListener;
import org.springframework.transaction.annotation.Transactional;

@Transactional
@ExtendWith(SpringExtension.class)
@SpringBootTest(classes = DatabaseTestApplication.class, webEnvironment = SpringBootTest.WebEnvironment.NONE)
@TestExecutionListeners({DependencyInjectionTestExecutionListener.class, TransactionalTestExecutionListener.class})
public abstract class DatabaseBaseTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.FilterType;

/**
* Sets up the application context for database repository tests.
Expand All @@ -33,12 +31,6 @@
* The DataSourceFactory is excluded so that Spring Boot will load an in-memory H2 database.
*/
@SpringBootApplication
@ComponentScan(
excludeFilters = {
@ComponentScan.Filter(
type = FilterType.ASSIGNABLE_TYPE,
value = DataSourceFactory.class)
})
public class DatabaseTestApplication {

public static void main(String[] args) {
Expand Down
28 changes: 17 additions & 11 deletions nifi-registry/nifi-registry-core/nifi-registry-jetty/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-jetty-configuration</artifactId>
<version>2.0.0-SNAPSHOT</version>
<exclusions>
<exclusion>
<groupId>org.eclipse.jetty.http2</groupId>
<artifactId>http2-server</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
Expand All @@ -45,7 +51,7 @@
</dependency>
<dependency>
<groupId>org.eclipse.jetty.http2</groupId>
<artifactId>http2-server</artifactId>
<artifactId>jetty-http2-server</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
Expand All @@ -56,28 +62,28 @@
<artifactId>jetty-server</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<groupId>org.eclipse.jetty.ee10</groupId>
<artifactId>jetty-ee10-servlet</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-webapp</artifactId>
<groupId>org.eclipse.jetty.ee10</groupId>
<artifactId>jetty-ee10-webapp</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlets</artifactId>
<groupId>org.eclipse.jetty.ee10</groupId>
<artifactId>jetty-ee10-servlets</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-annotations</artifactId>
<groupId>org.eclipse.jetty.ee10</groupId>
<artifactId>jetty-ee10-annotations</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>apache-jsp</artifactId>
<groupId>org.eclipse.jetty.ee10</groupId>
<artifactId>jetty-ee10-apache-jsp</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.server.SslConnectionFactory;
import org.eclipse.jetty.util.thread.QueuedThreadPool;
import org.eclipse.jetty.webapp.WebAppContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -39,7 +38,6 @@
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -114,19 +112,6 @@ private void configureConnectors() {
public void start() {
try {
server.start();

final Optional<Throwable> unavailableExceptionFound = Arrays.stream(server.getChildHandlers())
.filter(handler -> handler instanceof WebAppContext)
.map(handler -> (WebAppContext) handler)
.map(WebAppContext::getUnavailableException)
.filter(Objects::nonNull)
.findFirst();

if (unavailableExceptionFound.isPresent()) {
final Throwable unavailableException = unavailableExceptionFound.get();
shutdown(unavailableException);
}

final List<URI> applicationUrls = getApplicationUrls();
if (applicationUrls.isEmpty()) {
logger.warn("Started Server without connectors");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
package org.apache.nifi.registry.jetty.handler;

import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.handler.ScopedHandler;
import org.eclipse.jetty.server.Handler;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.eclipse.jetty.server.Response;
import org.eclipse.jetty.util.Callback;

/**
* HTTP Response Header Writer Handler applies standard headers to HTTP responses
*/
public class HeaderWriterHandler extends ScopedHandler {
public class HeaderWriterHandler extends Handler.Wrapper {
protected static final String CONTENT_SECURITY_POLICY_HEADER = "Content-Security-Policy";
protected static final String CONTENT_SECURITY_POLICY = "frame-ancestors 'self'";

Expand All @@ -41,19 +41,22 @@ public class HeaderWriterHandler extends ScopedHandler {
/**
* Handle requests and set HTTP response headers
*
* @param target Target URI
* @param request Jetty Request
* @param httpServletRequest HTTP Servlet Request
* @param httpServletResponse HTTP Servlet Response
* @param response Jetty Response
* @param callback Jetty Callback
* @return Handled status
* @throws Exception Thrown on failures from subsequent handlers
*/
@Override
public void doHandle(final String target, final Request request, final HttpServletRequest httpServletRequest, final HttpServletResponse httpServletResponse) {
httpServletResponse.setHeader(CONTENT_SECURITY_POLICY_HEADER, CONTENT_SECURITY_POLICY);
httpServletResponse.setHeader(FRAME_OPTIONS_HEADER, FRAME_OPTIONS);
httpServletResponse.setHeader(XSS_PROTECTION_HEADER, XSS_PROTECTION);
public boolean handle(final Request request, final Response response, final Callback callback) throws Exception {
response.getHeaders().add(CONTENT_SECURITY_POLICY_HEADER, CONTENT_SECURITY_POLICY);
response.getHeaders().add(FRAME_OPTIONS_HEADER, FRAME_OPTIONS);
response.getHeaders().add(XSS_PROTECTION_HEADER, XSS_PROTECTION);

if (httpServletRequest.isSecure()) {
httpServletResponse.setHeader(STRICT_TRANSPORT_SECURITY_HEADER, STRICT_TRANSPORT_SECURITY);
if (request.isSecure()) {
response.getHeaders().add(STRICT_TRANSPORT_SECURITY_HEADER, STRICT_TRANSPORT_SECURITY);
}

return super.handle(request, response, callback);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
import org.apache.nifi.registry.properties.NiFiRegistryProperties;
import org.apache.nifi.registry.security.crypto.CryptoKeyProvider;
import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.handler.HandlerCollection;
import org.eclipse.jetty.servlet.DefaultServlet;
import org.eclipse.jetty.servlet.ErrorPageErrorHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.eclipse.jetty.webapp.WebAppClassLoader;
import org.eclipse.jetty.webapp.WebAppContext;
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
import org.eclipse.jetty.ee10.servlet.DefaultServlet;
import org.eclipse.jetty.ee10.servlet.ErrorPageErrorHandler;
import org.eclipse.jetty.ee10.servlet.ServletHolder;
import org.eclipse.jetty.ee10.webapp.WebAppClassLoader;
import org.eclipse.jetty.ee10.webapp.WebAppContext;

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -101,7 +101,7 @@ public Handler getHandler(final NiFiRegistryProperties properties) {
final File libDirectory = properties.getWarLibDirectory();
final File workDirectory = properties.getWebWorkingDirectory();

final HandlerCollection handlers = new HandlerCollection();
final Handler.Collection handlers = new ContextHandlerCollection();
// Add Header Writer Handler before others
handlers.addHandler(new HeaderWriterHandler());

Expand Down Expand Up @@ -158,12 +158,8 @@ private WebAppContext getWebAppContext(
final File tempDirectory = getTempDirectory(workDirectory, applicationFile.getName());
webAppContext.setTempDirectory(tempDirectory);

try {
final WebAppClassLoader webAppClassLoader = new WebAppClassLoader(parentClassLoader, webAppContext);
webAppContext.setClassLoader(webAppClassLoader);
} catch (final IOException e) {
throw new IllegalStateException(String.format("Application Context Path [%s] ClassLoader creation failed", contextPath), e);
}
final WebAppClassLoader webAppClassLoader = new WebAppClassLoader(parentClassLoader, webAppContext);
webAppContext.setClassLoader(webAppClassLoader);

return webAppContext;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,34 +42,6 @@
Default web.xml file.
This file is applied to a Web application before it's own WEB_INF/web.xml file
</description>

<!-- ==================================================================== -->
<!-- Removes static cache of Methods from java.beans.Introspector to -->
<!-- ensure webapp classloader can be released on undeploy -->
<!-- ==================================================================== -->
<listener>
<listener-class>org.eclipse.jetty.servlet.listener.IntrospectorCleaner</listener-class>
</listener>


<!-- ==================================================================== -->
<!-- Context params to control Session Cookies -->
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<!--
UNCOMMENT TO ACTIVATE
<context-param>
<param-name>org.eclipse.jetty.servlet.SessionDomain</param-name>
<param-value>127.0.0.1</param-value>
</context-param>
<context-param>
<param-name>org.eclipse.jetty.servlet.SessionPath</param-name>
<param-value>/</param-value>
</context-param>
<context-param>
<param-name>org.eclipse.jetty.servlet.MaxAge</param-name>
<param-value>-1</param-value>
</context-param>
-->

<!-- ==================================================================== -->
<!-- The default servlet. -->
Expand Down Expand Up @@ -139,7 +111,7 @@
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<servlet>
<servlet-name>default</servlet-name>
<servlet-class>org.eclipse.jetty.servlet.DefaultServlet</servlet-class>
<servlet-class>org.eclipse.jetty.ee10.servlet.DefaultServlet</servlet-class>
<init-param>
<param-name>aliases</param-name>
<param-value>false</param-value>
Expand Down Expand Up @@ -184,18 +156,6 @@
<param-name>useFileMappedBuffer</param-name>
<param-value>true</param-value>
</init-param>
<!--
<init-param>
<param-name>resourceCache</param-name>
<param-value>resourceCache</param-value>
</init-param>
-->
<!--
<init-param>
<param-name>cacheControl</param-name>
<param-value>max-age=3600,public</param-value>
</init-param>
-->
<load-on-startup>0</load-on-startup>
</servlet>

Expand Down

This file was deleted.

Loading

0 comments on commit 429b521

Please sign in to comment.