Program: 79788
Project: 79788
Buggy source:
boolean processIndexType(IndexType indexType,String indexName,String orgDN) throws AuthLoginException {
  boolean ignoreProfile=false;
  IndexType previousType=loginState.getPreviousIndexType();
  String normOrgDN=DNUtils.normalizeDN(orgDN);
  if ((previousType != IndexType.LEVEL && previousType != IndexType.COMPOSITE_ADVICE) || indexType != IndexType.MODULE_INSTANCE) {
    HttpServletRequest hreq=loginState.getHttpServletRequest();
    boolean isTokenValid=false;
    final boolean isFederation=indexType == AuthContext.IndexType.MODULE_INSTANCE && ISAuthConstants.FEDERATION_MODULE.equals(indexName);
    if (hreq != null && !isFederation) {
      try {
        SSOTokenManager manager=SSOTokenManager.getInstance();
        SSOToken ssoToken=manager.createSSOToken(hreq);
        if (manager.isValidToken(ssoToken)) {
          debug.message("String_Node_Str");
          isTokenValid=true;
        }
      }
 catch (      Exception e) {
        debug.message("String_Node_Str" + e.toString());
      }
      if (!isTokenValid) {
        debug.message("String_Node_Str");
        Hashtable requestHash=loginState.getRequestParamHash();
        String newOrgDN=AuthUtils.getDomainNameByRequest(hreq,requestHash);
        if (debug.messageEnabled()) {
          debug.message("String_Node_Str" + orgDN + "String_Node_Str"+ newOrgDN);
        }
        if (normOrgDN != null) {
          if (!normOrgDN.equals(newOrgDN) && !pCookieMode) {
            loginStatus.setStatus(LoginStatus.AUTH_RESET);
            loginState.setErrorCode(AMAuthErrorCode.AUTH_ERROR);
            setErrorMsgAndTemplate();
            internalAuthError=true;
            throw new AuthLoginException(BUNDLE_NAME,AMAuthErrorCode.AUTH_ERROR,null);
          }
        }
      }
    }
  }
  if (indexType == IndexType.COMPOSITE_ADVICE) {
    debug.message("String_Node_Str");
    String compositeAdvice=URLEncDec.decode(indexName);
    loginState.setCompositeAdvice(compositeAdvice);
    try {
      if (processCompositeAdvice(indexType,indexName,orgDN,clientType)) {
        debug.message("String_Node_Str");
        return true;
      }
 else {
        return false;
      }
    }
 catch (    AuthException ae) {
      loginState.setErrorCode(ae.getErrorCode());
      loginState.logFailed(ae.getMessage());
      setErrorMsgAndTemplate();
      loginStatus.setStatus(LoginStatus.AUTH_FAILED);
      throw new AuthLoginException(ae);
    }
  }
 else   if (indexType == IndexType.LEVEL) {
    debug.message("String_Node_Str");
    try {
      if (processLevel(indexType,indexName,orgDN,clientType)) {
        debug.message("String_Node_Str");
        return true;
      }
 else {
        return false;
      }
    }
 catch (    AuthException ae) {
      loginState.setErrorCode(ae.getErrorCode());
      loginState.logFailed(ae.getMessage());
      setErrorMsgAndTemplate();
      loginStatus.setStatus(LoginStatus.AUTH_FAILED);
      throw new AuthLoginException(ae);
    }
  }
 else   if (indexType == IndexType.USER) {
    debug.message("String_Node_Str");
    boolean userValid=false;
    if (!loginState.ignoreProfile()) {
      userValid=validateUser(indexName);
    }
 else {
      ignoreProfile=true;
    }
    if (pCookieMode) {
      processPCookieMode(userValid);
      return true;
    }
 else     if ((!userValid) && (!ignoreProfile)) {
      debug.message("String_Node_Str");
      loginState.logFailed(bundle.getString("String_Node_Str"),"String_Node_Str");
      loginState.setErrorCode(AMAuthErrorCode.AUTH_LOGIN_FAILED);
      setErrorMsgAndTemplate();
      loginStatus.setStatus(LoginStatus.AUTH_FAILED);
      throw new AuthLoginException(BUNDLE_NAME,AMAuthErrorCode.AUTH_USER_INACTIVE,null);
    }
 else     if (ignoreProfile) {
      setAuthError(AMAuthErrorCode.AUTH_PROFILE_ERROR,"String_Node_Str");
      throw new AuthLoginException(BUNDLE_NAME,AMAuthErrorCode.AUTH_PROFILE_ERROR,null);
    }
 else {
      return false;
    }
  }
 else   if (indexType == IndexType.MODULE_INSTANCE) {
    debug.message("String_Node_Str");
    boolean instanceExists=loginState.getDomainAuthenticators().contains(indexName);
    if (!indexName.equals(ISAuthConstants.APPLICATION_MODULE) && !instanceExists) {
      debug.message("String_Node_Str");
      loginState.setErrorCode(AMAuthErrorCode.AUTH_MODULE_DENIED);
      loginState.logFailed(bundle.getString("String_Node_Str"),"String_Node_Str");
      setErrorMsgAndTemplate();
      loginStatus.setStatus(LoginStatus.AUTH_FAILED);
      throw new AuthLoginException(BUNDLE_NAME,AMAuthErrorCode.AUTH_MODULE_DENIED,null);
    }
 else {
      return false;
    }
  }
 else   if (indexType == IndexType.ROLE) {
    debug.message("String_Node_Str");
    if (loginState.ignoreProfile()) {
      setAuthError(AMAuthErrorCode.AUTH_TYPE_DENIED,"String_Node_Str");
      throw new AuthLoginException(BUNDLE_NAME,AMAuthErrorCode.AUTH_TYPE_DENIED,null);
    }
  }
  return false;
}

