@Test void doFilterInternal() throws ServletException, IOException { SecurityContextHolder.clearContext(); when(tokenAuthenticationService.getAuthentication(any())).thenReturn(new UserAuthentication(getBearer())); filter.doFilterInternal(request, response, chain); verify(tokenAuthenticationService, times(1)).getAuthentication(any()); verify(chain, times(1)).doFilter(any(), any()); }
@Override public void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { if (log.isTraceEnabled()) { log.trace("doFilter start"); } Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (authentication == null) { UserAuthentication userAuthentication = tokenAuthenticationService.getAuthentication(readAccessTokenCookie(request)); if(userAuthentication != null) { BearerTokenTO bearerToken = userAuthentication.getBearerToken(); AccessTokenTO token = bearerToken.getAccessTokenObject(); SecurityContextHolder.getContext().setAuthentication(new ObaMiddlewareAuthentication(token.getSub(), bearerToken, buildAuthorities(token))); } } filterChain.doFilter(request, response); if (log.isTraceEnabled()) { log.trace("doFilter end"); } }
JWTAuthenticationFilter extends OncePerRequestFilter { @Override public void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { if (log.isTraceEnabled()) { log.trace("doFilter start"); } Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (authentication == null) { UserAuthentication userAuthentication = tokenAuthenticationService.getAuthentication(readAccessTokenCookie(request)); if(userAuthentication != null) { BearerTokenTO bearerToken = userAuthentication.getBearerToken(); AccessTokenTO token = bearerToken.getAccessTokenObject(); SecurityContextHolder.getContext().setAuthentication(new ObaMiddlewareAuthentication(token.getSub(), bearerToken, buildAuthorities(token))); } } filterChain.doFilter(request, response); if (log.isTraceEnabled()) { log.trace("doFilter end"); } } }
JWTAuthenticationFilter extends OncePerRequestFilter { @Override public void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { if (log.isTraceEnabled()) { log.trace("doFilter start"); } Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (authentication == null) { UserAuthentication userAuthentication = tokenAuthenticationService.getAuthentication(readAccessTokenCookie(request)); if(userAuthentication != null) { BearerTokenTO bearerToken = userAuthentication.getBearerToken(); AccessTokenTO token = bearerToken.getAccessTokenObject(); SecurityContextHolder.getContext().setAuthentication(new ObaMiddlewareAuthentication(token.getSub(), bearerToken, buildAuthorities(token))); } } filterChain.doFilter(request, response); if (log.isTraceEnabled()) { log.trace("doFilter end"); } }  }
JWTAuthenticationFilter extends OncePerRequestFilter { @Override public void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { if (log.isTraceEnabled()) { log.trace("doFilter start"); } Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (authentication == null) { UserAuthentication userAuthentication = tokenAuthenticationService.getAuthentication(readAccessTokenCookie(request)); if(userAuthentication != null) { BearerTokenTO bearerToken = userAuthentication.getBearerToken(); AccessTokenTO token = bearerToken.getAccessTokenObject(); SecurityContextHolder.getContext().setAuthentication(new ObaMiddlewareAuthentication(token.getSub(), bearerToken, buildAuthorities(token))); } } filterChain.doFilter(request, response); if (log.isTraceEnabled()) { log.trace("doFilter end"); } }  @Override void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain); }
JWTAuthenticationFilter extends OncePerRequestFilter { @Override public void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { if (log.isTraceEnabled()) { log.trace("doFilter start"); } Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (authentication == null) { UserAuthentication userAuthentication = tokenAuthenticationService.getAuthentication(readAccessTokenCookie(request)); if(userAuthentication != null) { BearerTokenTO bearerToken = userAuthentication.getBearerToken(); AccessTokenTO token = bearerToken.getAccessTokenObject(); SecurityContextHolder.getContext().setAuthentication(new ObaMiddlewareAuthentication(token.getSub(), bearerToken, buildAuthorities(token))); } } filterChain.doFilter(request, response); if (log.isTraceEnabled()) { log.trace("doFilter end"); } }  @Override void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain);  }