From 07f9022d21efd7a4faf1e51bfdd5d139ab0118ee Mon Sep 17 00:00:00 2001 From: Ricky Herget Date: Mon, 31 Jul 2023 10:30:50 -0400 Subject: [PATCH 1/4] springboot websocket fat test pass --- dev/io.openliberty.springboot.fat30_fat/build.gradle | 1 + .../fat/src/com/ibm/ws/springboot/support/fat/FATSuite.java | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/dev/io.openliberty.springboot.fat30_fat/build.gradle b/dev/io.openliberty.springboot.fat30_fat/build.gradle index b4e2773bcfff..491a6b6e476c 100644 --- a/dev/io.openliberty.springboot.fat30_fat/build.gradle +++ b/dev/io.openliberty.springboot.fat30_fat/build.gradle @@ -28,6 +28,7 @@ // 'org.eclipse.jetty:jetty-util:9.4.7.RC0', // 'org.eclipse.jetty:jetty-websocket:8.2.0.v20160908', // Updated dependencies copied from io.openliberty.wsoc.2.1.internal_fat/build.gradle: + 'org.glassfish.tyrus.bundles:tyrus-standalone-client:2.1.3', 'jakarta.websocket:jakarta.websocket-api:2.1.0', 'org.eclipse.jetty:jetty-io:11.0.9', 'org.eclipse.jetty:jetty-util:11.0.9', diff --git a/dev/io.openliberty.springboot.fat30_fat/fat/src/com/ibm/ws/springboot/support/fat/FATSuite.java b/dev/io.openliberty.springboot.fat30_fat/fat/src/com/ibm/ws/springboot/support/fat/FATSuite.java index dcb5d1a45992..2892cbeb0f3f 100644 --- a/dev/io.openliberty.springboot.fat30_fat/fat/src/com/ibm/ws/springboot/support/fat/FATSuite.java +++ b/dev/io.openliberty.springboot.fat30_fat/fat/src/com/ibm/ws/springboot/support/fat/FATSuite.java @@ -53,7 +53,7 @@ SpringBootUtilityThinTest.class, WebAnnotationTests30.class, ExtractedAppTests30.class, - // WebSocketTests30.class, + WebSocketTests30.class, // Disabled due to application failures. MimeMapping30.class, ErrorPage30Test.class, From 6208004702497956ecb3f57475b9f6e23419092f Mon Sep 17 00:00:00 2001 From: Ricky Herget Date: Mon, 31 Jul 2023 11:33:32 -0400 Subject: [PATCH 2/4] Add doc link for added dependency --- dev/io.openliberty.springboot.fat30_fat/build.gradle | 5 +++++ .../fat/src/com/ibm/ws/springboot/support/fat/FATSuite.java | 1 - 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/dev/io.openliberty.springboot.fat30_fat/build.gradle b/dev/io.openliberty.springboot.fat30_fat/build.gradle index 491a6b6e476c..16663db84c5b 100644 --- a/dev/io.openliberty.springboot.fat30_fat/build.gradle +++ b/dev/io.openliberty.springboot.fat30_fat/build.gradle @@ -11,6 +11,10 @@ * IBM Corporation - initial API and implementation *******************************************************************************/ +repositories { + mavenCentral() +} + dependencies { requiredLibs 'net.sourceforge.htmlunit:htmlunit-core-js:2.44.0', 'net.sourceforge.htmlunit:htmlunit-cssparser:1.6.0', @@ -28,6 +32,7 @@ // 'org.eclipse.jetty:jetty-util:9.4.7.RC0', // 'org.eclipse.jetty:jetty-websocket:8.2.0.v20160908', // Updated dependencies copied from io.openliberty.wsoc.2.1.internal_fat/build.gradle: + // https://stackoverflow.com/a/52299076 jakarta.websocket.WebSocketContainer version 2.1.X 'org.glassfish.tyrus.bundles:tyrus-standalone-client:2.1.3', 'jakarta.websocket:jakarta.websocket-api:2.1.0', 'org.eclipse.jetty:jetty-io:11.0.9', diff --git a/dev/io.openliberty.springboot.fat30_fat/fat/src/com/ibm/ws/springboot/support/fat/FATSuite.java b/dev/io.openliberty.springboot.fat30_fat/fat/src/com/ibm/ws/springboot/support/fat/FATSuite.java index 2892cbeb0f3f..b3d501fbc91f 100644 --- a/dev/io.openliberty.springboot.fat30_fat/fat/src/com/ibm/ws/springboot/support/fat/FATSuite.java +++ b/dev/io.openliberty.springboot.fat30_fat/fat/src/com/ibm/ws/springboot/support/fat/FATSuite.java @@ -54,7 +54,6 @@ WebAnnotationTests30.class, ExtractedAppTests30.class, WebSocketTests30.class, - // Disabled due to application failures. MimeMapping30.class, ErrorPage30Test.class, // EnableSpringBootTraceTests30.class, From cd2b3ae92fac8df72c5bbe41c18576cbf2793db6 Mon Sep 17 00:00:00 2001 From: Ricky Herget Date: Tue, 1 Aug 2023 15:37:49 -0400 Subject: [PATCH 3/4] fix springboot security tests --- .../.classpath | 18 +++ .../.gitignore | 3 + .../.project | 40 +++++++ .../.settings/bndtools.core.prefs | 2 + .../org.eclipse.buildship.core.prefs | 2 + .../.settings/org.eclipse.jdt.core.prefs | 12 ++ .../bnd.bnd | 53 +++++++++ .../build.gradle | 56 ++++++++++ .../springboot.gradle | 1 + .../fat30/test/app/CustomizationBean.java | 31 ++++++ .../springboot/fat30/test/app/MvcConfig.java | 28 +++++ .../fat30/test/app/SecurityConfiguration.java | 63 +++++++++++ .../fat30/test/app/TestApplication.java | 105 ++++++++++++++++++ .../test/app/TestErrorPageRegistrar.java | 35 ++++++ .../fat30/test/app/TestWebFilter.java | 45 ++++++++ .../fat30/test/app/TestWebListener.java | 32 ++++++ .../fat30/test/app/TestWebServlet.java | 31 ++++++ .../src/main/resources/application.properties | 13 +++ .../resources/public/defaultErrorPage.html | 9 ++ .../resources/public/errorPageException.html | 9 ++ .../src/main/resources/public/file.weby | 4 + .../src/main/resources/public/noSuchPage.html | 9 ++ .../main/resources/public/useJarUrlsTest.html | 19 ++++ .../src/main/resources/server-keystore.jks | Bin 0 -> 2248 bytes .../src/main/resources/server-truststore.jks | Bin 0 -> 950 bytes .../src/main/resources/templates/hello.html | 13 +++ .../src/main/resources/templates/login.html | 21 ++++ .../bnd.bnd | 3 +- .../build.gradle | 3 +- .../support/fat/AbstractSpringTests.java | 2 + .../ws/springboot/support/fat/FATSuite.java | 11 +- .../support/fat/SpringSecurityTests30.java | 5 +- .../servers/SpringBootTests/jvm.options | 1 + 33 files changed, 667 insertions(+), 12 deletions(-) create mode 100644 dev/io.openliberty.springboot.fat30.security.app/.classpath create mode 100644 dev/io.openliberty.springboot.fat30.security.app/.gitignore create mode 100644 dev/io.openliberty.springboot.fat30.security.app/.project create mode 100644 dev/io.openliberty.springboot.fat30.security.app/.settings/bndtools.core.prefs create mode 100644 dev/io.openliberty.springboot.fat30.security.app/.settings/org.eclipse.buildship.core.prefs create mode 100644 dev/io.openliberty.springboot.fat30.security.app/.settings/org.eclipse.jdt.core.prefs create mode 100644 dev/io.openliberty.springboot.fat30.security.app/bnd.bnd create mode 100644 dev/io.openliberty.springboot.fat30.security.app/build.gradle create mode 100644 dev/io.openliberty.springboot.fat30.security.app/springboot.gradle create mode 100644 dev/io.openliberty.springboot.fat30.security.app/src/main/java/com/ibm/ws/springboot/fat30/test/app/CustomizationBean.java create mode 100644 dev/io.openliberty.springboot.fat30.security.app/src/main/java/com/ibm/ws/springboot/fat30/test/app/MvcConfig.java create mode 100644 dev/io.openliberty.springboot.fat30.security.app/src/main/java/com/ibm/ws/springboot/fat30/test/app/SecurityConfiguration.java create mode 100644 dev/io.openliberty.springboot.fat30.security.app/src/main/java/com/ibm/ws/springboot/fat30/test/app/TestApplication.java create mode 100644 dev/io.openliberty.springboot.fat30.security.app/src/main/java/com/ibm/ws/springboot/fat30/test/app/TestErrorPageRegistrar.java create mode 100644 dev/io.openliberty.springboot.fat30.security.app/src/main/java/com/ibm/ws/springboot/fat30/test/app/TestWebFilter.java create mode 100644 dev/io.openliberty.springboot.fat30.security.app/src/main/java/com/ibm/ws/springboot/fat30/test/app/TestWebListener.java create mode 100644 dev/io.openliberty.springboot.fat30.security.app/src/main/java/com/ibm/ws/springboot/fat30/test/app/TestWebServlet.java create mode 100644 dev/io.openliberty.springboot.fat30.security.app/src/main/resources/application.properties create mode 100644 dev/io.openliberty.springboot.fat30.security.app/src/main/resources/public/defaultErrorPage.html create mode 100644 dev/io.openliberty.springboot.fat30.security.app/src/main/resources/public/errorPageException.html create mode 100644 dev/io.openliberty.springboot.fat30.security.app/src/main/resources/public/file.weby create mode 100644 dev/io.openliberty.springboot.fat30.security.app/src/main/resources/public/noSuchPage.html create mode 100644 dev/io.openliberty.springboot.fat30.security.app/src/main/resources/public/useJarUrlsTest.html create mode 100644 dev/io.openliberty.springboot.fat30.security.app/src/main/resources/server-keystore.jks create mode 100644 dev/io.openliberty.springboot.fat30.security.app/src/main/resources/server-truststore.jks create mode 100644 dev/io.openliberty.springboot.fat30.security.app/src/main/resources/templates/hello.html create mode 100644 dev/io.openliberty.springboot.fat30.security.app/src/main/resources/templates/login.html create mode 100644 dev/io.openliberty.springboot.fat30_fat/publish/servers/SpringBootTests/jvm.options diff --git a/dev/io.openliberty.springboot.fat30.security.app/.classpath b/dev/io.openliberty.springboot.fat30.security.app/.classpath new file mode 100644 index 000000000000..bb5e6bdefaca --- /dev/null +++ b/dev/io.openliberty.springboot.fat30.security.app/.classpath @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + diff --git a/dev/io.openliberty.springboot.fat30.security.app/.gitignore b/dev/io.openliberty.springboot.fat30.security.app/.gitignore new file mode 100644 index 000000000000..90dde36e4aca --- /dev/null +++ b/dev/io.openliberty.springboot.fat30.security.app/.gitignore @@ -0,0 +1,3 @@ +/bin/ +/bin_test/ +/generated/ diff --git a/dev/io.openliberty.springboot.fat30.security.app/.project b/dev/io.openliberty.springboot.fat30.security.app/.project new file mode 100644 index 000000000000..8e864cf163c0 --- /dev/null +++ b/dev/io.openliberty.springboot.fat30.security.app/.project @@ -0,0 +1,40 @@ + + + io.openliberty.springboot.fat30.security.app + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.buildship.core.gradleprojectbuilder + + + + + bndtools.core.bndbuilder + + + + + + org.eclipse.jdt.core.javanature + bndtools.core.bndnature + org.eclipse.buildship.core.gradleprojectnature + + + + 1690812734863 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/dev/io.openliberty.springboot.fat30.security.app/.settings/bndtools.core.prefs b/dev/io.openliberty.springboot.fat30.security.app/.settings/bndtools.core.prefs new file mode 100644 index 000000000000..789fa99991ac --- /dev/null +++ b/dev/io.openliberty.springboot.fat30.security.app/.settings/bndtools.core.prefs @@ -0,0 +1,2 @@ +compileErrorAction=build +eclipse.preferences.version=1 diff --git a/dev/io.openliberty.springboot.fat30.security.app/.settings/org.eclipse.buildship.core.prefs b/dev/io.openliberty.springboot.fat30.security.app/.settings/org.eclipse.buildship.core.prefs new file mode 100644 index 000000000000..b1886adb46c0 --- /dev/null +++ b/dev/io.openliberty.springboot.fat30.security.app/.settings/org.eclipse.buildship.core.prefs @@ -0,0 +1,2 @@ +connection.project.dir=.. +eclipse.preferences.version=1 diff --git a/dev/io.openliberty.springboot.fat30.security.app/.settings/org.eclipse.jdt.core.prefs b/dev/io.openliberty.springboot.fat30.security.app/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 000000000000..6558ab78fc43 --- /dev/null +++ b/dev/io.openliberty.springboot.fat30.security.app/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,12 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate +org.eclipse.jdt.core.compiler.codegen.targetPlatform=17 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=17 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=17 diff --git a/dev/io.openliberty.springboot.fat30.security.app/bnd.bnd b/dev/io.openliberty.springboot.fat30.security.app/bnd.bnd new file mode 100644 index 000000000000..d951ae57b80b --- /dev/null +++ b/dev/io.openliberty.springboot.fat30.security.app/bnd.bnd @@ -0,0 +1,53 @@ +#******************************************************************************* +# Copyright (c) 2017, 2023 IBM Corporation and others. +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License 2.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/epl-2.0/ +# +# SPDX-License-Identifier: EPL-2.0 +# +# Contributors: +# IBM Corporation - initial API and implementation +#******************************************************************************* +-include= \ + ~../cnf/resources/bnd/bundle.props, \ + ~../cnf/resources/bnd/bundle.spring.props +-nouses=true + +bVersion=1.0 + +test.project: true +instrument.disabled: true +publish.wlp.jar.disabled: true + +javac.source: 17 +javac.target: 17 + +src: \ + src/main/java, \ + src/main/resources + +# Specify bundles to be added to the classpath of a VM used in testing. +# Entries in the -testpath instruction enable the Eclipse Package Explorer +# to resolve compile dependencies for test classes. The instruction is not +# required to build Spring Boot test artifacts. Each entry requies a +# corresponding entry in file cnf/oss_depenendcies.maven. +# Ref: https://bndtools.org/manual/packageexplorer.html + +-testpath: \ + org.springframework.boot:spring-boot;${springBootVersion30}, \ + org.springframework.boot:spring-boot-autoconfigure;${springBootVersion30}, \ +\ + org.springframework:spring-beans;${springVersion30}, \ + org.springframework:spring-context;${springVersion30}, \ + org.springframework:spring-core;${springVersion30}, \ + org.springframework:spring-web;${springVersion30}, \ + org.springframework:spring-webmvc;${springVersion30}, \ +\ + org.springframework.security:spring-security-config;${springSecurityVersion30}, \ + org.springframework.security:spring-security-core;${springSecurityVersion30}, \ + org.springframework.security:spring-security-crypto;${springSecurityVersion30}, \ + org.springframework.security:spring-security-web;${springSecurityVersion30}, \ +\ + io.openliberty.jakarta.servlet.6.0 diff --git a/dev/io.openliberty.springboot.fat30.security.app/build.gradle b/dev/io.openliberty.springboot.fat30.security.app/build.gradle new file mode 100644 index 000000000000..b37aa2fc6653 --- /dev/null +++ b/dev/io.openliberty.springboot.fat30.security.app/build.gradle @@ -0,0 +1,56 @@ +/******************************************************************************* + * Copyright (c) 2017, 2023 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + ********************************************************************************/ + +// https://plugins.gradle.org/plugin/org.springframework.boot +plugins { + id 'org.springframework.boot' version '3.0.7' +} +apply from: '../wlp-gradle/subprojects/spring.gradle' +def sv = springVersions[ '3.0' ] + +apply plugin: 'java' +apply plugin: 'io.spring.dependency-management' + +group = 'io.openliberty.example.spring' +version = '0.0.1-SNAPSHOT' +sourceCompatibility = 17 + +apply from: '../wlp-gradle/subprojects/maven-central-mirror.gradle' + +dependencies { + implementation('org.springframework.boot:spring-boot' + ':' + sv['springBoot.fat']) + implementation('org.springframework.boot:spring-boot-autoconfigure' + ':' + sv['springBoot.fat']) + + implementation('org.springframework.boot:spring-boot-starter-web') // + ':' + sv['springBoot']) // x + implementation('org.springframework.boot:spring-boot-starter-thymeleaf') // + ':' + sv['springBoot']) // x + implementation('org.springframework.boot:spring-boot-starter-security') // + ':' + sv['springBoot']) // x + implementation('org.thymeleaf.extras:thymeleaf-extras-springsecurity6') + + implementation('org.springframework:spring-beans' + ':' + sv['spring.fat']) + implementation('org.springframework:spring-core' + ':' + sv['spring.fat']) + implementation('org.springframework:spring-context' + ':' + sv['spring.fat']) + implementation('org.springframework:spring-web' + ':' + sv['spring.fat']) + implementation('org.springframework:spring-webmvc' + ':' + sv['spring.fat']) + + implementation('org.springframework.security:spring-security-config' + ':' + sv['springSecurity.fat']) + implementation('org.springframework.security:spring-security-core' + ':' + sv['springSecurity.fat']) + implementation('org.springframework.security:spring-security-web' + ':' + sv['springSecurity.fat']) + + implementation('org.webjars:bootstrap:5.2.3') + implementation('org.webjars:webjars-locator:0.46') + implementation('org.webjars:jquery:3.6.4') +} + +bootJar { + duplicatesStrategy 'warn' +} diff --git a/dev/io.openliberty.springboot.fat30.security.app/springboot.gradle b/dev/io.openliberty.springboot.fat30.security.app/springboot.gradle new file mode 100644 index 000000000000..8b137891791f --- /dev/null +++ b/dev/io.openliberty.springboot.fat30.security.app/springboot.gradle @@ -0,0 +1 @@ + diff --git a/dev/io.openliberty.springboot.fat30.security.app/src/main/java/com/ibm/ws/springboot/fat30/test/app/CustomizationBean.java b/dev/io.openliberty.springboot.fat30.security.app/src/main/java/com/ibm/ws/springboot/fat30/test/app/CustomizationBean.java new file mode 100644 index 000000000000..3d1abc2042f5 --- /dev/null +++ b/dev/io.openliberty.springboot.fat30.security.app/src/main/java/com/ibm/ws/springboot/fat30/test/app/CustomizationBean.java @@ -0,0 +1,31 @@ +/******************************************************************************* + * Copyright (c) 2018,2023 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package com.ibm.ws.springboot.fat30.test.app; + + +import org.springframework.boot.web.server.MimeMappings; +import org.springframework.boot.web.server.WebServerFactoryCustomizer; +import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory; +import org.springframework.stereotype.Component; + +@Component +public class CustomizationBean implements WebServerFactoryCustomizer { + + @Override + public void customize(ConfigurableServletWebServerFactory server) { + MimeMappings mappings = new MimeMappings(MimeMappings.DEFAULT); + mappings.add("weby","application/json"); + server.setMimeMappings(mappings); + } + +} \ No newline at end of file diff --git a/dev/io.openliberty.springboot.fat30.security.app/src/main/java/com/ibm/ws/springboot/fat30/test/app/MvcConfig.java b/dev/io.openliberty.springboot.fat30.security.app/src/main/java/com/ibm/ws/springboot/fat30/test/app/MvcConfig.java new file mode 100644 index 000000000000..748ca10a88a5 --- /dev/null +++ b/dev/io.openliberty.springboot.fat30.security.app/src/main/java/com/ibm/ws/springboot/fat30/test/app/MvcConfig.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2018,2023 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package com.ibm.ws.springboot.fat30.test.app; + +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + +@Configuration +public class MvcConfig implements WebMvcConfigurer { + + @Override + public void addViewControllers(ViewControllerRegistry registry) { + registry.addViewController("/hello").setViewName("hello"); + registry.addViewController("/login").setViewName("login"); + } + +} diff --git a/dev/io.openliberty.springboot.fat30.security.app/src/main/java/com/ibm/ws/springboot/fat30/test/app/SecurityConfiguration.java b/dev/io.openliberty.springboot.fat30.security.app/src/main/java/com/ibm/ws/springboot/fat30/test/app/SecurityConfiguration.java new file mode 100644 index 000000000000..96173dce8749 --- /dev/null +++ b/dev/io.openliberty.springboot.fat30.security.app/src/main/java/com/ibm/ws/springboot/fat30/test/app/SecurityConfiguration.java @@ -0,0 +1,63 @@ +/******************************************************************************* + * Copyright (c) 2018,2023 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package com.ibm.ws.springboot.fat30.test.app; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +import org.springframework.security.core.userdetails.User; +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.security.core.userdetails.UserDetailsService; +import org.springframework.security.provisioning.InMemoryUserDetailsManager; +import org.springframework.security.web.SecurityFilterChain; + +// Updated for Spring 3.0 per: +// +// https://spring.io/blog/2022/02/21/spring-security-without-the-websecurityconfigureradapter +// +// https://docs.spring.io/spring-security/reference/servlet/authorization/authorize-http-requests.html +// +// https://stackoverflow.com/questions/72381114/spring-security-upgrading-the-deprecated-websecurityconfigureradapter-in-spring +// +// https://spring.io/guides/gs/securing-web/ + +@Configuration +@EnableWebSecurity +public class SecurityConfiguration { + + @Bean + public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { + http.authorizeHttpRequests() + .requestMatchers("/", "/hello").hasRole("USER") + .anyRequest(); + http.formLogin() + .loginPage("/login") + .permitAll(); + http.logout((logout) -> logout.permitAll()); + + return http.build(); + } + + @Bean + public UserDetailsService userDetailsService() { + UserDetails user = + User.withDefaultPasswordEncoder() + .username("user") + .password("password") + .roles("USER") + .build(); + + return new InMemoryUserDetailsManager(user); + } +} diff --git a/dev/io.openliberty.springboot.fat30.security.app/src/main/java/com/ibm/ws/springboot/fat30/test/app/TestApplication.java b/dev/io.openliberty.springboot.fat30.security.app/src/main/java/com/ibm/ws/springboot/fat30/test/app/TestApplication.java new file mode 100644 index 000000000000..3f992db4c894 --- /dev/null +++ b/dev/io.openliberty.springboot.fat30.security.app/src/main/java/com/ibm/ws/springboot/fat30/test/app/TestApplication.java @@ -0,0 +1,105 @@ +/******************************************************************************* + * Copyright (c) 2018,2023 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package com.ibm.ws.springboot.fat30.test.app; + +import jakarta.servlet.ServletContext; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.core.env.Environment; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@SpringBootApplication +@RestController +public class TestApplication { + public static final String TEST_ATTR = "test.weblistener.attr"; + @Autowired + ServletContext context; + + @Autowired + private Environment env; + + public static void main(String[] args) { + SpringApplication.run(TestApplication.class, args); + for(String arg: args) { + if("--throw.application.exception=true".equals(arg)) { + throw new RuntimeException("APPLICATION EXCEPTION"); + } + } + } + + @RequestMapping("/") + public String hello() { + return "HELLO SPRING BOOT!!"; + } + + @RequestMapping(value="/buttonClicked", produces="text/html") + public String click() { + return "Hello. You clicked a button."; + } + + @RequestMapping(value="/getAppProp") + public String getAppProperty(@RequestParam("key") String key) { + return env.getProperty(key); + } + + @RequestMapping("/testWebListenerAttr") + public String testWebListenerAttr() { + // should be null + Object result = context.getAttribute(TEST_ATTR); + if (result == null) { + return "PASSED"; + } else { + return "FAILED"; + } + } + + @RequestMapping("/testContextParams") + public String testContextParams() { + return context.getInitParameter("context_parameter_test_key"); + } + + @RequestMapping(value="/exception", produces="text/html") + public void throwIllegalArgumentException() { + throw new IllegalArgumentException("Thrown on purpose for FAT test. Exception error page."); + } + + @RequestMapping(value="/other-exception", produces="text/html") + public void throwFileSystemNotFoundException() { + throw new java.nio.file.FileSystemNotFoundException("Thrown on purpose for FAT test. Default error page."); + } + + static final String + IbmApiClazzName = "com.ibm.websphere.application.ApplicationMBean", + TpClazzName = "jakarta.mail.Message"; + + @RequestMapping("/loadIbmApiClass") + public String loadApiClass() { return loadClazz(IbmApiClazzName); } + + @RequestMapping("/loadTpClass") + public String loadTpClass() { return loadClazz(TpClazzName); } + + String loadClazz(String clazzName) { + Class clazz = null; + try { + clazz = this.getClass().getClassLoader().loadClass(clazzName); + } catch (Exception e) { + e.printStackTrace(System.out); + } + return "SPRING BOOT, YOU GOT" + ((null==clazz) ? " NO " : " ") + "CLAZZ: " + clazzName; + } + +} diff --git a/dev/io.openliberty.springboot.fat30.security.app/src/main/java/com/ibm/ws/springboot/fat30/test/app/TestErrorPageRegistrar.java b/dev/io.openliberty.springboot.fat30.security.app/src/main/java/com/ibm/ws/springboot/fat30/test/app/TestErrorPageRegistrar.java new file mode 100644 index 000000000000..47865baf616b --- /dev/null +++ b/dev/io.openliberty.springboot.fat30.security.app/src/main/java/com/ibm/ws/springboot/fat30/test/app/TestErrorPageRegistrar.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * Copyright (c) 2018,2023 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package com.ibm.ws.springboot.fat30.test.app; + +import org.springframework.boot.web.server.ErrorPage; +import org.springframework.boot.web.server.ErrorPageRegistrar; +import org.springframework.boot.web.server.ErrorPageRegistry; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.http.HttpStatus; + +@Configuration +public class TestErrorPageRegistrar implements ErrorPageRegistrar { + @Override + public void registerErrorPages(ErrorPageRegistry registry) { + registry.addErrorPages(new ErrorPage(IllegalArgumentException.class, "/errorPageException.html"), + new ErrorPage("/defaultErrorPage.html"), + new ErrorPage(HttpStatus.NOT_FOUND, "/noSuchPage.html")); + } + + @Bean + public ErrorPageRegistrar errorPageRegistrar(){ + return new TestErrorPageRegistrar(); + } +} diff --git a/dev/io.openliberty.springboot.fat30.security.app/src/main/java/com/ibm/ws/springboot/fat30/test/app/TestWebFilter.java b/dev/io.openliberty.springboot.fat30.security.app/src/main/java/com/ibm/ws/springboot/fat30/test/app/TestWebFilter.java new file mode 100644 index 000000000000..737607c66251 --- /dev/null +++ b/dev/io.openliberty.springboot.fat30.security.app/src/main/java/com/ibm/ws/springboot/fat30/test/app/TestWebFilter.java @@ -0,0 +1,45 @@ +/******************************************************************************* + * Copyright (c) 2018,2023 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package com.ibm.ws.springboot.fat30.test.app; + +import java.io.IOException; + +import jakarta.servlet.Filter; +import jakarta.servlet.FilterChain; +import jakarta.servlet.FilterConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; +import jakarta.servlet.annotation.WebFilter; + +@WebFilter("/WebServlet") +public class TestWebFilter implements Filter { + + @Override + public void destroy() { + // nothing + } + + @Override + public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) + throws IOException, ServletException { + resp.getOutputStream().print("@WebFilter-"); + chain.doFilter(req, resp); + } + + @Override + public void init(FilterConfig config) throws ServletException { + // nothing + } + +} diff --git a/dev/io.openliberty.springboot.fat30.security.app/src/main/java/com/ibm/ws/springboot/fat30/test/app/TestWebListener.java b/dev/io.openliberty.springboot.fat30.security.app/src/main/java/com/ibm/ws/springboot/fat30/test/app/TestWebListener.java new file mode 100644 index 000000000000..06eda0cba74d --- /dev/null +++ b/dev/io.openliberty.springboot.fat30.security.app/src/main/java/com/ibm/ws/springboot/fat30/test/app/TestWebListener.java @@ -0,0 +1,32 @@ +/******************************************************************************* + * Copyright (c) 2018,2023 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package com.ibm.ws.springboot.fat30.test.app; + +import jakarta.servlet.ServletContextEvent; +import jakarta.servlet.ServletContextListener; +import jakarta.servlet.annotation.WebListener; + +@WebListener +public class TestWebListener implements ServletContextListener { + + @Override + public void contextDestroyed(ServletContextEvent e) { + // nothing + } + + @Override + public void contextInitialized(ServletContextEvent e) { + e.getServletContext().setAttribute(TestApplication.TEST_ATTR, "PASSED"); + } + +} diff --git a/dev/io.openliberty.springboot.fat30.security.app/src/main/java/com/ibm/ws/springboot/fat30/test/app/TestWebServlet.java b/dev/io.openliberty.springboot.fat30.security.app/src/main/java/com/ibm/ws/springboot/fat30/test/app/TestWebServlet.java new file mode 100644 index 000000000000..92318324ee37 --- /dev/null +++ b/dev/io.openliberty.springboot.fat30.security.app/src/main/java/com/ibm/ws/springboot/fat30/test/app/TestWebServlet.java @@ -0,0 +1,31 @@ +/******************************************************************************* + * Copyright (c) 2018,2023 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package com.ibm.ws.springboot.fat30.test.app; + +import java.io.IOException; + +import jakarta.servlet.ServletException; +import jakarta.servlet.annotation.WebServlet; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +@SuppressWarnings("serial") +@WebServlet("/WebServlet") +public class TestWebServlet extends HttpServlet { + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + resp.getOutputStream().print("@WebServlet-" + req.getServletContext().getAttribute(TestApplication.TEST_ATTR)); + } + +} diff --git a/dev/io.openliberty.springboot.fat30.security.app/src/main/resources/application.properties b/dev/io.openliberty.springboot.fat30.security.app/src/main/resources/application.properties new file mode 100644 index 000000000000..3403dc976cc6 --- /dev/null +++ b/dev/io.openliberty.springboot.fat30.security.app/src/main/resources/application.properties @@ -0,0 +1,13 @@ +############################################################################### +# Copyright (c) 2018 IBM Corporation and others. +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License 2.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/epl-2.0/ +# +# SPDX-License-Identifier: EPL-2.0 +# +# Contributors: +# IBM Corporation - initial API and implementation +############################################################################### +server.port=8081 \ No newline at end of file diff --git a/dev/io.openliberty.springboot.fat30.security.app/src/main/resources/public/defaultErrorPage.html b/dev/io.openliberty.springboot.fat30.security.app/src/main/resources/public/defaultErrorPage.html new file mode 100644 index 000000000000..f911d706846a --- /dev/null +++ b/dev/io.openliberty.springboot.fat30.security.app/src/main/resources/public/defaultErrorPage.html @@ -0,0 +1,9 @@ + + + + + + +This is a default error handling page + + \ No newline at end of file diff --git a/dev/io.openliberty.springboot.fat30.security.app/src/main/resources/public/errorPageException.html b/dev/io.openliberty.springboot.fat30.security.app/src/main/resources/public/errorPageException.html new file mode 100644 index 000000000000..db1cffac1ed1 --- /dev/null +++ b/dev/io.openliberty.springboot.fat30.security.app/src/main/resources/public/errorPageException.html @@ -0,0 +1,9 @@ + + + + + +

