Program: 166339
Project: 166339
Buggy source:
@Override public void doFilter(ServletRequest servletRequest,ServletResponse servletResponse,FilterChain filterChain) throws IOException, ServletException {
  RangerSecurityContext context=RangerContextHolder.getSecurityContext();
  UserSessionBase session=context != null ? context.getUserSession() : null;
  ssoEnabled=session != null ? session.isSSOEnabled() : PropertiesUtil.getBooleanProperty("String_Node_Str",false);
  String userAgent=((HttpServletRequest)servletRequest).getHeader("String_Node_Str");
  if (((HttpServletRequest)servletRequest).getSession() != null) {
    if (((HttpServletRequest)servletRequest).getSession().getAttribute("String_Node_Str") != null) {
      ssoEnabled=false;
      servletRequest.setAttribute("String_Node_Str",false);
      filterChain.doFilter(servletRequest,servletResponse);
      return;
    }
  }
  if (ssoEnabled && !((HttpServletRequest)servletRequest).getRequestURI().contains(LOCAL_LOGIN_URL) && isWebUserAgent(userAgent)) {
    if (jwtProperties != null && !isAuthenticated()) {
      HttpServletRequest httpServletRequest=(HttpServletRequest)servletRequest;
      HttpServletResponse httpServletResponse=(HttpServletResponse)servletResponse;
      String serializedJWT=getJWTFromCookie(httpServletRequest);
      if (serializedJWT != null) {
        SignedJWT jwtToken=null;
        try {
          jwtToken=SignedJWT.parse(serializedJWT);
          boolean valid=validateToken(jwtToken);
          if (valid) {
            String userName=jwtToken.getJWTClaimsSet().getSubject();
            LOG.info("String_Node_Str" + userName);
            String rangerLdapDefaultRole=PropertiesUtil.getProperty("String_Node_Str","String_Node_Str");
            if (userName != null && !userName.trim().isEmpty()) {
              final List<GrantedAuthority> grantedAuths=new ArrayList<>();
              grantedAuths.add(new SimpleGrantedAuthority(rangerLdapDefaultRole));
              final UserDetails principal=new User(userName,"String_Node_Str",grantedAuths);
              final Authentication finalAuthentication=new UsernamePasswordAuthenticationToken(principal,"String_Node_Str",grantedAuths);
              WebAuthenticationDetails webDetails=new WebAuthenticationDetails(httpServletRequest);
              ((AbstractAuthenticationToken)finalAuthentication).setDetails(webDetails);
              RangerAuthenticationProvider authenticationProvider=new RangerAuthenticationProvider();
              authenticationProvider.setSsoEnabled(ssoEnabled);
              final Authentication authentication=authenticationProvider.authenticate(finalAuthentication);
              SecurityContextHolder.getContext().setAuthentication(authentication);
            }
            filterChain.doFilter(servletRequest,httpServletResponse);
          }
 else {
            String ssourl=constructLoginURL(httpServletRequest);
            if (LOG.isDebugEnabled())             LOG.debug("String_Node_Str" + ssourl);
            httpServletResponse.sendRedirect(ssourl);
          }
        }
 catch (        ParseException e) {
          LOG.warn("String_Node_Str",e);
        }
      }
 else {
        String ssourl=constructLoginURL(httpServletRequest);
        if (LOG.isDebugEnabled())         LOG.debug("String_Node_Str" + ssourl);
        httpServletResponse.sendRedirect(ssourl);
      }
    }
 else {
      filterChain.doFilter(servletRequest,servletResponse);
    }
  }
 else   if (ssoEnabled && ((HttpServletRequest)servletRequest).getRequestURI().contains(LOCAL_LOGIN_URL) && isWebUserAgent(userAgent)&& isAuthenticated()) {
    String url=((HttpServletRequest)servletRequest).getRequestURI().replace(LOCAL_LOGIN_URL + "String_Node_Str","String_Node_Str");
    url=url.replace(LOCAL_LOGIN_URL,"String_Node_Str");
    LOG.warn("String_Node_Str");
    ((HttpServletResponse)servletResponse).sendRedirect(url);
  }
 else {
    filterChain.doFilter(servletRequest,servletResponse);
  }
}

