springboot security 权限不足_springBoot整合springSecurity(零一)
整體結構===》》》
1,springboot2.0整合springSecurity5.1.1
2,mysql--->>InnoDB
3,持久層我用的是用MybatiysPlus(這里就不寫關于這個的了,基本是查)
4,web服務不是jar服務
5,數據庫表=》賬戶表/角色表/權限表/賬戶角色關聯表/角色權限關聯表
6,需要說一下的是角色表,給框架返回的角色碼需要以ROLE_開頭,
例如;
實現功能:
spring boot整合security
1,基于內存賬戶登陸
2,自定義數據庫賬戶角色權限登陸
3,結合security推薦加密賬戶密碼
4,自定義捕獲無權限訪問異常信息
5,控制session會話并捕獲超時異常
二:===================================================
去年寫過關于這兩個框架的東西,但現在回頭看以前寫的純粹是廢紙一張,不知道有沒有誤人子弟;
========================pom.xml==========================
<====================application.yml=========================
#action YAML配置式 logging:level:org.springframework: INFOcom.example: DEBUG #服務端口 server:port: 8080servlet:session:#spring boot升級后必須要加時間標識秒timeout:10s spring: datasource: url: jdbc:mysql://127.0.0.1:3306/databaseName?useUnicode=true&characterEncoding=UTF-8&useSSL=falseusername: rootpassword: 172575 driverClassName : com.mysql.jdbc.Driverthymeleaf:prefix : classpath:/templates/ #掃描文件路徑suffix : .html #文件格式cache : false #關閉緩存encoding: UTF-8 #編碼格式#content-type:text/html #加載網頁內容 mode: HTML5 mybatis:mapperlocations : classpath:mapper/*.xmltypealiasespackage : springSecurity.enity===================Application.java==========================
package===================SecurityConfig.java========================
package========================SecurityService=====================
package========================ExceptionSecurity.java=================
package========================WebContorller.java===================
package springSecurity;import java.util.UUID; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import springSecurity.dto.SysRole; import springSecurity.dto.SysUser; import springSecurity.service.SysRoleService; import springSecurity.service.SysUseraccount;/*** @author Administrator zpy 20181110*/ @Controller public class WebContorller {private static Logger logger = LoggerFactory.getLogger(WebContorller.class);@AutowiredSysUseraccount sysUserService;@AutowiredSysRoleService sysRoleService;// 默認轉向登陸@RequestMapping("/")public String loading() {return "login";}// login action@RequestMapping(value = "/login")public String userLogin() {return "login";}// 進入主菜單@RequestMapping(value = "/index")public String index() {return "index";}//權限不足拒絕頁面@RequestMapping("/403")public String Noloading() {return "403";}//session超時去往超時頁面@RequestMapping("timeOut")public String timeOut() {return "timeOut";}}HTML頁面不太會寫,可以自己寫幾個簡單的html對應contorller的跳轉地址就成;
結語:
那幾個不太重要的service就不寫了,基本就是根據賬號查賬戶表信息,然后根據賬戶表的編號查角色賬戶關聯表,得到角色信息,然后根據角色信息返回給扽路賬戶進行正常訪問請求;
啟動以后,直接訪問htp://127.0.0.1:8080即可
總結
以上是生活随笔為你收集整理的springboot security 权限不足_springBoot整合springSecurity(零一)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 软件推荐:17 款必备Chrome浏览
- 下一篇: easy2game使用教程_Easy2g