charon-spring-boot-starter icon indicating copy to clipboard operation
charon-spring-boot-starter copied to clipboard

ForwardedRequestInterceptor not working as expected

Open mghildiy opened this issue 6 years ago • 5 comments
trafficstars

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?

mghildiy avatar Apr 04 '19 07:04 mghildiy

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.

mkopylec avatar Apr 04 '19 07:04 mkopylec

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

mghildiy avatar Apr 04 '19 07:04 mghildiy

Just check out the readme file

mkopylec avatar Apr 04 '19 07:04 mkopylec

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.

mghildiy avatar Apr 04 '19 09:04 mghildiy

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?

mkopylec avatar Apr 08 '19 16:04 mkopylec