@Test void doFilter() throws IOException, ServletException { SecurityContextHolder.clearContext(); when(request.getHeader("Authorization")).thenReturn("Bearer bearerToken"); when(ledgersUserMgmt.validate(anyString())).thenReturn(ResponseEntity.ok(getBearer())); filter.doFilter(request, response, chain); verify(ledgersUserMgmt, times(1)).validate(anyString()); verify(chain, times(1)).doFilter(any(), any()); }
@Override public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) servletRequest; HttpServletResponse response = (HttpServletResponse) servletResponse; String bearerToken = resolveBearerToken(request); if (StringUtils.isBlank(bearerToken)) { chain.doFilter(request, response); return; } if (authenticationIsRequired()) { try { authInterceptor.setAccessToken(bearerToken); ResponseEntity<BearerTokenTO> validateResponse = ledgersUserMgmt.validate(bearerToken); BearerTokenTO token = Optional.ofNullable(validateResponse.getBody()) .orElseThrow(() -> new RestException("Couldn't get bearer token")); fillSecurityContext(token); } catch (FeignException | RestException e) { handleAuthenticationFailure(response, e); return; } } chain.doFilter(request, response); }
TokenAuthenticationFilter extends AbstractAuthFilter { @Override public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) servletRequest; HttpServletResponse response = (HttpServletResponse) servletResponse; String bearerToken = resolveBearerToken(request); if (StringUtils.isBlank(bearerToken)) { chain.doFilter(request, response); return; } if (authenticationIsRequired()) { try { authInterceptor.setAccessToken(bearerToken); ResponseEntity<BearerTokenTO> validateResponse = ledgersUserMgmt.validate(bearerToken); BearerTokenTO token = Optional.ofNullable(validateResponse.getBody()) .orElseThrow(() -> new RestException("Couldn't get bearer token")); fillSecurityContext(token); } catch (FeignException | RestException e) { handleAuthenticationFailure(response, e); return; } } chain.doFilter(request, response); } }
TokenAuthenticationFilter extends AbstractAuthFilter { @Override public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) servletRequest; HttpServletResponse response = (HttpServletResponse) servletResponse; String bearerToken = resolveBearerToken(request); if (StringUtils.isBlank(bearerToken)) { chain.doFilter(request, response); return; } if (authenticationIsRequired()) { try { authInterceptor.setAccessToken(bearerToken); ResponseEntity<BearerTokenTO> validateResponse = ledgersUserMgmt.validate(bearerToken); BearerTokenTO token = Optional.ofNullable(validateResponse.getBody()) .orElseThrow(() -> new RestException("Couldn't get bearer token")); fillSecurityContext(token); } catch (FeignException | RestException e) { handleAuthenticationFailure(response, e); return; } } chain.doFilter(request, response); }  }
TokenAuthenticationFilter extends AbstractAuthFilter { @Override public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) servletRequest; HttpServletResponse response = (HttpServletResponse) servletResponse; String bearerToken = resolveBearerToken(request); if (StringUtils.isBlank(bearerToken)) { chain.doFilter(request, response); return; } if (authenticationIsRequired()) { try { authInterceptor.setAccessToken(bearerToken); ResponseEntity<BearerTokenTO> validateResponse = ledgersUserMgmt.validate(bearerToken); BearerTokenTO token = Optional.ofNullable(validateResponse.getBody()) .orElseThrow(() -> new RestException("Couldn't get bearer token")); fillSecurityContext(token); } catch (FeignException | RestException e) { handleAuthenticationFailure(response, e); return; } } chain.doFilter(request, response); }  @Override void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain); }
TokenAuthenticationFilter extends AbstractAuthFilter { @Override public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) servletRequest; HttpServletResponse response = (HttpServletResponse) servletResponse; String bearerToken = resolveBearerToken(request); if (StringUtils.isBlank(bearerToken)) { chain.doFilter(request, response); return; } if (authenticationIsRequired()) { try { authInterceptor.setAccessToken(bearerToken); ResponseEntity<BearerTokenTO> validateResponse = ledgersUserMgmt.validate(bearerToken); BearerTokenTO token = Optional.ofNullable(validateResponse.getBody()) .orElseThrow(() -> new RestException("Couldn't get bearer token")); fillSecurityContext(token); } catch (FeignException | RestException e) { handleAuthenticationFailure(response, e); return; } } chain.doFilter(request, response); }  @Override void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain);  }