Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/upgrading-to-spring-boot-2.x' in…
Browse files Browse the repository at this point in the history
…to upgrading-to-spring-boot-2.x
  • Loading branch information
mederly committed Jun 21, 2018
2 parents fb2adfe + e4fcc78 commit c3b2743
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 93 deletions.
6 changes: 3 additions & 3 deletions build-system/pom.xml
Expand Up @@ -63,10 +63,10 @@
<selenium.version>1.0.1</selenium.version>
<slf4j.version>1.7.25</slf4j.version>
<logback.version>1.2.3</logback.version>
<spring.boot.version>1.5.8.e1</spring.boot.version> <!-- can be replaced by a stock version;
<spring.boot.version>2.0.1.RELEASE</spring.boot.version> <!-- can be replaced by a stock version;
ideally after https://github.com/spring-projects/spring-boot/issues/11367 is resolved but it should be OK even before that -->
<spring.version>5.0.5.RELEASE</spring.version>
<spring.security.version>5.0.5.RELEASE</spring.security.version>
<spring.version>5.0.6.RELEASE</spring.version>
<spring.security.version>5.0.6.RELEASE</spring.security.version>
<cas.client.version>3.5.0</cas.client.version>
<testng.version>6.8.8</testng.version>
<xml.resolver.version>1.2</xml.resolver.version>
Expand Down
3 changes: 2 additions & 1 deletion gui/admin-gui/pom.xml
Expand Up @@ -122,6 +122,7 @@
</plugins>
</build>


