class PermissionFilter extends OncePerRequestFilter {

    /**
     * 是否开启权限管理
     */
    @Value("${sonic.permission.enable}")
    private boolean permissionEnable;
    /**
     * 内置超管账号
     */
    @Value("${sonic.permission.superAdmin}")
    private String superAdmin;

    @Autowired
    private JWTTokenTool jwtTokenTool;

    @Autowired
    private RolesServices rolesServices;

    @Autowired
    private ResourcesService resourcesService;

    public static final String TOKEN = "SonicToken";

    @Resource
    private MessageSource messageSource;

    @Override
    protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {<FILL_FUNCTION_BODY>}


    private RespModel process(HttpServletRequest request, RespModel respModel) {
        String l = request.getHeader("Accept-Language");
        CommonResultControllerAdvice.process(l, respModel, messageSource);

        return respModel;
    }


}

        if (request.getRequestURL().toString().contains("swagger")) {
            filterChain.doFilter(request, response);
            return;
        }

        String token = request.getHeader(TOKEN);

        if (permissionEnable && token != null && !request.getMethod().equalsIgnoreCase("options")) {
            String userName = jwtTokenTool.getUserName(token);

            if (Objects.equals(superAdmin, userName)) {
                filterChain.doFilter(request, response);
                return;
            }

            String resourceName = request.getServletPath();
            String method = request.getMethod();
            log.info("PermissionFilter: {}", resourceName);

            Resources resources = resourcesService.search(resourceName, method);

            if (resources == null) {
                response.setContentType("text/plain;charset=UTF-8");
                JSONObject re = (JSONObject) JSONObject.toJSON(process(request, new RespModel(RespEnum.RESOURCE_NOT_FOUND)));
                response.getWriter().write(re.toJSONString());
                return;
            }

            if (resources.getWhite() == UrlType.WHITE || resources.getNeedAuth() == UrlType.WHITE) {
                filterChain.doFilter(request, response);
                return;
            }

            if (!rolesServices.checkUserHasResourceAuthorize(userName, resourceName, method)) {
                response.setContentType("text/plain;charset=UTF-8");
                JSONObject re = (JSONObject) JSONObject.toJSON(process(request, new RespModel(RespEnum.PERMISSION_DENIED)));
                response.getWriter().write(re.toJSONString());
                return;
            }
        }

        filterChain.doFilter(request, response);
    
<methods>public void <init>() ,public final void doFilter(jakarta.servlet.ServletRequest, jakarta.servlet.ServletResponse, jakarta.servlet.FilterChain) throws jakarta.servlet.ServletException, java.io.IOException<variables>public static final java.lang.String ALREADY_FILTERED_SUFFIX