集中式整合之加入springsecurity
生活随笔
收集整理的這篇文章主要介紹了
集中式整合之加入springsecurity
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
創建工程并導入jar包
先只導入SpringBoot
<parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.1.3.RELEASE</version><relativePath/> </parent><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency> </dependencies>提供處理器
@Controller @RequestMapping("/product") public class ProductController {@RequestMapping@ResponseBodypublic String hello(){return "success";} }編寫啟動類
@SpringBootApplication public class SecurityApplication {public static void main(String[] args) {SpringApplication.run(SecurityApplication.class, args);} }測試效果
使用SpringBoot內置tomcat啟動項目,即可訪問處理器。
加入SpringSecurity的jar包
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-security</artifactId> </dependency>重啟再次測試
SpringBoot已經為SpringSecurity提供了默認配置,默認所有資源都必須認證通過才能訪問。
那么問題來了!此刻并沒有連接數據庫,也并未在內存中指定認證用戶,如何認證呢?
其實SpringBoot已經提供了默認用戶名user,密碼在項目啟動時隨機生成,如圖:
認證通過后可以繼續訪問處理器資源:
總結
以上是生活随笔為你收集整理的集中式整合之加入springsecurity的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: SpringSecurity权限控制之异
- 下一篇: SpringSecurity集中式整合之