Program: 29242
Project: 29242
Buggy source:
/** 
 * Checks whether or not authentication is needed. Returns an int, one of AUTHENTICATE_NOT_NEEDED, AUTHENTICATE_NEEDED, or AUTHENTICATED_NOT_AUTHORIZED
 * @param request Request we are processing
 * @param response Response we are creating
 * @param constraints Security constraint we are enforcing
 * @param disableProxyCaching whether or not to disable proxy caching forprotected resources.
 * @param securePagesWithPragma true if we add headers whichare incompatible with downloading office documents in IE under SSL but which fix a caching problem in Mozilla.
 * @param ssoEnabled true if sso is enabled
 * @exception IOException if an input/output error occurs
 */
public int preAuthenticateCheck(HttpRequest request,HttpResponse response,SecurityConstraint[] constraints,boolean disableProxyCaching,boolean securePagesWithPragma,boolean ssoEnabled) throws IOException {
  boolean isGranted=false;
  try {
    HttpServletRequest hsr=(HttpServletRequest)request.getRequest();
    if (hsr.getUserPrincipal() == null) {
      SecurityContext.setUnauthenticatedContext();
    }
    if (helper != null && helper.getServerAuthConfig() != null) {
      return Realm.AUTHENTICATE_NEEDED;
    }
    isGranted=invokeWebSecurityManager(request,response,constraints);
  }
 catch (  IOException iex) {
    throw iex;
  }
catch (  Throwable ex) {
    _logger.log(Level.SEVERE,"String_Node_Str",ex);
    ((HttpServletResponse)response.getResponse()).sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
    response.setDetailMessage(rb.getString("String_Node_Str"));
    return Realm.AUTHENTICATED_NOT_AUTHORIZED;
  }
  if (isGranted) {
    HashMap sharedState=null;
    boolean delegateSessionMgmt=false;
    if (((HttpServletRequest)request).getUserPrincipal() != null) {
      disableProxyCaching(request,response,disableProxyCaching,securePagesWithPragma);
      if (ssoEnabled) {
        HttpServletRequest hreq=(HttpServletRequest)request.getRequest();
        WebSecurityManager webSecMgr=getWebSecurityManager(true);
        if (!webSecMgr.permitAll(hreq)) {
          hreq.getSession(true);
        }
      }
    }
    return Realm.AUTHENTICATE_NOT_NEEDED;
  }
 else   if (((HttpServletRequest)request).getUserPrincipal() != null) {
    ((HttpServletResponse)response.getResponse()).sendError(HttpServletResponse.SC_FORBIDDEN);
    response.setDetailMessage(rb.getString("String_Node_Str"));
    return Realm.AUTHENTICATED_NOT_AUTHORIZED;
  }
 else {
    disableProxyCaching(request,response,disableProxyCaching,securePagesWithPragma);
    return Realm.AUTHENTICATE_NEEDED;
  }
}

Fixed version (ground truth):
/** 
 * Checks whether or not authentication is needed. Returns an int, one of AUTHENTICATE_NOT_NEEDED, AUTHENTICATE_NEEDED, or AUTHENTICATED_NOT_AUTHORIZED
 * @param request Request we are processing
 * @param response Response we are creating
 * @param constraints Security constraint we are enforcing
 * @param disableProxyCaching whether or not to disable proxy caching forprotected resources.
 * @param securePagesWithPragma true if we add headers whichare incompatible with downloading office documents in IE under SSL but which fix a caching problem in Mozilla.
 * @param ssoEnabled true if sso is enabled
 * @exception IOException if an input/output error occurs
 */
public int preAuthenticateCheck(HttpRequest request,HttpResponse response,SecurityConstraint[] constraints,boolean disableProxyCaching,boolean securePagesWithPragma,boolean ssoEnabled) throws IOException {
  boolean isGranted=false;
  try {
    HttpServletRequest hsr=(HttpServletRequest)request.getRequest();
    if (hsr.getUserPrincipal() == null) {
      SecurityContext.setUnauthenticatedContext();
    }
    if (helper != null && helper.getServerAuthConfig() != null) {
      return Realm.AUTHENTICATE_NEEDED;
    }
    isGranted=invokeWebSecurityManager(request,response,constraints);
  }
 catch (  IOException iex) {
    throw iex;
  }
catch (  Throwable ex) {
    _logger.log(Level.SEVERE,"String_Node_Str",ex);
    ((HttpServletResponse)response.getResponse()).sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
    response.setDetailMessage(rb.getString("String_Node_Str"));
    return Realm.AUTHENTICATED_NOT_AUTHORIZED;
  }
  if (isGranted) {
    HashMap sharedState;
    boolean delegateSessionMgmt=false;
    if (((HttpServletRequest)request).getUserPrincipal() != null) {
      disableProxyCaching(request,response,disableProxyCaching,securePagesWithPragma);
      if (ssoEnabled) {
        HttpServletRequest hreq=(HttpServletRequest)request.getRequest();
        WebSecurityManager webSecMgr=getWebSecurityManager(true);
        if (!webSecMgr.permitAll(hreq)) {
          hreq.getSession(true);
        }
      }
    }
    return Realm.AUTHENTICATE_NOT_NEEDED;
  }
 else   if (((HttpServletRequest)request).getUserPrincipal() != null) {
    ((HttpServletResponse)response.getResponse()).sendError(HttpServletResponse.SC_FORBIDDEN);
    response.setDetailMessage(rb.getString("String_Node_Str"));
    return Realm.AUTHENTICATED_NOT_AUTHORIZED;
  }
 else {
    disableProxyCaching(request,response,disableProxyCaching,securePagesWithPragma);
    return Realm.AUTHENTICATE_NEEDED;
  }
}