Skip to content

Commit

Permalink
Fix tests failing due to spring-framework#25981
Browse files Browse the repository at this point in the history
  • Loading branch information
joshiste committed Nov 18, 2020
1 parent b43086d commit d2b765b
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -88,8 +86,10 @@ public List<UiExtension> getJsExtensions() {
return this.uiExtensions.getJsExtensions();
}

// FIXME: add @Nullable to principal parameter
// see https://github.com/spring-projects/spring-framework/issues/25981
@ModelAttribute(value = "user", binding = false)
public Map<String, Object> getUser(@Nullable Principal principal) {
public Map<String, Object> getUser(Principal principal) {
if (principal != null) {
return singletonMap("name", principal.getName());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}

}

0 comments on commit d2b765b

Please sign in to comment.