/*
 * @Author: Kane
 * @Date: 2023-01-29 10:50:49
 * @LastEditors: Kane
 * @LastEditTime: 2023-02-04 18:05:18
 * @FilePath: /后端-需求/src/main/java/com/cpic/xim/web/filters/token/TokenFilter.java
 * @Description: 
 * 
 * Copyright (c) ${2022} by Kane, All Rights Reserved. 
 */
package com.cpic.xim.web.filters.token;

import java.io.IOException;
import java.util.Enumeration;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@SuppressWarnings( "unused" )
public class TokenFilter implements Filter
{
    private static final String FILTE_METHODS = "POST,GET";

    @Override
    public void doFilter( ServletRequest req, ServletResponse resp, FilterChain chain )
            throws ServletException, IOException
    {
        HttpServletRequest request = (HttpServletRequest) req;
        HttpServletResponse response = (HttpServletResponse) resp;

        String method = request.getMethod().toUpperCase();

        // 只处理POST和GET
        if ( FILTE_METHODS.indexOf( method ) != -1 )
        {
            // 检查token
            String token = request.getHeader( "token" );
        }

        chain.doFilter( request, response );
    }
}
