我正在根据https://codecentric.github.io/spring-boot-admin/2.0.2文档进行开发,但是我没有在安全的应用程序中注册客户端。
我的配置是:
application.yml
# Security config
spring.security.user:
name: admin
password: admin
# Actuator config
management:
endpoint:
shutdown.enabled: true
health.show-details: always
endpoints.web.exposure.include: '*'
# Spring boot admin config
spring.boot.admin:
context-path: /admin
client:
url: http://localhost:8080/admin
username: ${spring.security.user.name}
password: ${spring.security.user.password}
instance:
name: ${app.name}
metadata.user:
name: ${spring.security.user.name}
password: ${spring.security.user.password}
WebSecurityConfiguration
@Configuration
public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter {
private final String adminContextPath;
public WebSecurityConfiguration(AdminServerProperties adminServerProperties) {
this.adminContextPath = adminServerProperties.getContextPath();
}
@Override
protected void configure(HttpSecurity http) throws Exception {
SavedRequestAwareAuthenticationSuccessHandler successHandler = new SavedRequestAwareAuthenticationSuccessHandler();
successHandler.setTargetUrlParameter("redirectTo");
successHandler.setDefaultTargetUrl(adminContextPath + "/");
http.authorizeRequests()
.antMatchers(adminContextPath + "/assets/**").permitAll()
.antMatchers(adminContextPath + "/login").permitAll()
.anyRequest().authenticated()
.and()
.formLogin().loginPage(adminContextPath + "/login").successHandler(successHandler).and()
.logout().logoutUrl(adminContextPath + "/logout").and()
.httpBasic().and()
.csrf()
.csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse())
.ignoringAntMatchers("/instances", "/actuator/**");
}
}
发生错误:
2018-08-22 00:44:21.770 DEBUG 9616 --- [gistrationTask1] d.c.b.a.c.r.ApplicationRegistrator: Failed to register application as Application(name=template-api, managementUrl=http://localhost:8080/actuator, healthUrl=http://localhost:8080/actuator/health, serviceUrl=http://localhost:8080/) at spring-boot-admin ([http://localhost:8080/admin/instances]): 401 null
有人可以为此401
提供帮助吗?
更新日期2018-09-01:
我尝试了单独的配置,并且发生了相同的错误:
服务器:
# Security config
spring.security.user:
name: test-name
password: test-password
# Spring boot admin config
spring.boot.admin:
context-path: /admin
客户:
# Spring boot admin config
spring.boot.admin:
client:
url: http://localhost:8080/admin
username: test-name
password: test-password
instance:
name: ${app.name}
metadata.user:
name: test-name
password: test-password
答案 0 :(得分:0)
401未经授权的错误是HTTP状态代码,表示您尝试访问的页面只有先使用有效的用户ID和密码登录才能加载。您是否正确配置了客户端和管理服务器?
您可以在这里查看我的服务器和客户端spring boot应用程序的示例源代码,其中包含和不包含安全性配置。
https://github.com/anandvarkeyphilips/spring-boot-admin/tree/master/spring-boot-admin-samples
答案 1 :(得分:0)
Spring Boot Admin文档中存在一个错误。它是固定的。