RBAC权限控制初步实现
This commit is contained in:
parent
97b22ee98a
commit
f8d2002b8a
@ -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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user