In the Spring-boot-admin (SBA) monitoring side, in order to prevent unauthorized access, the general need to do access control. With a few simple steps, you can configure the spring security to control access to the SBA. 1, the introduction of dependence:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId> Spring-boot-starter-security</artifactid>
</dependency>
2. Configuration:
@Configuration @EnableWebSecurity public class Websecurityconfig extends Websecurityconfigureradapter {@Value ("${
Spring.profiles} ") Private String env; @Override protected void Configure (Httpsecurity http) throws Exception {/*if ("dev". Equals (env)) {//If you need to be in the development service to avoid logging in to HT
Tp.authorizerequests (). Antmatchers ("*//**", "*//**//*filters"). Permitall ();
HTTP.CSRF (). disable ();
Http.httpbasic ();
Return }*/http. Formlogin (). LoginPage ("/login.html"). Loginprocessingurl ("/login"). Permitall ()-logout (). Lo Gouturl ("/logout"). and (). Authorizerequests (). Antmatchers ("/login.html", "/**/*.css", "/img/**", "/api/**")
Release "/api/**": in order to be monitored by the end of login registration. Permitall (). and (). Authorizerequests (). Antmatchers ("/**"). authenticated ();
HTTP.CSRF (). disable ();
Http.httpbasic (); /* @Autowired///can also configure the login account password in the Application.yml file: Security.user.name/password public void Configureglobal ( Authenticationmanagerbuilder auth) throws Exception {auth. inmemoryAuthentication (). Withuser ("Svcadmin"). Password ("PW"). Roles ("USER"); }*/
}
APPLICATION.YML:
Security:
User:
name:sba
password:passwd
3, Login page: