0

I am trying to use a HttpServletRequestWrapper implementation in a Grails 3 project. I have an implementation of the wrapper but i am not sure on how to hook it in into the project. Any hints on how to do this?

The implementation if the HttpServletRequestWrapper:

public class AuthenticationRequestWrapper extends HttpServletRequestWrapper {
    public AuthenticationRequestWrapper(HttpServletRequest request) {
        super(request);
    }
    ... code omitted intentionally
}
Marco
  • 15,101
  • 33
  • 107
  • 174
  • What are you trying to do with it? I'm not sure how to wire it in without changing some of the grails code (I haven't looked at that part), but perhaps if you describe what you're trying to do there might be another way? Is this a custom authenticator? – BZ. Jul 07 '16 at 17:54
  • I want to use the request body in a HMAC calculation. The request body can only be read once and doing the HMAC calculation in an interceptor breaks everything. The stream is alread read by the interceptor. So i was trying to wrap it by using ServletRequestWrapper – Marco Jul 07 '16 at 18:23
  • You would do this in a Servlet Filter, passing the wrapped request to the `chain()` call instead of the current one, but in Grails 3 there's a bug (https://github.com/grails/grails-core/issues/9924) that's been marked as Won't Fix where a wrapped request or response from a filter is ignored, so I'm not sure if this is possible. – Burt Beckwith Jul 07 '16 at 18:56
  • @BurtBeckwith Seeing what i want to do, so calculating an HMAC including the request body. Would there be another solution to achieve this without breaking the request handling from Grails? – Marco Jul 07 '16 at 19:47
  • You can do what I did in spring-security-core as a workaround for the bug, replacing the GrailsWebRequest with one that uses the filter's request and response but otherwise delegates to the existing instance: https://github.com/grails-plugins/grails-spring-security-core/blob/master/src/main/groovy/grails/plugin/springsecurity/web/UpdateRequestContextHolderExceptionTranslationFilter.groovy (skip the exception translation stuff and just use the logic in `doFilter()` combined with your wrapper) – Burt Beckwith Jul 07 '16 at 21:03

0 Answers0