Fixed version (ground truth):
boolean processIndexType(IndexType indexType,String indexName,String orgDN) throws AuthLoginException {
  boolean ignoreProfile=false;
  IndexType previousType=loginState.getPreviousIndexType();
  String normOrgDN=DNUtils.normalizeDN(orgDN);
  if ((previousType != IndexType.LEVEL && previousType != IndexType.COMPOSITE_ADVICE) || indexType != IndexType.MODULE_INSTANCE) {
    HttpServletRequest hreq=loginState.getHttpServletRequest();
    boolean isTokenValid=false;
    final boolean isFederation=indexType == IndexType.MODULE_INSTANCE && ISAuthConstants.FEDERATION_MODULE.equals(indexName);
    if (hreq != null && !isFederation) {
      try {
        SSOTokenManager manager=SSOTokenManager.getInstance();
        SSOToken ssoToken=manager.createSSOToken(hreq);
        if (manager.isValidToken(ssoToken)) {
          debug.message("String_Node_Str");
          isTokenValid=true;
        }
      }
 catch (      Exception e) {
        debug.message("String_Node_Str" + e.toString());
      }
      if (!isTokenValid) {
        debug.message("String_Node_Str");
        Hashtable requestHash=loginState.getRequestParamHash();
        String newOrgDN=AuthUtils.getDomainNameByRequest(hreq,requestHash);
        if (debug.messageEnabled()) {
          debug.message("String_Node_Str" + orgDN + "String_Node_Str"+ newOrgDN);
        }
        if (normOrgDN != null) {
          if (!normOrgDN.equals(newOrgDN) && !pCookieMode) {
            loginStatus.setStatus(LoginStatus.AUTH_RESET);
            loginState.setErrorCode(AMAuthErrorCode.AUTH_ERROR);
            setErrorMsgAndTemplate();
            internalAuthError=true;
            throw new AuthLoginException(BUNDLE_NAME,AMAuthErrorCode.AUTH_ERROR,null);
          }
        }
      }
    }
  }
  if (indexType == IndexType.COMPOSITE_ADVICE) {
    debug.message("String_Node_Str");
    String compositeAdvice=URLEncDec.decode(indexName);
    loginState.setCompositeAdvice(compositeAdvice);
    try {
      if (processCompositeAdvice(indexType,indexName,orgDN,clientType)) {
        debug.message("String_Node_Str");
        return true;
      }
 else {
        return false;
      }
    }
 catch (    AuthException ae) {
      loginState.setErrorCode(ae.getErrorCode());
      loginState.logFailed(ae.getMessage());
      setErrorMsgAndTemplate();
      loginStatus.setStatus(LoginStatus.AUTH_FAILED);
      throw new AuthLoginException(ae);
    }
  }
 else   if (indexType == IndexType.LEVEL) {
    debug.message("String_Node_Str");
    try {
      if (processLevel(indexType,indexName,orgDN,clientType)) {
        debug.message("String_Node_Str");
        return true;
      }
 else {
        return false;
      }
    }
 catch (    AuthException ae) {
      loginState.setErrorCode(ae.getErrorCode());
      loginState.logFailed(ae.getMessage());
      setErrorMsgAndTemplate();
      loginStatus.setStatus(LoginStatus.AUTH_FAILED);
      throw new AuthLoginException(ae);
    }
  }
 else   if (indexType == IndexType.USER) {
    debug.message("String_Node_Str");
    boolean userValid=false;
    if (!loginState.ignoreProfile()) {
      userValid=validateUser(indexName);
    }
 else {
      ignoreProfile=true;
    }
    if (pCookieMode) {
      processPCookieMode(userValid);
      return true;
    }
 else     if ((!userValid) && (!ignoreProfile)) {
      debug.message("String_Node_Str");
      loginState.logFailed(bundle.getString("String_Node_Str"),"String_Node_Str");
      loginState.setErrorCode(AMAuthErrorCode.AUTH_LOGIN_FAILED);
      setErrorMsgAndTemplate();
      loginStatus.setStatus(LoginStatus.AUTH_FAILED);
      throw new AuthLoginException(BUNDLE_NAME,AMAuthErrorCode.AUTH_USER_INACTIVE,null);
    }
 else     if (ignoreProfile) {
      setAuthError(AMAuthErrorCode.AUTH_PROFILE_ERROR,"String_Node_Str");
      throw new AuthLoginException(BUNDLE_NAME,AMAuthErrorCode.AUTH_PROFILE_ERROR,null);
    }
 else {
      return false;
    }
  }
 else   if (indexType == IndexType.MODULE_INSTANCE) {
    debug.message("String_Node_Str");
    boolean instanceExists=loginState.getDomainAuthenticators().contains(indexName);
    if (!indexName.equals(ISAuthConstants.APPLICATION_MODULE) && !instanceExists) {
      debug.message("String_Node_Str");
      loginState.setErrorCode(AMAuthErrorCode.AUTH_MODULE_DENIED);
      loginState.logFailed(bundle.getString("String_Node_Str"),"String_Node_Str");
      setErrorMsgAndTemplate();
      loginStatus.setStatus(LoginStatus.AUTH_FAILED);
      throw new AuthLoginException(BUNDLE_NAME,AMAuthErrorCode.AUTH_MODULE_DENIED,null);
    }
 else {
      return false;
    }
  }
 else   if (indexType == IndexType.ROLE) {
    debug.message("String_Node_Str");
    if (loginState.ignoreProfile()) {
      setAuthError(AMAuthErrorCode.AUTH_TYPE_DENIED,"String_Node_Str");
      throw new AuthLoginException(BUNDLE_NAME,AMAuthErrorCode.AUTH_TYPE_DENIED,null);
    }
  }
  return false;
}