opinion: 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. You will be asked a question pertaining to issues that may appear in any civil law cases including civil government, civil private, and diversity cases. The issue is: "Did the court's ruling on an issue arising out of an alternative dispute resolution process (ADR, settlement conference, role of mediator or arbitrator, etc.) favor the appellant?" Answer the question based on the directionality of the appeals court decision. If the court discussed the issue in its opinion and answered the related question in the affirmative, answer "Yes". If the issue was discussed and the opinion answered the question negatively, answer "No". If the opinion considered the question but gave a mixed answer, supporting the respondent in part and supporting the appellant in part, answer "Mixed answer". If the opinion does not discuss the issue, or notes that a particular issue was raised by one of the litigants but the court dismissed the issue as frivolous or trivial or not worthy of discussion for some other reason, answer "Issue not discussed". If the opinion considered the question but gave a "mixed" answer, supporting the respondent in part and supporting the appellant in part (or if two issues treated separately by the court both fell within the area covered by one question and the court answered one question affirmatively and one negatively), answer "Mixed answer". If the opinion either did not consider or discuss the issue at all or if the opinion indicates that this issue was not worthy of consideration by the court of appeals even though it was discussed by the lower court or was raised in one of the briefs, answer "Issue not discussed".