Fixed version (ground truth):
@Override public void doFilter(ServletRequest servletRequest,ServletResponse servletResponse,FilterChain filterChain) throws IOException, ServletException {
  HttpServletRequest httpRequest=(HttpServletRequest)servletRequest;
  if (httpRequest.getRequestedSessionId() != null && !httpRequest.isRequestedSessionIdValid()) {
    if (httpRequest.getServletContext().getAttribute(httpRequest.getRequestedSessionId()) != null && httpRequest.getServletContext().getAttribute(httpRequest.getRequestedSessionId()).toString().equals("String_Node_Str")) {
      ssoEnabled=false;
      httpRequest.getSession().setAttribute("String_Node_Str","String_Node_Str");
      httpRequest.getServletContext().removeAttribute(httpRequest.getRequestedSessionId());
    }
  }
  RangerSecurityContext context=RangerContextHolder.getSecurityContext();
  UserSessionBase session=context != null ? context.getUserSession() : null;
  ssoEnabled=session != null ? session.isSSOEnabled() : PropertiesUtil.getBooleanProperty("String_Node_Str",false);
  String userAgent=httpRequest.getHeader("String_Node_Str");
  if (httpRequest.getSession() != null) {
    if (httpRequest.getSession().getAttribute("String_Node_Str") != null) {
      ssoEnabled=false;
      servletRequest.setAttribute("String_Node_Str",false);
      filterChain.doFilter(servletRequest,servletResponse);
      return;
    }
  }
  if (ssoEnabled && !httpRequest.getRequestURI().contains(LOCAL_LOGIN_URL) && isWebUserAgent(userAgent)) {
    if (jwtProperties != null && !isAuthenticated()) {
      HttpServletResponse httpServletResponse=(HttpServletResponse)servletResponse;
      String serializedJWT=getJWTFromCookie(httpRequest);
      if (serializedJWT != null) {
        SignedJWT jwtToken=null;
        try {
          jwtToken=SignedJWT.parse(serializedJWT);
          boolean valid=validateToken(jwtToken);
          if (valid) {
            String userName=jwtToken.getJWTClaimsSet().getSubject();
            LOG.info("String_Node_Str" + userName);
            String rangerLdapDefaultRole=PropertiesUtil.getProperty("String_Node_Str","String_Node_Str");
            if (userName != null && !userName.trim().isEmpty()) {
              final List<GrantedAuthority> grantedAuths=new ArrayList<>();
              grantedAuths.add(new SimpleGrantedAuthority(rangerLdapDefaultRole));
              grantedAuths.add(new SimpleGrantedAuthority("String_Node_Str"));
              grantedAuths.add(new SimpleGrantedAuthority("String_Node_Str"));
              final UserDetails principal=new User(userName,"String_Node_Str",grantedAuths);
              final Authentication finalAuthentication=new UsernamePasswordAuthenticationToken(principal,"String_Node_Str",grantedAuths);
              WebAuthenticationDetails webDetails=new WebAuthenticationDetails(httpRequest);
              ((AbstractAuthenticationToken)finalAuthentication).setDetails(webDetails);
              RangerAuthenticationProvider authenticationProvider=new RangerAuthenticationProvider();
              authenticationProvider.setSsoEnabled(ssoEnabled);
              final Authentication authentication=authenticationProvider.authenticate(finalAuthentication);
              SecurityContextHolder.getContext().setAuthentication(authentication);
            }
            filterChain.doFilter(servletRequest,httpServletResponse);
          }
 else {
            String ssourl=constructLoginURL(httpRequest);
            if (LOG.isDebugEnabled())             LOG.debug("String_Node_Str" + ssourl);
            httpServletResponse.sendRedirect(ssourl);
          }
        }
 catch (        ParseException e) {
          LOG.warn("String_Node_Str",e);
        }
      }
 else {
        String ssourl=constructLoginURL(httpRequest);
        if (LOG.isDebugEnabled())         LOG.debug("String_Node_Str" + ssourl);
        httpServletResponse.sendRedirect(ssourl);
      }
    }
 else {
      filterChain.doFilter(servletRequest,servletResponse);
    }
  }
 else   if (ssoEnabled && ((HttpServletRequest)servletRequest).getRequestURI().contains(LOCAL_LOGIN_URL) && isWebUserAgent(userAgent)&& isAuthenticated()) {
    String url=((HttpServletRequest)servletRequest).getRequestURI().replace(LOCAL_LOGIN_URL + "String_Node_Str","String_Node_Str");
    url=url.replace(LOCAL_LOGIN_URL,"String_Node_Str");
    LOG.warn("String_Node_Str");
    ((HttpServletResponse)servletResponse).sendRedirect(url);
  }
 else {
    filterChain.doFilter(servletRequest,servletResponse);
  }
}