Skip to content

Commit

Permalink
Merge pull request #25844 from rsherget/springboot-websocket-fat-test
Browse files Browse the repository at this point in the history
Springboot websocket fat test
  • Loading branch information
wraschke committed Aug 4, 2023
2 parents bb85bf1 + 6bf8a19 commit 140e0bd
Show file tree
Hide file tree
Showing 36 changed files with 697 additions and 130 deletions.
18 changes: 18 additions & 0 deletions dev/io.openliberty.springboot.fat30.security.app/.classpath
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="bin/main" path="src/main/java">
<attributes>
<attribute name="gradle_scope" value="main"/>
<attribute name="gradle_used_by_scope" value="main,test"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="bin/main" path="src/main/resources">
<attributes>
<attribute name="gradle_scope" value="main"/>
<attribute name="gradle_used_by_scope" value="main,test"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17/"/>
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
<classpathentry kind="output" path="bin/default"/>
</classpath>
3 changes: 3 additions & 0 deletions dev/io.openliberty.springboot.fat30.security.app/.gitignore
@@ -0,0 +1,3 @@
/bin/
/bin_test/
/generated/
40 changes: 40 additions & 0 deletions dev/io.openliberty.springboot.fat30.security.app/.project
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>io.openliberty.springboot.fat30.security.app</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>bndtools.core.bndbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>bndtools.core.bndnature</nature>
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
</natures>
<filteredResources>
<filter>
<id>1690812734863</id>
<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>
@@ -0,0 +1,2 @@
compileErrorAction=build
eclipse.preferences.version=1
@@ -0,0 +1,2 @@
connection.project.dir=..
eclipse.preferences.version=1
@@ -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
53 changes: 53 additions & 0 deletions 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
56 changes: 56 additions & 0 deletions 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'
}
@@ -0,0 +1 @@

@@ -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<ConfigurableServletWebServerFactory> {

@Override
public void customize(ConfigurableServletWebServerFactory server) {
MimeMappings mappings = new MimeMappings(MimeMappings.DEFAULT);
mappings.add("weby","application/json");
server.setMimeMappings(mappings);
}

}
@@ -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");
}

}
@@ -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);
}
}

0 comments on commit 140e0bd

Please sign in to comment.