如何在eureka配置用户名和密码
1.pom.xml 加入依赖
<!--加入密码认证--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-security</artifactId></dependency>
2.application.properties 配置如下 用户名和密码
#开启安全认证用户名和密码spring.security.basic.enabled=truespring.security.user.name=adminspring.security.user.password=root
3. 加入配置类WebSecurityConfig.java
packageorg.fh.config;importorg.springframework.security.config.annotation.web.builders.HttpSecurity;importorg.springframework.security.config.annotation.web.configuration.EnableWebSecurity;importorg.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;importorg.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler;/***/@EnableWebSecuritypublicclassWebSecurityConfigextendsWebSecurityConfigurerAdapter{@Overrideprotectedvoidconfigure(HttpSecurityhttp)throwsException{SavedRequestAwareAuthenticationSuccessHandlersuccessHandler=newSavedRequestAwareAuthenticationSuccessHandler();successHandler.setTargetUrlParameter("redirectTo");http.headers().frameOptions().disable();http.csrf().disable().authorizeRequests().antMatchers("/actuator/**").permitAll().anyRequest().authenticated().and().httpBasic();}}
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。