RBAC权限控制初步实现

This commit is contained in:
myh 2023-11-06 16:56:37 +08:00
parent 97b22ee98a
commit f8d2002b8a

View File

@ -0,0 +1,23 @@
package com.example.springdemo.utils;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;
import org.jetbrains.annotations.NotNull;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
@Component
public class PermissionInterceptor implements HandlerInterceptor {
@Override
public boolean preHandle(@NotNull HttpServletRequest request,
@NotNull HttpServletResponse response,
@NotNull Object handler) throws Exception {
HttpSession session = request.getSession();
if (session.getAttribute("users") == null) {
response.sendRedirect("/login");
return false;
}
return true;
}
}