玩转SpringBoot安全管理第三期来喽💨
前两期传送门:
💫玩转SpringBoot安全管理:SpringSecurity介绍及入门、自定义用户认证及授权管理、MVC Security安全配置介绍(内存和JDBC身份认证实现)
💫玩转SpringBoot安全管理:SpringSecurity之UserDetailService身份认证
资源也在前两期里有链接🔗
依旧回到WebSecurityConfigurerAdapter类当中,这次我们需要实现它的configure(HttpSecurity http)方法,在这个方法中我们实现用户访问控制
在开始之前呢,我们要把templates下的index.html页面改成下面的页面:
其实也就是把sec:authorize="hasRole(‘common’)"和sec:authorize="hasAuthority(‘ROLE_vip’)"给注释掉了,现在已经不需要用到他了,我们要自定义访问控制路径
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity5">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>影视直播厅</title>
</head>
<body>
<h1 align="center">欢迎进入电影网站首页</h1>
<div sec:authorize="isAnonymous()">
<h2 align="center">游客您好,如果想查看电影<a th:href="@{/userLogin}">请登录</a></h2>