无法在Spring Boot Admin中更改日志级别

时间:2019-10-07 07:01:42

标签: java spring spring-boot spring-security spring-boot-admin

我正在尝试使用Spring Boot Admin在Spring Boot应用程序中在运行时更改日志级别,但是我在浏览器控制台中得到了401并且日志级别也未更改。

我所做的工作是创建一个springadmin应用程序和一个名为SpringBootClient的客户端,管理员将在运行时更改客户端的日志级别。当我登录springadmin应用程序并提供指定的用户名和密码时,我登录了springadmin应用程序,在那里我可以看到我的客户端为UP,但是当我进行更改时它在“日志记录器”标签中的日志,我看到诸如配置WARN失败之类的消息,当我检查浏览器控制台时,它向POST发出了http://localhost:8080/instances/8723817f5b45/actuator/loggers/com.muktadirkhan请求,并给出了{{1 }}。

这是我的401应用程序的application.properties

springadmin

spring.security.user.name=admin spring.security.user.password=admin management.endpoints.web.exposure.include=httptrace,loggers,health,info,metrics spring.boot.admin.routes.endpoints=env, metrics, trace, jolokia, info, configprops 像这样:

springadminApplication.java

我还在package com.muktadirkhan.springboot; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.Configuration; import de.codecentric.boot.admin.server.config.EnableAdminServer; @EnableAdminServer @Configuration @SpringBootApplication public class SpringadminApplication { public static void main(String[] args) { SpringApplication.run(SpringadminApplication.class, args); } } 应用程序中创建了一个WebSecurityConfig.java,如下所示:

springadmin

关于客户,我的package com.muktadirkhan.springboot; import org.springframework.context.annotation.Configuration; import org.springframework.http.HttpMethod; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler; import org.springframework.security.web.csrf.CookieCsrfTokenRepository; import org.springframework.security.web.util.matcher.AntPathRequestMatcher; import de.codecentric.boot.admin.server.config.AdminServerProperties; import de.codecentric.boot.admin.server.web.PathUtils; import java.util.*; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.convert.DurationUnit; @Configuration public class WebSecurityConfig extends WebSecurityConfigurerAdapter { private final AdminServerProperties adminServer; public WebSecurityConfig(AdminServerProperties adminServer) { this.adminServer = adminServer; } @Override protected void configure(HttpSecurity http) throws Exception { SavedRequestAwareAuthenticationSuccessHandler successHandler = new SavedRequestAwareAuthenticationSuccessHandler(); successHandler.setTargetUrlParameter("redirectTo"); successHandler.setDefaultTargetUrl(this.adminServer.getContextPath() + "/"); http .authorizeRequests() .antMatchers(this.adminServer.getContextPath() + "/assets/**").permitAll() .antMatchers(this.adminServer.getContextPath() + "/login").permitAll() .anyRequest().authenticated() .and() .formLogin() .loginPage(this.adminServer.getContextPath() + "/login") .successHandler(successHandler) .and() .logout() .logoutUrl(this.adminServer.getContextPath() + "/logout") .and() .httpBasic() .and() .csrf() .csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse()) .ignoringRequestMatchers( new AntPathRequestMatcher(this.adminServer.getContextPath() + "/instances", HttpMethod.POST.toString()), new AntPathRequestMatcher(this.adminServer.getContextPath() + "/instances/*", HttpMethod.DELETE.toString()), new AntPathRequestMatcher(this.adminServer.getContextPath() + "/actuator/**")) .and() .rememberMe() .key(UUID.randomUUID().toString()) .tokenValiditySeconds(1209600); } } 是:

SpringBootClientApplication.java

客户端的package com.muktadirkhan.springboot; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class SpringBootClientApplication { public static void main(String[] args) { SpringApplication.run(SpringBootClientApplication.class, args); } }

application.properties

1 个答案:

答案 0 :(得分:0)

您的客户端上可能具有适用于此终端公开的执行器端点的csrf安全设置,因此不允许spring boot管理服务器执行任何POST请求