From 57d721194cb3bd2482654beba52d8486d2d63e63 Mon Sep 17 00:00:00 2001 From: Johannes Edmeier Date: Wed, 18 Nov 2020 09:01:52 +0100 Subject: [PATCH] Fix tests failing due to spring-framework#25981 --- .../admin/server/ui/web/UiController.java | 8 +++++--- .../ui/AdminUiServletApplicationTest.java | 2 +- .../admin/server/ui/web/UiControllerTest.java | 20 +------------------ 3 files changed, 7 insertions(+), 23 deletions(-) diff --git a/spring-boot-admin-server-ui/src/main/java/de/codecentric/boot/admin/server/ui/web/UiController.java b/spring-boot-admin-server-ui/src/main/java/de/codecentric/boot/admin/server/ui/web/UiController.java index 1feb57e0658..4d9f2032f3c 100644 --- a/spring-boot-admin-server-ui/src/main/java/de/codecentric/boot/admin/server/ui/web/UiController.java +++ b/spring-boot-admin-server-ui/src/main/java/de/codecentric/boot/admin/server/ui/web/UiController.java @@ -20,8 +20,6 @@ import java.util.List; import java.util.Map; -import javax.annotation.Nullable; - import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; import org.springframework.boot.context.properties.ConstructorBinding; @@ -89,7 +87,11 @@ public List getJsExtensions() { } @ModelAttribute(value = "user", binding = false) - public Map getUser(@Nullable Principal principal) { + public Map getUser( + /* + * @Nullable FIXME: + * https://github.com/spring-projects/spring-framework/issues/25981 + */ Principal principal) { if (principal != null) { return singletonMap("name", principal.getName()); } diff --git a/spring-boot-admin-server-ui/src/test/java/de/codecentric/boot/admin/server/ui/AdminUiServletApplicationTest.java b/spring-boot-admin-server-ui/src/test/java/de/codecentric/boot/admin/server/ui/AdminUiServletApplicationTest.java index f86948ab154..f157625a652 100644 --- a/spring-boot-admin-server-ui/src/test/java/de/codecentric/boot/admin/server/ui/AdminUiServletApplicationTest.java +++ b/spring-boot-admin-server-ui/src/test/java/de/codecentric/boot/admin/server/ui/AdminUiServletApplicationTest.java @@ -59,7 +59,7 @@ public static class SecurityConfiguration extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { http.authorizeRequests().anyRequest().permitAll()// - .and().csrf().disable(); + .and().csrf().disable().anonymous().principal("anonymousUser"); } } diff --git a/spring-boot-admin-server-ui/src/test/java/de/codecentric/boot/admin/server/ui/web/UiControllerTest.java b/spring-boot-admin-server-ui/src/test/java/de/codecentric/boot/admin/server/ui/web/UiControllerTest.java index 116cd6e4e0f..efba4625296 100644 --- a/spring-boot-admin-server-ui/src/test/java/de/codecentric/boot/admin/server/ui/web/UiControllerTest.java +++ b/spring-boot-admin-server-ui/src/test/java/de/codecentric/boot/admin/server/ui/web/UiControllerTest.java @@ -16,16 +16,9 @@ package de.codecentric.boot.admin.server.ui.web; -import java.security.Principal; - import org.junit.jupiter.api.Test; -import org.springframework.core.MethodParameter; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.setup.MockMvcBuilders; -import org.springframework.web.bind.support.WebDataBinderFactory; -import org.springframework.web.context.request.NativeWebRequest; -import org.springframework.web.method.support.HandlerMethodArgumentResolver; -import org.springframework.web.method.support.ModelAndViewContainer; import de.codecentric.boot.admin.server.ui.extensions.UiExtensions; import de.codecentric.boot.admin.server.web.servlet.AdminControllerHandlerMapping; @@ -73,18 +66,7 @@ private MockMvc setupController(String publicUrl) { return MockMvcBuilders .standaloneSetup( new UiController(publicUrl, UiExtensions.EMPTY, UiController.Settings.builder().build())) - .setCustomArgumentResolvers(new HandlerMethodArgumentResolver() { - @Override - public boolean supportsParameter(MethodParameter parameter) { - return parameter.getParameterType().equals(Principal.class); - } - - @Override - public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, - NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception { - return null; - } - }).setCustomHandlerMapping(() -> new AdminControllerHandlerMapping("")).build(); + .setCustomHandlerMapping(() -> new AdminControllerHandlerMapping("")).build(); } }