1.?pom.xml 加入依賴
在侯馬等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強發(fā)展的系統(tǒng)性、市場前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務(wù)理念,為客戶提供成都做網(wǎng)站、成都網(wǎng)站建設(shè)、成都外貿(mào)網(wǎng)站建設(shè) 網(wǎng)站設(shè)計制作按需網(wǎng)站制作,公司網(wǎng)站建設(shè),企業(yè)網(wǎng)站建設(shè),品牌網(wǎng)站建設(shè),營銷型網(wǎng)站,成都外貿(mào)網(wǎng)站制作,侯馬網(wǎng)站建設(shè)費用合理。
???????????? org.springframework.boot ????????????spring-boot-starter-security ????????
2.?application.properties 配置如下 用戶名和密碼
#開啟安全認(rèn)證?用戶名和密碼 spring.security.basic.enabled=true spring.security.user.name=fh_admin spring.security.user.password=root
3. 加入配置類?WebSecurityConfig.java
package?org.fh.config; import?org.springframework.security.config.annotation.web.builders.HttpSecurity; import?org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import?org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; import?org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler; /** ?*?說明:CSRF保護(hù)禁用 ?*?作者:F-H?Admin ?*?官網(wǎng):www.1b23.com ?*/ @EnableWebSecurity public?class?WebSecurityConfig?extends?WebSecurityConfigurerAdapter?{ ????@Override ????protected?void?configure(HttpSecurity?http)?throws?Exception?{ ???? ???? SavedRequestAwareAuthenticationSuccessHandler?successHandler?=?new?SavedRequestAwareAuthenticationSuccessHandler(); successHandler.setTargetUrlParameter("redirectTo"); http.headers().frameOptions().disable(); ???? ???? http.csrf().disable().authorizeRequests().antMatchers("/actuator/**").permitAll().anyRequest().authenticated().and().httpBasic(); ????} }