<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down Expand Up @@ -210,7 +211,7 @@
<dependency>
<groupId>org.webjars</groupId>
<artifactId>webjars-locator-core</artifactId>
<version>0.32</version>
<version>0.35</version>
</dependency>
<dependency>
<groupId>ro.isdc.wro4j</groupId>
Expand Down
Expand Up @@ -23,9 +23,8 @@
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.autoconfigure.condition.SearchStrategy;
import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration.BeanPostProcessorsRegistrar;
import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory;
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory;
import org.springframework.boot.autoconfigure.web.servlet.ServletWebServerFactoryAutoConfiguration.BeanPostProcessorsRegistrar;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
Expand All @@ -37,7 +36,7 @@
/**
* Custom configuration (factory) for embedded tomcat factory.
* This is necessary, as the tomcat factory is hacking tomcat setup.
* @see MidPointTomcatEmbeddedServletContainerFactory
* @see MidPointTomcatServletWebServerFactory
*
* @author semancik
*/
Expand All @@ -51,12 +50,12 @@ public class EmbeddedTomcatAutoConfiguration {

@Configuration
@ConditionalOnClass({ Servlet.class, Tomcat.class })
@ConditionalOnMissingBean(value = EmbeddedServletContainerFactory.class, search = SearchStrategy.CURRENT)
@ConditionalOnMissingBean(value = TomcatServletWebServerFactory.class, search = SearchStrategy.CURRENT)
public static class EmbeddedTomcat {

@Bean
public TomcatEmbeddedServletContainerFactory tomcatEmbeddedServletContainerFactory() {
return new MidPointTomcatEmbeddedServletContainerFactory();
public TomcatServletWebServerFactory tomcatEmbeddedServletContainerFactory() {
return new MidPointTomcatServletWebServerFactory();
}

}
Expand Down
Expand Up @@ -37,21 +37,27 @@
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
import org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration;
import org.springframework.boot.autoconfigure.security.SecurityFilterAutoConfiguration;
import org.springframework.boot.autoconfigure.web.*;
import org.springframework.boot.autoconfigure.http.HttpMessageConvertersAutoConfiguration;
import org.springframework.boot.autoconfigure.security.servlet.SecurityFilterAutoConfiguration;
import org.springframework.boot.autoconfigure.web.embedded.EmbeddedWebServerFactoryCustomizerAutoConfiguration;
import org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration;
import org.springframework.boot.autoconfigure.web.servlet.MultipartAutoConfiguration;
import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer;
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory;
import org.springframework.boot.web.servlet.ErrorPage;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.server.ErrorPage;
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletListenerRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory;
import org.springframework.boot.web.servlet.server.Session;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ImportResource;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextListener;
import org.springframework.web.filter.DelegatingFilterProxy;
import ro.isdc.wro.http.WroFilter;
Expand All @@ -60,10 +66,11 @@

import java.io.File;
import java.lang.management.ManagementFactory;
import java.util.concurrent.TimeUnit;
import java.time.Duration;

/**
* Created by Viliam Repan (lazyman).
* Modified by Lukas Skublik.
*/
@ImportResource(locations = {
"classpath:ctx-common.xml",
Expand Down Expand Up @@ -91,18 +98,17 @@
})
@ImportAutoConfiguration(classes = {
EmbeddedTomcatAutoConfiguration.class,
DispatcherServletAutoConfiguration.class,
WebMvcAutoConfiguration.class,
HttpMessageConvertersAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class,
SecurityAutoConfiguration.class,
SecurityFilterAutoConfiguration.class,
ServerPropertiesAutoConfiguration.class,
MultipartAutoConfiguration.class
DispatcherServletAutoConfiguration.class,
WebMvcAutoConfiguration.class,
HttpMessageConvertersAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class,
SecurityFilterAutoConfiguration.class,
EmbeddedWebServerFactoryCustomizerAutoConfiguration.class,
MultipartAutoConfiguration.class
})
@SpringBootConfiguration
public class MidPointSpringApplication extends SpringBootServletInitializer {

private static final Trace LOGGER = TraceManager.getTrace(MidPointSpringApplication.class);

private static final String MIDPOINT_HOME_PROPERTY = "midpoint.home";
Expand All @@ -111,7 +117,7 @@ public class MidPointSpringApplication extends SpringBootServletInitializer {

@Autowired StartupConfiguration startupConfiguration;
@Autowired NodeAuthenticationEvaluator nodeAuthenticator;

public static void main(String[] args) {
System.setProperty("xml.catalog.className", CatalogImpl.class.getName());
String mode = args != null && args.length > 0 ? args[0] : null;
Expand Down Expand Up @@ -162,13 +168,14 @@ private static SpringApplicationBuilder configureApplication(SpringApplicationBu
System.setProperty(MIDPOINT_HOME_PROPERTY, mpHome);
}

System.setProperty("spring.config.location", "${midpoint.home}/");
//TODO Could not resolve placeholder
// System.setProperty("spring.config.location", "${midpoint.home}/");

application.bannerMode(Banner.Mode.LOG);

return application.sources(MidPointSpringApplication.class);
}

@Bean
public ServletListenerRegistrationBean requestContextListener() {
return new ServletListenerRegistrationBean(new RequestContextListener());
Expand All @@ -195,7 +202,7 @@ public FilterRegistrationBean wicket() {

return registration;
}

@Bean
public FilterRegistrationBean springSecurityFilterChain() {
FilterRegistrationBean registration = new FilterRegistrationBean();
Expand Down Expand Up @@ -241,44 +248,45 @@ public ServletRegistrationBean staticWebServlet() {
registration.addUrlMappings("/static-web/*");
return registration;
}

@Component
public class ServerCustomization implements WebServerFactoryCustomizer<ConfigurableServletWebServerFactory> {

@Value("${server.servlet.session.timeout}")
private int sessionTimeout;

@Override
public void customize(ConfigurableServletWebServerFactory server) {

server.addErrorPages(new ErrorPage(HttpStatus.UNAUTHORIZED,
"/error/401"));
server.addErrorPages(new ErrorPage(HttpStatus.FORBIDDEN,
"/error/403"));
server.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND,
"/error/404"));
server.addErrorPages(new ErrorPage(HttpStatus.GONE,
"/error/410"));
server.addErrorPages(new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR,
"/error"));

Session session = new Session();
session.setTimeout(Duration.ofMinutes(sessionTimeout));
server.setSession(session);

server.setContextPath("/midpoint");


if (server instanceof TomcatServletWebServerFactory) {
customizeTomcat((TomcatServletWebServerFactory) server);
}
}

private void customizeTomcat(TomcatServletWebServerFactory tomcatFactory) {
// Tomcat valve used to redirect root URL (/) to real application URL (/midpoint/).
// See comments in TomcatRootValve
Valve rootValve = new TomcatRootValve();
tomcatFactory.addEngineValves(rootValve);
}

@Bean
public ServerProperties serverProperties() {
return new ServerCustomization();
}

private static class ServerCustomization extends ServerProperties {

@Value("${server.session.timeout}")
private int sessionTimeout;

@Override
public void customize(ConfigurableEmbeddedServletContainer container) {
super.customize(container);

container.addErrorPages(new ErrorPage(HttpStatus.UNAUTHORIZED,
"/error/401"));
container.addErrorPages(new ErrorPage(HttpStatus.FORBIDDEN,
"/error/403"));
container.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND,
"/error/404"));
container.addErrorPages(new ErrorPage(HttpStatus.GONE,
"/error/410"));
container.addErrorPages(new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR,
"/error"));

container.setSessionTimeout(sessionTimeout, TimeUnit.MINUTES);

if (container instanceof TomcatEmbeddedServletContainerFactory) {
customizeTomcat((TomcatEmbeddedServletContainerFactory) container);
}
}

private void customizeTomcat(TomcatEmbeddedServletContainerFactory tomcatFactory) {
// Tomcat valve used to redirect root URL (/) to real application URL (/midpoint/).
// See comments in TomcatRootValve
Valve rootValve = new TomcatRootValve();
tomcatFactory.addEngineValves(rootValve);
}
}
}
Expand Up @@ -16,8 +16,8 @@
package com.evolveum.midpoint.web.boot;

