opinion: James Haynes CAMARILLO, Plaintiff-Appellee, v. Daniel J. McCARTHY, Director, et al., Defendants-Appellants.
  No. 92-15991.
  United States Court of Appeals, Ninth Circuit.
  Submitted Feb. 3, 1993.
  Memorandum April 2, 1993.
  Order and Opinion July 1, 1993.
  Allen R. Crown, Deputy Atty. Gen., Sacramento, CA, for defendants-appellants.
  James Haynes Camarillo, pro se.
  Before: FARRIS, POOLE, and WIGGINS, Circuit Judges.
  The panel unanimously found this case suitable for decision without oral argument. Fed. R.App.P. 34(a); 9th Cir.R. 34-4.
  ORDER
  The memorandum disposition filed April 2, 1993, is redesignated as an authored opinion by Judge Farris.
  OPINION
  FARRIS, Circuit Judge:
  Defendants, California state prison officials, appeal the denial of their motion for summary judgment in an action brought by former state prisoner James Haynes Camar-illo pursuant to 42 U.S.C. § 1983. While incarcerated, Camarillo, who is HIV-positive, was transferred to a housing unit for HIV-positive inmates. Camarillo’s suit alleged that his transfer violated his constitutional rights of: (1) equal protection; (2) privacy; (3) due process; (4) freedom from cruel and unusual punishment; and (5) freedom of association. On cross-motions for summary judgment, the district court held that qualified immunity barred suit against the officials for the first four of the alleged constitutional violations. On the freedom of association claim, the court did not address qualified immunity. Instead, it denied the defendants’ motion for summary judgment and ordered the matter to proceed to trial because a question remained as to whether Camarillo’s freedom to associate in fact was curtailed.
  We have jurisdiction over this interlocutory appeal pursuant to the collateral order doctrine. See Mitchell v. Forsyth, 472 U.S. 511, 530, 105 S.Ct. 2806, 2817, 86 L.Ed.2d 411 (1985); Romero v. Kitsap County, 931 F.2d 624, 626 (9th Cir.1991). We review de novo the denial of a defense based on qualified immunity. Romero, 931 F.2d at 627.
  I.
  Camarillo argues that the prison officials waived the defense of qualified immunity by failing to raise it as an affirmative defense in their answer to the complaint. Qualified immunity is an affirmative defense that should be pled by the defendant. Gomez v. Toledo, 446 U.S. 635, 640, 100 S.Ct. 1920, 1923, 64 L.Ed.2d 572 (1980); Fed. R.Civ.P. 8(c). In the absence of a showing of prejudice, however, an affirmative defense may be raised for the first time at summary judgment. See Rivera v. Anaya, 726 F.2d 564, 566 (9th Cir.1984). Camarillo has not claimed prejudice; nor is any suggested by the record. The defense of qualified immunity was not waived. See id.
  II.
  Qualified immunity protects government officials performing discretionary functions from liability for civil damages, unless the official’s conduct violates clearly established statutory or constitutional rights of which a reasonable person would have known. Harlow v. Fitzgerald, 457 U.S. 800, 818, 102 S.Ct. 2727, 2738, 73 L.Ed.2d 396 (1982); Romero, 931 F.2d at 627. The plaintiff in a § 1983 action bears the burden of proving that the right allegedly violated was clearly established at the time of the official’s allegedly impermissible conduct. Elder v. Holloway, 975 F.2d 1388, 1390 (9th Cir.1992), petition for cert. filed, — U.S. -, 113 S.Ct. 3033, 125 L.Ed.2d 721 (1993); Romero, 931 F.2d at 627.
  A law is “clearly established” when “the contours of the right [are] sufficiently clear that a reasonable official would understand that what he is doing violates that right.” Anderson v. Creighton, 483 U.S. 635, 640, 107 S.Ct. 3034, 3039, 97 L.Ed.2d 523 (1987). The magistrate judge, whose findings were adopted by the district court, canvassed relevant decisional law, see Wood v. Ostrander, 879 F.2d 583, 591 (9th Cir.1989), cert. denied, 498 U.S. 938, 111 S.Ct. 341, 112 L.Ed.2d 305 (1990), and concluded that “[i]t was not clearly established by statute or case law that such segregation violated statutory or constitutional rights.” Nevertheless, the court denied in part the defendants’ motion for summary judgment because a factual dispute remained as to whether Camarillo’s freedom to associate was restricted.
  The district court should have ordered summary judgment for the defendants. Once it was determined that no clearly established constitutional right was violated, the factual dispute became immaterial. See Romero, 931 F.2d at 628.
  III.
  Camarillo argues that it was clearly established at the time he was segregated in the HIV unit that prison inmates have First Amendment rights, including freedom of association. Camarillo misapprehends the level of generality at which a law must be “clearly established.” See Anderson, 483 U.S. at 639, 107 S.Ct. at 3038. The operation of the “clearly established” standard,
  depends substantially upon the level of generality at which the relevant “legal rule” is to be identified. For example, the right to due process of law is quite clearly established by the Due Process Clause, and thus there is a sense in which any action that violates the Clause (no matter how unclear it may be that the particular action is a violation) violates a clearly established right. Much the same could be said of any other constitutional or statutory violation. But if the test of “clearly established law” were to be applied at this level of generality, it would bear no relationship to the “objective legal reasonableness” that is the touchstone of Harlow.
  Id.
  The relevant, properly particularized question, see id. 483 U.S. at 640, 107 S.Ct. at 3039, is whether, at the time of the transfer, it was clearly established that inmates are entitled to be free from prison regulations that restrict their association with members of the general prison population.
  A prison regulation that impinges on uan inmate’s constitutional rights is valid if it is reasonably related to legitimate penological interests. Turner v. Safley, 482 U.S. 78, 89, 107 S.Ct. 2254, 2261, 96 L.Ed.2d 64 (1987). It was not clearly established at the relevant time-nor is it now-that a prison policy segregating HIV-positive inmates from the general prison population is unconstitutional. Camarillo failed to cite a single ease, either to the district court or on appeal, indicating otherwise.
  REVERSED and REMANDED for entry of summary judgment for defendants on the issue of freedom of association.
  . Several recent cases in other circuits have upheld as constitutional prison policies mandating segregation of HIV-positive inmates. See, e.g., Moore v. Mabus, 976 F.2d 268, 271 (5th Cir. 1992) ("the identification and segregation of HIV-positive prisoners obviously serves a legitimate penological interest.”); Harris v. Thigpen, 941 F.2d 1495, 1521 (11th Cir.1991); Muhammad v. Carlson, 845 F.2d 175, 177 (8th Cir.1988), cert. denied, 489 U.S. 1068, 109 S.Ct. 1346, 103 L.Ed.2d 814 (1989); Cordero v. Coughlin, 607 F.Supp. 9, 11 (S.D.N.Y.1984).
  . This is not to say that any particular HIV-segregation policy-including that of the California Department of Corrections-is constitutional. That question is not before us. We hold only that the officials in this action are immune from suit under the doctrine of qualified immunity.
  .Although it is Camarillo's responsibility to "identify the universe of statutory or decisional law from which the court can determine whether the right allegedly violated was clearly established,” see Elder, 975 F.2d at 1392, we may undertake our own inquiry. See id. at 1396. Our research convinces us that the right Camarillo asserts was not clearly established in June 1987.
instruction: What follows is an opinion from a United States Court of Appeals.
  Intervenors who participated as parties at the courts of appeals should be counted as either appellants or respondents when it can be determined whose position they supported. For example, if there were two plaintiffs who lost in district court, appealed, and were joined by four intervenors who also asked the court of appeals to reverse the district court, the number of appellants should be coded as six.
  In some cases there is some confusion over who should be listed as the appellant and who as the respondent. This confusion is primarily the result of the presence of multiple docket numbers consolidated into a single appeal that is disposed of by a single opinion. Most frequently, this occurs when there are cross appeals and/or when one litigant sued (or was sued by) multiple litigants that were originally filed in district court as separate actions. The coding rule followed in such cases should be to go strictly by the designation provided in the title of the case. The first person listed in the title as the appellant should be coded as the appellant even if they subsequently appeared in a second docket number as the respondent and regardless of who was characterized as the appellant in the opinion.
  To clarify the coding conventions, consider the following hypothetical case in which the US Justice Department sues a labor union to strike down a racially discriminatory seniority system and the corporation (siding with the position of its union) simultaneously sues the government to get an injunction to block enforcement of the relevant civil rights law. From a district court decision that consolidated the two suits and declared the seniority system illegal but refused to impose financial penalties on the union, the corporation appeals and the government and union file cross appeals from the decision in the suit brought by the government. Assume the case was listed in the Federal Reporter as follows:
  United States of America,
  Plaintiff, Appellant
  v
  International Brotherhood of Widget Workers,AFL-CIO
  Defendant, Appellee.
  International Brotherhood of Widget Workers,AFL-CIO
  Defendants, Cross-appellants
  v
  United States of America.
  Widgets, Inc. & Susan Kuersten Sheehan, President & Chairman
  of the Board
  Plaintiff, Appellants,
  v
  United States of America,
  Defendant, Appellee.
  This case should be coded as follows:Appellant = United States, Respondents = International Brotherhood of Widget Workers Widgets, Inc., Total number of appellants = 1, Number of appellants that fall into the category "the federal government, its agencies, and officials" = 1, Total number of respondents = 3, Number of respondents that fall into the category "private business and its executives" = 2, Number of respondents that fall into the category "groups and associations" = 1.
  Your task is to identify the state of the first listed state or local government agency that is an appellant.
choices: not Alabama Alaska Arizona Arkansas California Colorado Connecticut Delaware Florida Georgia Hawaii Idaho Illinois Indiana Iowa Kansas Kentucky Louisiana Maine Maryland Massachussets Michigan Minnesota Mississippi Missouri Montana Nebraska Nevada New New New New North North Ohio Oklahoma Oregon Pennsylvania Rhode South South Tennessee Texas Utah Vermont Virginia Washington West Wisconsin Wyoming Virgin Puerto District Guam not Panama