Program: 28237
Project: 28237
Buggy source:
/** 
 * Register an authenticated Principal and authentication type in our request, in the current session (if there is one), and with our SingleSignOn valve, if there is one.  Set the appropriate cookie to be returned.
 * @param request The servlet request we are processing
 * @param response The servlet response we are generating
 * @param principal The authenticated Principal to be registered
 * @param authType The authentication type to be registered
 * @param username Username used to authenticate (if any)
 * @param password Password used to authenticate (if any)
 */
protected void register(HttpRequest request,HttpResponse response,Principal principal,String authType,String username,char[] password){
  if (log.isLoggable(Level.FINE)) {
    String msg="String_Node_Str" + principal.getName() + "String_Node_Str"+ authType+ "String_Node_Str";
    log.log(Level.FINE,msg);
  }
  request.setAuthType(authType);
  request.setUserPrincipal(principal);
  Session session=getSession(request,false);
  if (session != null && changeSessionIdOnAuthentication) {
    request.changeSessionId();
  }
 else   if (alwaysUseSession) {
    session=getSession(request,true);
  }
  if (cache) {
    if (session != null) {
      session.setAuthType(authType);
      session.setPrincipal(principal);
      if (username != null)       session.setNote(Constants.SESS_USERNAME_NOTE,username);
 else       session.removeNote(Constants.SESS_USERNAME_NOTE);
      if (password != null)       session.setNote(Constants.SESS_PASSWORD_NOTE,password);
 else       session.removeNote(Constants.SESS_PASSWORD_NOTE);
    }
  }
  if (sso == null)   return;
  HttpServletRequest hreq=(HttpServletRequest)request.getRequest();
  HttpServletResponse hres=(HttpServletResponse)response.getResponse();
  String value=request.generateSessionId();
  if (value == null) {
    value=generateSessionId();
  }
  Cookie cookie=new Cookie(Constants.SINGLE_SIGN_ON_COOKIE,value);
  cookie.setMaxAge(-1);
  cookie.setPath("String_Node_Str");
  StandardHost host=(StandardHost)context.getParent();
  if (host != null) {
    host.configureSingleSignOnCookieSecure(cookie,hreq);
    host.configureSingleSignOnCookieHttpOnly(cookie);
  }
 else {
    cookie.setSecure(hreq.isSecure());
  }
  hres.addCookie(cookie);
  String realm=context.getRealm().getRealmName();
  assert(realm != null);
  sso.register(value,principal,authType,username,password,realm);
  request.setNote(Constants.REQ_SSOID_NOTE,value);
  if (sso.isVersioningSupported()) {
    request.setNote(Constants.REQ_SSO_VERSION_NOTE,Long.valueOf(0));
  }
}

Fixed version (ground truth):
/** 
 * Register an authenticated Principal and authentication type in our request, in the current session (if there is one), and with our SingleSignOn valve, if there is one.  Set the appropriate cookie to be returned.
 * @param request The servlet request we are processing
 * @param response The servlet response we are generating
 * @param principal The authenticated Principal to be registered
 * @param authType The authentication type to be registered
 * @param username Username used to authenticate (if any)
 * @param password Password used to authenticate (if any)
 */
protected void register(HttpRequest request,HttpResponse response,Principal principal,String authType,String username,char[] password){
  if (log.isLoggable(Level.FINE)) {
    String pname=((principal != null) ? principal.getName() : "String_Node_Str");
    String msg="String_Node_Str" + pname + "String_Node_Str"+ authType+ "String_Node_Str";
    log.log(Level.FINE,msg);
  }
  request.setAuthType(authType);
  request.setUserPrincipal(principal);
  Session session=getSession(request,false);
  if (session != null && changeSessionIdOnAuthentication) {
    request.changeSessionId();
  }
 else   if (alwaysUseSession) {
    session=getSession(request,true);
  }
  if (cache) {
    if (session != null) {
      session.setAuthType(authType);
      session.setPrincipal(principal);
      if (username != null)       session.setNote(Constants.SESS_USERNAME_NOTE,username);
 else       session.removeNote(Constants.SESS_USERNAME_NOTE);
      if (password != null)       session.setNote(Constants.SESS_PASSWORD_NOTE,password);
 else       session.removeNote(Constants.SESS_PASSWORD_NOTE);
    }
  }
  if (sso == null)   return;
  HttpServletRequest hreq=(HttpServletRequest)request.getRequest();
  HttpServletResponse hres=(HttpServletResponse)response.getResponse();
  String value=request.generateSessionId();
  if (value == null) {
    value=generateSessionId();
  }
  Cookie cookie=new Cookie(Constants.SINGLE_SIGN_ON_COOKIE,value);
  cookie.setMaxAge(-1);
  cookie.setPath("String_Node_Str");
  StandardHost host=(StandardHost)context.getParent();
  if (host != null) {
    host.configureSingleSignOnCookieSecure(cookie,hreq);
    host.configureSingleSignOnCookieHttpOnly(cookie);
  }
 else {
    cookie.setSecure(hreq.isSecure());
  }
  hres.addCookie(cookie);
  String realm=context.getRealm().getRealmName();
  assert(realm != null);
  sso.register(value,principal,authType,username,password,realm);
  request.setNote(Constants.REQ_SSOID_NOTE,value);
  if (sso.isVersioningSupported()) {
    request.setNote(Constants.REQ_SSO_VERSION_NOTE,Long.valueOf(0));
  }
}