Exception thrown of type IllegalArgumentException

+ + + \ No newline at end of file diff --git a/dev/io.openliberty.springboot.fat30.security.app/src/main/resources/public/file.weby b/dev/io.openliberty.springboot.fat30.security.app/src/main/resources/public/file.weby new file mode 100644 index 000000000000..0604c964ae9c --- /dev/null +++ b/dev/io.openliberty.springboot.fat30.security.app/src/main/resources/public/file.weby @@ -0,0 +1,4 @@ +{ + "name": "Sam", + "city": "Austin" +} \ No newline at end of file diff --git a/dev/io.openliberty.springboot.fat30.security.app/src/main/resources/public/noSuchPage.html b/dev/io.openliberty.springboot.fat30.security.app/src/main/resources/public/noSuchPage.html new file mode 100644 index 000000000000..6289d685df76 --- /dev/null +++ b/dev/io.openliberty.springboot.fat30.security.app/src/main/resources/public/noSuchPage.html @@ -0,0 +1,9 @@ + + + + + +

The requested page does not exist...

+ + + \ No newline at end of file diff --git a/dev/io.openliberty.springboot.fat30.security.app/src/main/resources/public/useJarUrlsTest.html b/dev/io.openliberty.springboot.fat30.security.app/src/main/resources/public/useJarUrlsTest.html new file mode 100644 index 000000000000..aca00f45dc9b --- /dev/null +++ b/dev/io.openliberty.springboot.fat30.security.app/src/main/resources/public/useJarUrlsTest.html @@ -0,0 +1,19 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/dev/io.openliberty.springboot.fat30.security.app/src/main/resources/server-keystore.jks b/dev/io.openliberty.springboot.fat30.security.app/src/main/resources/server-keystore.jks new file mode 100644 index 0000000000000000000000000000000000000000..7fbe48c9a29f01d4bb4db4b33bc07bc6c25845be GIT binary patch literal 2248 zcmchY={M938^`B2n;2`DEVo?}(Qn3*u_apw$&w{ujEOKt%m^7YvSlZ0q9kOp-`TRn z!`LcI)`)nNB-tr$+`7;6;{FSs7uSpL=bY=D>wK^4e6NG$gJlQ=0zE3=pW^T*5~zMe z1%IMn0MYM=l6J2vkspMirZGuYgi?l;s{!qnP75bIaak>0n z3WC+zYw4`ca=7-uvkQ$c@lMLdako1Huhn$%zF$nB?TzWpIkh9Nj_G$Mg^FpPGTB<*;F3 zv*$Q~!ui4*PZG_hj5>_2X3&%XrE5Q)F}C5_WIQ%P!={;^HE10#t+*$S9PDE8Hs9KRC}WzIbhO{Mlu5qkz71SJ~KE z`YDS&UbYP=S2VMZ$8_@k%67X^g`N_+HUOyoi#&{?-U~x#PsX!2ktS{5Awm_ zOc|g2n}g{s&2P{`w{XO-w^G+Q^Eu}JaJ%duZe7x`N*bZ9E=lGY2(6@vPsT^c1W!kw z&NXwX6Pph&39s@xVZhLv(2Y_bxOghvLi!kA1cl$I8nmj|^H7^TGbqqwl z9AKh9l%^*XI0?oeg2N2vL?;i54(j*%`clk&M^kk)5jc+urrTvMWKrFn80=Xv2LFCH zTU6q~uS<&Y5gX{q?*R0vWzlr&yz`|`y|)MN3ORRfNIM(^q<&Q!^3A97C2~WtEqgI~ zf@0N+b<~*mkyq*U+j|n4oz1;Ga|c@i)p`0^{xd&CFB=0AC89VM?NvCIg;}09fj)+2 zdoR$Wd2)1#Tksho5MDloSqbz#tdlqL$q+7{{h+s^%xh+1vwbNyNVREW z-p674t?Ktm^+G2F9}1e?x$amS>uyNcooL=`v$|6)w;Z2YO$to9R6t%+v04M|m^u(Y*RwT>@j^u^fSYf!2 z;`2xx<7FWQ`BU%|B8KazOAu<;^DL1aI73?F#>w?^@z^oapP zZ?Z3m=tIFA2f2S!7%!_gnSl59Ap285@e>>v90tTHVL@eOWfcbjE-a{u1F<0Xf8hT* z4IPmDw;4yT0!9b8ARrxJgVF&2lJa2tK2tPjJC=_~|MNc;@@6*+1*G-_^}V zBQ;9t!1#Dv%xgPazO_e}a5lq1SSpfCUeJe2^&K#`+Oig3cwa6XZ>&9fO2v!Oz4Ikpx_+CRb( z9yb3r@#vzCOavhIS*0S(8nW4}<3N_9`bdn3O!={v>r~miRXu9qShT;CQQ?`tzUrGk z@Aq4Oi^*6EHfbtOmW#`#cncBKHN4)MgcDO`rz*|e>k8ZJ(uQPtScMd^kj20|b{w=lO$YFTPdenBqK zK`?F1!fX&18YqbK8d@3}7#SNGn3x(GMoI7+8JJlb7#SEr1?cCLCPpRXU|?irU~XdM zXE11DNK{R~N?GmY|1 ziQDG)yJyYu_rK*ScXvunXa4)<`zOjICO&r1t#aa6vPRF!_Vbg+%qB0p^4bcHTYoXJ ze(v!4N(%GwqqCHBEiUS&%$@L9?;h)e2k+jM72cNHUntzLuXNAVCmK`#eSP`bX8lvO zS$c;Sf6$6=vzQnleD0B2^9<)}Gi?oTbt!+p82?>;QQi#|;pF0|t8q)8`jcafY`u6U?Kb;HA@F%eIXgehFm)pM*{w|ZXo$+y>C zw}rbXO6~s0{dZ1Zc;(@*{C=YRp-jw-42+8v4de}EfiWw~$0Eiea`R2)%Qdws>badi z{IjO5|M^1tFGu7wJa;Ra_sqZzDOpUAOGTiO5{h46KC*N&$AOA zWh|S%zRL8*j!geo{x*Cor!JkeF4g7vo-MM=o_Q7L*Z#R;7CmR3##vzoyPrRFPlkTa zKUsP}j&=Uw8%J0?YBl$TRD3?2=&=0lj^?{gr^UDTPQ5K0>Y{wh+961S&Hah{g~^H* zS8_K!v!1H17~SykdPD2Oi3<-uwR!VoSwh+lt!Gd8?;kkz`<3#GpFugbNvpM3&l(AC zUuMStW#3}Q1!atrcgmg>Prh=_p)GGwPuYY{$^S+vveEW)_Fd&xeX_&vm}}IcD6?t+ DP2X(E literal 0 HcmV?d00001 diff --git a/dev/io.openliberty.springboot.fat30.security.app/src/main/resources/templates/hello.html b/dev/io.openliberty.springboot.fat30.security.app/src/main/resources/templates/hello.html new file mode 100644 index 000000000000..326a97d3a6a5 --- /dev/null +++ b/dev/io.openliberty.springboot.fat30.security.app/src/main/resources/templates/hello.html @@ -0,0 +1,13 @@ + + + + Hello World! + + +

Hello !

+
+ +
+ + \ No newline at end of file diff --git a/dev/io.openliberty.springboot.fat30.security.app/src/main/resources/templates/login.html b/dev/io.openliberty.springboot.fat30.security.app/src/main/resources/templates/login.html new file mode 100644 index 000000000000..8dfe7d9b1bec --- /dev/null +++ b/dev/io.openliberty.springboot.fat30.security.app/src/main/resources/templates/login.html @@ -0,0 +1,21 @@ + + + + + Spring Security Example + + +
+ Invalid username and password. +
+
+ You have been logged out. +
+
+
+
+
+
+ + diff --git a/dev/io.openliberty.springboot.fat30_fat/bnd.bnd b/dev/io.openliberty.springboot.fat30_fat/bnd.bnd index d634939143cf..4020f6fe60ad 100644 --- a/dev/io.openliberty.springboot.fat30_fat/bnd.bnd +++ b/dev/io.openliberty.springboot.fat30_fat/bnd.bnd @@ -89,4 +89,5 @@ src: \ io.openliberty.springboot.fat30.war.app;version=latest,\ io.openliberty.springboot.fat30.webanno.app;version=latest,\ io.openliberty.springboot.fat30.webflux.app;version=latest,\ - io.openliberty.springboot.fat30.websocket.app;version=latest + io.openliberty.springboot.fat30.websocket.app;version=latest,\ + io.openliberty.springboot.fat30.security.app;version=latest diff --git a/dev/io.openliberty.springboot.fat30_fat/build.gradle b/dev/io.openliberty.springboot.fat30_fat/build.gradle index 16663db84c5b..ef67ce027891 100644 --- a/dev/io.openliberty.springboot.fat30_fat/build.gradle +++ b/dev/io.openliberty.springboot.fat30_fat/build.gradle @@ -65,7 +65,8 @@ def appDefs = [ 'io.openliberty.springboot.fat30.websocket.app', '.jar' ], [ 'io.openliberty.springboot.fat30.actuator.app', '.jar' ], [ 'io.openliberty.springboot.fat30.webflux.app', '.jar' ], - [ 'io.openliberty.springboot.fat30.multicontext.app', '.jar' ] ] + [ 'io.openliberty.springboot.fat30.multicontext.app', '.jar' ], + [ 'io.openliberty.springboot.fat30.security.app', '.jar' ] ] autoFVT.dependsOn ':wlp.lib.extract:build' appDefs.each { appDef -> diff --git a/dev/io.openliberty.springboot.fat30_fat/fat/src/com/ibm/ws/springboot/support/fat/AbstractSpringTests.java b/dev/io.openliberty.springboot.fat30_fat/fat/src/com/ibm/ws/springboot/support/fat/AbstractSpringTests.java index 1f64ce7d0b50..9fdc9bf70aab 100644 --- a/dev/io.openliberty.springboot.fat30_fat/fat/src/com/ibm/ws/springboot/support/fat/AbstractSpringTests.java +++ b/dev/io.openliberty.springboot.fat30_fat/fat/src/com/ibm/ws/springboot/support/fat/AbstractSpringTests.java @@ -66,6 +66,8 @@ public abstract class AbstractSpringTests { "io.openliberty.springboot.fat30.webflux.app-0.0.1-SNAPSHOT.jar"; public static final String SPRING_BOOT_30_APP_WEBSOCKET = "io.openliberty.springboot.fat30.websocket.app-0.0.1-SNAPSHOT.jar"; + public static final String SPRING_BOOT_30_APP_SECURITY = + "io.openliberty.springboot.fat30.security.app-0.0.1-SNAPSHOT.jar"; // Various spring configuration property fragments. diff --git a/dev/io.openliberty.springboot.fat30_fat/fat/src/com/ibm/ws/springboot/support/fat/FATSuite.java b/dev/io.openliberty.springboot.fat30_fat/fat/src/com/ibm/ws/springboot/support/fat/FATSuite.java index b3d501fbc91f..f3bd51e7b7cb 100644 --- a/dev/io.openliberty.springboot.fat30_fat/fat/src/com/ibm/ws/springboot/support/fat/FATSuite.java +++ b/dev/io.openliberty.springboot.fat30_fat/fat/src/com/ibm/ws/springboot/support/fat/FATSuite.java @@ -37,14 +37,11 @@ WarmStartTests30.class, SSLTests30.class, SSLMutualAuthTests30.class, - // SpringSecurityTests30.class, - // Disabled due to application failures. + SpringSecurityTests30.class, JSPTests30.class, - // MissingServletTests30.class, - // Disabled: The jakarta servlet class is being provisioned even without the servlet feature! + MissingServletTests30.class, MissingSslFeatureTests30.class, - // MissingWebsocketFeatureTests30.class, - // Disabled: The jakarta web socket class is being provisioned even without the web socket feature! + MissingWebsocketFeatureTests30.class, MultiContextTests30.class, MultipleApplicationsNotSupported30.class, NeedSpringBootFeatureTests30.class, @@ -56,7 +53,7 @@ WebSocketTests30.class, MimeMapping30.class, ErrorPage30Test.class, - // EnableSpringBootTraceTests30.class, + //EnableSpringBootTraceTests30.class, // Disabled: Failing to start web server. See the test class for details. ExceptionOccuredAfterAppIsAvailableTest30.class, JakartaFeatureTests30.class, diff --git a/dev/io.openliberty.springboot.fat30_fat/fat/src/com/ibm/ws/springboot/support/fat/SpringSecurityTests30.java b/dev/io.openliberty.springboot.fat30_fat/fat/src/com/ibm/ws/springboot/support/fat/SpringSecurityTests30.java index 308fd807f65d..f733c50e89d9 100644 --- a/dev/io.openliberty.springboot.fat30_fat/fat/src/com/ibm/ws/springboot/support/fat/SpringSecurityTests30.java +++ b/dev/io.openliberty.springboot.fat30_fat/fat/src/com/ibm/ws/springboot/support/fat/SpringSecurityTests30.java @@ -15,7 +15,6 @@ import static org.junit.Assert.assertTrue; import java.io.IOException; -import java.util.Arrays; import java.util.HashSet; import java.util.Set; @@ -62,7 +61,7 @@ public Set getFeatures() { @Override public String getApplication() { - return SPRING_BOOT_30_APP_BASE; + return SPRING_BOOT_30_APP_SECURITY; } @After @@ -105,7 +104,7 @@ private HtmlPage signInWithCorrectCredentials(HtmlPage loginPage) throws IOExcep HtmlPage helloPage = (HtmlPage) form.getInputByName("signIn").click(); //Only authorized users are authenticated and provided access to hello page String url = helloPage.getUrl().toExternalForm(); - assertTrue("User not authenticated, hence not directed to hello page:" + url, url.endsWith(EXPECTED_HTTP_PORT + "/hello")); + assertTrue("User not authenticated, hence not directed to hello page:" + url, url.endsWith(EXPECTED_HTTP_PORT + "/hello?continue")); String body = helloPage.getBody().asText(); assertTrue("Expected output not found:" + body, body.contains("Hello user!")); return helloPage; diff --git a/dev/io.openliberty.springboot.fat30_fat/publish/servers/SpringBootTests/jvm.options b/dev/io.openliberty.springboot.fat30_fat/publish/servers/SpringBootTests/jvm.options new file mode 100644 index 000000000000..9ec5b94cf71a --- /dev/null +++ b/dev/io.openliberty.springboot.fat30_fat/publish/servers/SpringBootTests/jvm.options @@ -0,0 +1 @@ +-Dcom.ibm.ws.beta.edition=true \ No newline at end of file From 6bf8a1929231237a5cae436aa430fca4acfa6db2 Mon Sep 17 00:00:00 2001 From: Ricky Herget Date: Thu, 3 Aug 2023 14:30:12 -0400 Subject: [PATCH 4/4] solve springboot trace fat test --- .../fat/EnableSpringBootTraceTests30.java | 94 +------------------ .../ws/springboot/support/fat/FATSuite.java | 3 +- .../support/fat/MissingServletTests30.java | 13 +-- .../fat/MissingWebsocketFeatureTests30.java | 31 +++--- 4 files changed, 24 insertions(+), 117 deletions(-) diff --git a/dev/io.openliberty.springboot.fat30_fat/fat/src/com/ibm/ws/springboot/support/fat/EnableSpringBootTraceTests30.java b/dev/io.openliberty.springboot.fat30_fat/fat/src/com/ibm/ws/springboot/support/fat/EnableSpringBootTraceTests30.java index cbcb1793a794..34067ac4709d 100644 --- a/dev/io.openliberty.springboot.fat30_fat/fat/src/com/ibm/ws/springboot/support/fat/EnableSpringBootTraceTests30.java +++ b/dev/io.openliberty.springboot.fat30_fat/fat/src/com/ibm/ws/springboot/support/fat/EnableSpringBootTraceTests30.java @@ -14,8 +14,9 @@ import static componenttest.custom.junit.runner.Mode.TestMode.FULL; -import java.util.Collections; +import java.util.Arrays; import java.util.HashMap; +import java.util.HashSet; import java.util.Map; import java.util.Set; @@ -27,99 +28,14 @@ import componenttest.custom.junit.runner.FATRunner; import componenttest.custom.junit.runner.Mode; -// Disabled: Failing to start web server. - -// org.springframework.context.ApplicationContextException: Unable to start web serve -// at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:164) ~[spring-boot-3.0.4.jar:3.0.4 -// at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:578) ~[spring-context-6.0.6.jar:6.0.6 -// at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146) ~[spring-boot-3.0.4.jar:3.0.4 -// at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:732) ~[spring-boot-3.0.4.jar:3.0.4 -// at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:434) ~[spring-boot-3.0.4.jar:3.0.4 -// at org.springframework.boot.SpringApplication.run(SpringApplication.java:310) ~[spring-boot-3.0.4.jar:3.0.4 -// at org.springframework.boot.SpringApplication.run(SpringApplication.java:1304) ~[spring-boot-3.0.4.jar:3.0.4 -// at org.springframework.boot.SpringApplication.run(SpringApplication.java:1293) ~[spring-boot-3.0.4.jar:3.0.4 -// at com.ibm.ws.springboot.fat30.test.app.TestApplication.main(TestApplication.java:36) ~[com.ibm.ws.springboot.fat30.app-0.0.1-SNAPSHOT.spring:na -// at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na -// at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na -// at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na -// at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na -// at com.ibm.ws.app.manager.springboot.internal.SpringBootRuntimeContainer.lambda$invokeSpringMain$6(SpringBootRuntimeContainer.java:139) ~[na:na -// at com.ibm.ws.threading.internal.ExecutorServiceImpl$RunnableWrapper.run(ExecutorServiceImpl.java:247) ~[na:na -// at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136) ~[na:na -// at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) ~[na:na -// at java.base/java.lang.Thread.run(Thread.java:857) ~[na:na -// Caused by: org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomca -// at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.initialize(TomcatWebServer.java:142) ~[spring-boot-3.0.4.jar:3.0.4 -// at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.(TomcatWebServer.java:104) ~[spring-boot-3.0.4.jar:3.0.4 -// at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getTomcatWebServer(TomcatServletWebServerFactory.java:488) ~[spring-boot-3.0.4.jar:3.0.4 -// at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getWebServer(TomcatServletWebServerFactory.java:210) ~[spring-boot-3.0.4.jar:3.0.4 -// at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:183) ~[spring-boot-3.0.4.jar:3.0.4 -// at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:161) ~[spring-boot-3.0.4.jar:3.0.4 -// ... 17 common frames omitte -// Caused by: org.apache.catalina.LifecycleException: A child container failed during star -// at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:890) ~[tomcat-embed-core-10.1.8.jar:10.1.8 -// at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:241) ~[tomcat-embed-core-10.1.8.jar:10.1.8 -// at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) ~[tomcat-embed-core-10.1.8.jar:10.1.8 -// at org.apache.catalina.core.StandardService.startInternal(StandardService.java:428) ~[tomcat-embed-core-10.1.8.jar:10.1.8 -// at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) ~[tomcat-embed-core-10.1.8.jar:10.1.8 -// at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:913) ~[tomcat-embed-core-10.1.8.jar:10.1.8 -// at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) ~[tomcat-embed-core-10.1.8.jar:10.1.8 -// at org.apache.catalina.startup.Tomcat.start(Tomcat.java:485) ~[tomcat-embed-core-10.1.8.jar:10.1.8 -// at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.initialize(TomcatWebServer.java:123) ~[spring-boot-3.0.4.jar:3.0.4 -// ... 22 common frames omitte -// Caused by: java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: A child container failed during star -// at java.base/java.util.concurrent.FutureTask.report(FutureTask.java:122) ~[na:na -// at java.base/java.util.concurrent.FutureTask.get(FutureTask.java:191) ~[na:na -// at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:878) ~[tomcat-embed-core-10.1.8.jar:10.1.8 -// ... 30 common frames omitte -// Caused by: org.apache.catalina.LifecycleException: A child container failed during star -// at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:890) ~[tomcat-embed-core-10.1.8.jar:10.1.8 -// at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:846) ~[tomcat-embed-core-10.1.8.jar:10.1.8 -// at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) ~[tomcat-embed-core-10.1.8.jar:10.1.8 -// at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1332) ~[tomcat-embed-core-10.1.8.jar:10.1.8 -// at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1322) ~[tomcat-embed-core-10.1.8.jar:10.1.8 -// at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) ~[na:na -// at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75) ~[tomcat-embed-core-10.1.8.jar:10.1.8 -// at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:145) ~[na:na -// at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:871) ~[tomcat-embed-core-10.1.8.jar:10.1.8 -// ... 30 common frames omitte -// Caused by: java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to initialize component [org.apache.catalina.webresources.StandardRoot@f618ee6e -// at java.base/java.util.concurrent.FutureTask.report(FutureTask.java:122) ~[na:na -// at java.base/java.util.concurrent.FutureTask.get(FutureTask.java:191) ~[na:na -// at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:878) ~[tomcat-embed-core-10.1.8.jar:10.1.8 -// ... 38 common frames omitte -// Caused by: org.apache.catalina.LifecycleException: Failed to initialize component [org.apache.catalina.webresources.StandardRoot@f618ee6e -// at org.apache.catalina.util.LifecycleBase.handleSubClassException(LifecycleBase.java:440) ~[tomcat-embed-core-10.1.8.jar:10.1.8 -// at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:139) ~[tomcat-embed-core-10.1.8.jar:10.1.8 -// at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:173) ~[tomcat-embed-core-10.1.8.jar:10.1.8 -// at org.apache.catalina.core.StandardContext.resourcesStart(StandardContext.java:4567) ~[tomcat-embed-core-10.1.8.jar:10.1.8 -// at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:4700) ~[tomcat-embed-core-10.1.8.jar:10.1.8 -// at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) ~[tomcat-embed-core-10.1.8.jar:10.1.8 -// at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1332) ~[tomcat-embed-core-10.1.8.jar:10.1.8 -// at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1322) ~[tomcat-embed-core-10.1.8.jar:10.1.8 -// at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) ~[na:na -// at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75) ~[tomcat-embed-core-10.1.8.jar:10.1.8 -// at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:145) ~[na:na -// at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:871) ~[tomcat-embed-core-10.1.8.jar:10.1.8 -// ... 38 common frames omitte -// Caused by: java.lang.Error: factory already define -// at java.base/java.net.URL.setURLStreamHandlerFactory(URL.java:1228) ~[na:na -// at org.apache.catalina.webresources.TomcatURLStreamHandlerFactory.(TomcatURLStreamHandlerFactory.java:121) ~[tomcat-embed-core-10.1.8.jar:10.1.8 -// at org.apache.catalina.webresources.TomcatURLStreamHandlerFactory.getInstanceInternal(TomcatURLStreamHandlerFactory.java:52) ~[tomcat-embed-core-10.1.8.jar:10.1.8 -// at org.apache.catalina.webresources.TomcatURLStreamHandlerFactory.register(TomcatURLStreamHandlerFactory.java:73) ~[tomcat-embed-core-10.1.8.jar:10.1.8 -// at org.apache.catalina.webresources.StandardRoot.registerURLStreamHandlerFactory(StandardRoot.java:699) ~[tomcat-embed-core-10.1.8.jar:10.1.8 -// at org.apache.catalina.webresources.StandardRoot.initInternal(StandardRoot.java:686) ~[tomcat-embed-core-10.1.8.jar:10.1.8 -// at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:136) ~[tomcat-embed-core-10.1.8.jar:10.1.8 -// ... 48 common frames omitted - @RunWith(FATRunner.class) -@Mode(FULL) +//@Mode(FULL) @MinimumJavaLevel(javaLevel = 17) public class EnableSpringBootTraceTests30 extends CommonWebServerTests { @Override public Set getFeatures() { - return Collections.singleton("springBoot-3.0"); + return new HashSet<>(Arrays.asList("springBoot-3.0", "servlet-6.0")); } @Override @@ -143,4 +59,4 @@ public void stopTestServer() throws Exception { public void testEnableSpringBootTraceFor30() throws Exception { testBasicSpringBootApplication(); } -} +} \ No newline at end of file diff --git a/dev/io.openliberty.springboot.fat30_fat/fat/src/com/ibm/ws/springboot/support/fat/FATSuite.java b/dev/io.openliberty.springboot.fat30_fat/fat/src/com/ibm/ws/springboot/support/fat/FATSuite.java index f3bd51e7b7cb..f143e1534daa 100644 --- a/dev/io.openliberty.springboot.fat30_fat/fat/src/com/ibm/ws/springboot/support/fat/FATSuite.java +++ b/dev/io.openliberty.springboot.fat30_fat/fat/src/com/ibm/ws/springboot/support/fat/FATSuite.java @@ -53,8 +53,7 @@ WebSocketTests30.class, MimeMapping30.class, ErrorPage30Test.class, - //EnableSpringBootTraceTests30.class, - // Disabled: Failing to start web server. See the test class for details. + EnableSpringBootTraceTests30.class, ExceptionOccuredAfterAppIsAvailableTest30.class, JakartaFeatureTests30.class, TemplateTests30.class, diff --git a/dev/io.openliberty.springboot.fat30_fat/fat/src/com/ibm/ws/springboot/support/fat/MissingServletTests30.java b/dev/io.openliberty.springboot.fat30_fat/fat/src/com/ibm/ws/springboot/support/fat/MissingServletTests30.java index ce40d8c9b79a..4355916d29c7 100644 --- a/dev/io.openliberty.springboot.fat30_fat/fat/src/com/ibm/ws/springboot/support/fat/MissingServletTests30.java +++ b/dev/io.openliberty.springboot.fat30_fat/fat/src/com/ibm/ws/springboot/support/fat/MissingServletTests30.java @@ -34,18 +34,6 @@ public boolean expectApplicationSuccess() { return false; } - // Disabled: The jakarta servlet class is being provisioned even without the servlet feature! - // - // FeatureAuditor: Found [ true ] class [ org.springframework.web.WebApplicationInitializer ] as [ org/springframework/web/WebApplicationInitializer.class ] - // FeatureAuditor: Found [ false ] class [ org.springframework.web.socket.WebSocketHandler ] as [ org/springframework/web/socket/WebSocketHandler.class ] - // FeatureAuditor: Found [ false ] class [ com.ibm.ws.springboot.support.web.server.version15.container.LibertyConfiguration ] as [ com/ibm/ws/springboot/support/web/server/version15/container/LibertyConfiguration.class ] - // FeatureAuditor: Found [ false ] class [ com.ibm.ws.springboot.support.web.server.version20.container.LibertyConfiguration ] as [ com/ibm/ws/springboot/support/web/server/version20/container/LibertyConfiguration.class ] - // FeatureAuditor: Found [ false ] class [ io.openliberty.springboot.support.web.server.version30.container.LibertyConfiguration ] as [ io/openliberty/springboot/support/web/server/version30/container/LibertyConfiguration.class ] - // FeatureAuditor: Found [ false ] class [ javax.servlet.Servlet ] as [ javax/servlet/Servlet.class ] - // FeatureAuditor: Found [ true ] class [ jakarta.servlet.Servlet ] as [ jakarta/servlet/Servlet.class ] - // FeatureAuditor: Found [ false ] class [ javax.websocket.WebSocketContainer ] as [ javax/websocket/WebSocketContainer.class ] - // FeatureAuditor: Found [ true ] class [ jakarta.websocket.WebSocketContainer ] as [ jakarta/websocket/WebSocketContainer.class ] - @Test public void testMissingServletFor30() throws Exception { assertNotNull("No error message CWWKC0274E was found for missing servlet feature", @@ -53,6 +41,7 @@ public void testMissingServletFor30() throws Exception { stopServer(true, "CWWKC0274E", "CWWKZ0002E"); } + // appsecurity-5.0 cannot be added for a seperate test as it contains the servlet-6.0 feature @Override public Set getFeatures() { return Collections.singleton("springBoot-3.0"); diff --git a/dev/io.openliberty.springboot.fat30_fat/fat/src/com/ibm/ws/springboot/support/fat/MissingWebsocketFeatureTests30.java b/dev/io.openliberty.springboot.fat30_fat/fat/src/com/ibm/ws/springboot/support/fat/MissingWebsocketFeatureTests30.java index c6d5c5f68ede..cfeec60c6848 100644 --- a/dev/io.openliberty.springboot.fat30_fat/fat/src/com/ibm/ws/springboot/support/fat/MissingWebsocketFeatureTests30.java +++ b/dev/io.openliberty.springboot.fat30_fat/fat/src/com/ibm/ws/springboot/support/fat/MissingWebsocketFeatureTests30.java @@ -15,7 +15,6 @@ import static componenttest.custom.junit.runner.Mode.TestMode.FULL; import static org.junit.Assert.assertNotNull; -import java.util.Arrays; import java.util.HashSet; import java.util.Set; @@ -35,18 +34,6 @@ public boolean expectApplicationSuccess() { return false; } - // Disabled: The jakarta web socket class is being provisioned even without the web socket feature! - // - // FeatureAuditor: Found [ true ] class [ org.springframework.web.WebApplicationInitializer ] as [ org/springframework/web/WebApplicationInitializer.class ] - // FeatureAuditor: Found [ true ] class [ org.springframework.web.socket.WebSocketHandler ] as [ org/springframework/web/socket/WebSocketHandler.class ] - // FeatureAuditor: Found [ false ] class [ com.ibm.ws.springboot.support.web.server.version15.container.LibertyConfiguration ] as [ com/ibm/ws/springboot/support/web/server/version15/container/LibertyConfiguration.class ] - // FeatureAuditor: Found [ false ] class [ com.ibm.ws.springboot.support.web.server.version20.container.LibertyConfiguration ] as [ com/ibm/ws/springboot/support/web/server/version20/container/LibertyConfiguration.class ] - // FeatureAuditor: Found [ true ] class [ io.openliberty.springboot.support.web.server.version30.container.LibertyConfiguration ] as [ io/openliberty/springboot/support/web/server/version30/container/LibertyConfiguration.class ] - // FeatureAuditor: Found [ false ] class [ javax.servlet.Servlet ] as [ javax/servlet/Servlet.class ] - // FeatureAuditor: Found [ true ] class [ jakarta.servlet.Servlet ] as [ jakarta/servlet/Servlet.class ] - // FeatureAuditor: Found [ false ] class [ javax.websocket.WebSocketContainer ] as [ javax/websocket/WebSocketContainer.class ] - // FeatureAuditor: Found [ true ] class [ jakarta.websocket.WebSocketContainer ] as [ jakarta/websocket/WebSocketContainer.class ] - @Test public void testMissingWebsocketFor30() throws Exception { assertNotNull("No error message CWWKC0275E was found for missing websocket feature", @@ -54,9 +41,25 @@ public void testMissingWebsocketFor30() throws Exception { stopServer(true, "CWWKC0275E", "CWWKZ0002E"); } + @Test + public void testMissingWebsocketWithSecurity() throws Exception { + assertNotNull("No error message CWWKC0275E was found for missing websocket feature", + server.waitForStringInLog("CWWKC0275E")); + stopServer(true, "CWWKC0275E", "CWWKZ0002E"); + } + @Override public Set getFeatures() { - return new HashSet<>(Arrays.asList("springBoot-3.0", "servlet-6.0")); + HashSet features = new HashSet<>(3); + features.add("springBoot-3.0"); + features.add("servlet-6.0"); + + String methodName = testName.getMethodName(); + if ((methodName != null) && methodName.equals("testMissingWebsocketWithSecurity")) { + features.add("appSecurity-5.0"); + } + + return features; } @Override