您好,登錄后才能下訂單哦!
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
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保護禁用 ?*?作者:www.1b23.com ?*/@EnableWebSecuritypublic?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(); ????} }
?
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。