DisableIdTokenResponseTypeFilter extends OncePerRequestFilter { @Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { logger.debug("Processing id_token disable filter"); HttpServletRequest requestWrapper = request; logger.debug(String.format("pre id_token disable:%s pathinfo:%s request_uri:%s response_type:%s",isIdTokenDisabled(), requestWrapper.getPathInfo(), request.getRequestURI() ,requestWrapper.getParameter(RESPONSE_TYPE))); if (isIdTokenDisabled() && (applyPath(request.getPathInfo()) || applyPath(request.getRequestURI()))) { requestWrapper = new RemoveIdTokenParameterValueWrapper(request); } logger.debug(String.format("post id_token disable:%s pathinfo:%s request_uri:%s response_type:%s",isIdTokenDisabled(), requestWrapper.getPathInfo(), request.getRequestURI() ,requestWrapper.getParameter(RESPONSE_TYPE))); filterChain.doFilter(requestWrapper, response); } DisableIdTokenResponseTypeFilter(boolean active, List<String> paths); boolean isIdTokenDisabled(); void setIdTokenDisabled(boolean disabled); static final String ID_TOKEN; }
@Test public void testDoFilterInternal_NO_Response_Type_Parameter() throws Exception { filter.doFilterInternal(request, response, chain); verify(chain).doFilter(captor.capture(), any()); assertSame(request, captor.getValue()); reset(chain); disabledFilter.doFilterInternal(request, response, chain); verify(chain).doFilter(captor.capture(), any()); assertNotSame(request, captor.getValue()); }
@Test public void testDoFilterInternal_Code_Response_Type_Parameter() throws Exception { String responseType = "code"; request.addParameter(RESPONSE_TYPE, responseType); filter.doFilterInternal(request, response, chain); verify(chain).doFilter(captor.capture(), any()); assertSame(request, captor.getValue()); reset(chain); assertEquals(responseType, captor.getValue().getParameter(RESPONSE_TYPE)); assertEquals(1, captor.getValue().getParameterMap().get(RESPONSE_TYPE).length); assertEquals(responseType, captor.getValue().getParameterMap().get(RESPONSE_TYPE)[0]); assertEquals(1, captor.getValue().getParameterValues(RESPONSE_TYPE).length); assertEquals(responseType, captor.getValue().getParameterValues(RESPONSE_TYPE)[0]); disabledFilter.doFilterInternal(request, response, chain); verify(chain).doFilter(captor.capture(), any()); assertNotSame(request, captor.getValue()); assertEquals(responseType, captor.getValue().getParameter(RESPONSE_TYPE)); assertEquals(1, captor.getValue().getParameterMap().get(RESPONSE_TYPE).length); assertEquals(responseType, captor.getValue().getParameterMap().get(RESPONSE_TYPE)[0]); assertEquals(1, captor.getValue().getParameterValues(RESPONSE_TYPE).length); assertEquals(responseType, captor.getValue().getParameterValues(RESPONSE_TYPE)[0]); }