Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于【springboot-security-oauth2 】项目的拦截器问题 #7

Open
LiHuiNeng opened this issue Apr 23, 2020 · 1 comment
Open

Comments

@LiHuiNeng
Copy link

下载demo,运行跑完之后发现有一个问题,想请教一下。
1.带上token请求,执行到MyFilterSecurityInterceptor的doFilter方法。
HelloController控制器会先执行一次返回,得到正确结果。
image

2.之后该链路会继续调用,然后又再次返回到HelloController控制器,又得到一次返回。
image
image
请教:如果只想得到一次返回结果该如何做呢?
谢谢!

@musicguoke
Copy link

musicguoke commented Jul 6, 2022

@LiHuiNeng hi,Here's how I solved it.

@Override
   public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
       HttpServletRequest request = (HttpServletRequest) servletRequest;
       if (!request.getRequestURI().equals("/oauth/token")) {
           FilterInvocation fi = new FilterInvocation(servletRequest, servletResponse, filterChain);
           invoke(fi);
       } else {
           HttpServletResponse response = (HttpServletResponse) servletResponse;
           response.setHeader("Access-Control-Allow-Origin", "*");
           response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE");
           response.setHeader("Access-Control-Allow-Headers", ":x-requested-with,content-type");
           filterChain.doFilter(servletRequest, servletResponse);
       }
   }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants