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

Bug - Filter chain not working properly #66

Closed
mianor64 opened this issue Sep 3, 2017 · 3 comments
Closed

Bug - Filter chain not working properly #66

mianor64 opened this issue Sep 3, 2017 · 3 comments
Assignees
Labels
Milestone

Comments

@mianor64
Copy link

mianor64 commented Sep 3, 2017

Summary
Filter chain is not working as expected. In some case I want to set the response directly, for example for authorization (i.e return http code 401), in doFilter method and interrupt the process. But even if the http code of the reponse is correctly set (401), the process is not interrupted. The controller with the URL requested is then called (but should not be). Then you received http 401 with a response as if the request was successful.

Steps to reproduce
From aws-serverless-java-container-master\samples\spring\pet-store, modify LambdaHandler.java to add a filter, named TestFilter which will only set response to http 401 when the doFilter method is called (see in attachments). Call url /pets. You will receive a http response code 401 with a list of pets.

Add the TestFilter class (see in attachments):

public class TestFilter implements Filter {
@OverRide
public void doFilter(final ServletRequest req, final ServletResponse res, final FilterChain chain) throws IOException, ServletException {
if(true) {
((HttpServletResponse) res).setStatus(401);
return;
}
chain.doFilter(req, res);
}

Expected Result
I expected the TestFilter doFilter() to interrupt the process if I return before calling chain.doFilter method and then just receive a http reponse code 401 (without the list of pets)

Actual Result
TestFilter doFilter() is executed, the response is set (http code 401) but the controller is actually called and the list of pets returned.

aws-serverless-spring-bug.zip

@sapessi sapessi added the bug label Sep 5, 2017
@sapessi
Copy link
Collaborator

sapessi commented Sep 5, 2017

Hey @mianor64. This is indeed a bug. The behavior should be fixed by #65. It will go out with the next release.

@sapessi sapessi self-assigned this Sep 5, 2017
sapessi added a commit that referenced this issue Oct 12, 2017
…lt execution. The servlet is injected in the chain by the FilterChainManager. This should fix the last issues with #65 and fix #66
@sapessi
Copy link
Collaborator

sapessi commented Oct 12, 2017

Hey @mianor64, I've committed a fix for this to 0.8-SNAPSHOT in the servlet-improvements branch. I've also added a couple of unit tests for it to the Spark and Spring implementations. If you get a chance, could you help me run a quick test?

@sapessi
Copy link
Collaborator

sapessi commented Nov 21, 2017

Unit tests are all passing. Closing this assuming the fix works.

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

No branches or pull requests

2 participants