mkopylec / charon-spring-boot-starter

Reverse proxy implementation in form of a Spring Boot starter.
Apache License 2.0
240 stars 54 forks source link

ForwardedRequestInterceptor not working as expected #80

Open mghildiy opened 5 years ago

mghildiy commented 5 years ago

In my maven application, I have implemented ForwardedRequestInterceptor.intercept() as:

requestData.setUri("error/403");

403.html is location at:

\src\main\resources\templates\error\403.html

Instead of 403.html, I get following:

{"statusCode":404,"error":"Not Found","message":"Not Found"}

How to ensure that 403.html is displayed?

mkopylec commented 5 years ago

Please provide more details about how you have configured Charon. What is the destination hostname? Probably your destination server does not provide an error page on /error/403 url, that's why you are getting 404 error.

mghildiy commented 5 years ago

Can you provide some links on how to configure Charon? Currently I don't see any Charon specific configuration in the application.

mkopylec commented 5 years ago

Just check out the readme file

mghildiy commented 5 years ago

So I studied my application a bit more. Here is the situation:

I have some LDAP based user validations. If validation is successful, I redirect the request to another server whose response then I intercept using ReceivedResponseInterceptor and perform some actions of my own. MappingsProvider is extended for it. It works fine.

But if LDAP validations fails, I simply need to display error html page which resides in current server, ie no redirection to another server. To do this I have done what I posted in my original post. So my understanding is that no mappings are needed for it. But it doesn't work.

mkopylec commented 5 years ago

I see your problem now. The ForwardedRequestInterceptor is invoked to late, after the mapping is already chosen. Currently the only way you can achieve your goal is to implement ReceivedResponseInterceptor and change the response to HTTP 301 with Location header set to"/error/403". Is that solution enough for you?