import org.apache.catalina.startup.Tomcat;
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer;
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.embedded.tomcat.TomcatWebServer;

import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
Expand All @@ -28,12 +28,13 @@
*
* @author semancik
*/
public class MidPointTomcatEmbeddedServletContainerFactory extends TomcatEmbeddedServletContainerFactory {
public class MidPointTomcatServletWebServerFactory extends TomcatServletWebServerFactory {

private static final Trace LOGGER = TraceManager.getTrace(MidPointTomcatEmbeddedServletContainerFactory.class);
private static final Trace LOGGER = TraceManager.getTrace(MidPointTomcatServletWebServerFactory.class);

@Override
protected TomcatEmbeddedServletContainer getTomcatEmbeddedServletContainer(Tomcat tomcat) {

protected TomcatWebServer getTomcatWebServer(Tomcat tomcat) {

// We are setting up fake context here. This context does not really do anything.
// But it is "mapped" to the root URL (/ ... or rather "" in Tomcat parlance).
Expand All @@ -44,7 +45,7 @@ protected TomcatEmbeddedServletContainer getTomcatEmbeddedServletContainer(Tomca
RootRootContext rootRootContext = new RootRootContext();
tomcat.getHost().addChild(rootRootContext);

return super.getTomcatEmbeddedServletContainer(tomcat);
return super.getTomcatWebServer(tomcat);
}


Expand Down
Expand Up @@ -30,7 +30,6 @@
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.AuthenticationProvider;
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 @@ -43,7 +42,8 @@
*/
@Order(SecurityProperties.BASIC_AUTH_ORDER - 1)
@Configuration
@EnableGlobalMethodSecurity(securedEnabled = true)
//TODO
//@EnableGlobalMethodSecurity(securedEnabled = true)
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

Expand All @@ -56,7 +56,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
private boolean csrfEnabled;
@Value("${auth.logout.url:/}")
private String authLogoutUrl;

@Bean
public WicketLoginUrlAuthenticationEntryPoint wicketAuthenticationEntryPoint() {
return new WicketLoginUrlAuthenticationEntryPoint("/login");
Expand Down
22 changes: 8 additions & 14 deletions gui/admin-gui/src/main/resources/application.yml
@@ -1,35 +1,29 @@
spring:
application:
name: MidPoint

http:
servlet:
multipart:
max-file-size: 100Mb
max-request-size: 100Mb

server:
display-name: MidPoint
contextPath: /midpoint # Spring Boot 1.x
session:
timeout: 15 # in minutes. By default spring uses seconds, but tomcat/container (not embedded) uses this value
# as minutes - so we end up with never expiring session.
tomcat:
basedir: ${midpoint.home}
max-http-post-size: 104857600 # in bytes

servlet:
path: /midpoint # Spring Boot 2.0
context-path: /midpoint
application-display-name: MidPoint
session:
timeout: 15 # in minutes. By default spring uses seconds, but tomcat/container (not embedded) uses this value
# as minutes - so we end up with never expiring session.

auth:
logout:
url: / # NOTE: This URL is relative to application root


#security:
# enable-csrf: false # default for midpoint is true

# more properties with default values can be found here:
# https://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html

logging:
level:
org.springframework: TRACE
# https://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html

0 comments on commit c3b2743

Please sign in to comment.