springboot專案整合shiro

2021-09-29 04:09:00 字數 2236 閱讀 3522

pom.xml配置檔案中,新增shiro

org.apache.shiro

shiro-spring-boot-web-starter

1.4.0

com.github.theborakompanioni

thymeleaf-extras-shiro

2.0.0

org.springframework.boot

spring-boot-starter-thymeleaf

第一:開啟shiro配置,預設true

第二:開啟shiro web配置,預設true

第三:登入位址

第四:登入成功位址,預設為/

第五:未獲取授權預設跳轉位址

第六:是否允許通過url引數實現會話跟蹤,預設true

第七:是否允許通過cookie實現會話跟蹤,預設true

建立config目錄,shiroconfig,webmvcconfig,exceptioncontroller,usercontroller

shiroconfig

這裡提供兩個bean,realm配置兩個使用者,sang/123,admin/123,分別對應角色user和admin,user有read許可權,admin有read,write許可權

@configuration

public class shiroconfig

@bean

public shirofilterchaindefinition shirofilterchaindefinition()

@bean

public shirodialect shirodialect()

}

webmvcconfig

對於其他不需要角色就可以訪問的介面,直接在webmvc中配置即可

@configuration

public class webmvcconfig implements webmvcconfigurer

}

exceptioncontroller

@controlleradvice

public class exceptioncontroller

}

usercontroller

@controller

public class usercontroller catch (authenticationexception e)

return "redirect:/index";

}@requiresroles("admin")

public string admin()

@requiresroles(value = ,logical = logical.or)

public string user()

}

templates目錄下建立以下html

訪問localhost:8080/index

測試

springboot專案整合vue

由於特殊原因,所以臨危受命將vue整合到springboot的專案中,終於在忙活了一天之後成功搞定,下面就分享一下這次的整合過程 1建立springboot和vue專案 springboot以及vue專案都已經由前後端同事分別開發完成,這裡就不介紹具體的建立過程了 2.打包vue專案 vue使用了v...

SpringBoot專案整合Swagger2

swagger 是最流行的 api 開發工具,它遵循 openapi specification openapi 規範,也簡稱 oas swagger 可以貫穿於整個 api 生態,如 api 的設計 編寫 api 文件 測試和部署。swagger 是一種通用的,和程式語言無關的 api 描述規範。...

SpringBoot專案整合Swagger UI

參考文章 mybatis plus自動生成實體類 包含swagger註解 因為1中是mybatis的 生成器,另外找了mybatis plus的 在pom.xml中新增依賴 配置swaggerconfig檔案 configuration 配置 enableswagger2 開啟swagger pub...