Washington(CNN) A former head of the FBI and CIA says President Donald Trump and Attorney General William Barr's harsh criticism of the bureau in the wake of an inspector general report about the origins of the Russia investigation are "dangerous and unwarranted" and a "dire threat to the rule of law."

"Today, the integrity of the institutions that protect our civil order is, tragically, under assault from too many people whose job it should be to protect them," William Webster, the only person to lead both of the intelligence services, wrote in a New York Times op-ed published Monday.

"Calling F.B.I. professionals 'scum,' as the president did, is a slur against people who risk their lives to keep us safe. Mr. Barr's charges of bias within the F.B.I., made without providing any evidence and in direct dispute of the findings of the nonpartisan inspector general, risk inflicting enduring damage on this critically important institution," Webster argued.

Webster wrote that the "aspersions cast upon" the FBI by Trump and my "longtime friend" Barr are "troubling in the extreme."

Trump, who has long criticized FBI leadership, last week lashed out at Director Christopher Wray after Wray backed the findings of an inspector general report that found the FBI's investigation into Russian election interference was properly launched.

"I don't know what report current Director of the FBI Christopher Wray was reading, but it sure wasn't the one given to me. With that kind of attitude, he will never be able to fix the FBI, which is badly broken despite having some of the greatest men & women working there!" Trump wrote on Twitter.

After the IG's report was released last Monday, Barr excoriated the FBI for launching what he called an "intrusive investigation" into a presidential campaign based on the "thinnest of suspicions."

In his op-ed, Webster pushed back against Trump's criticism of Wray and the FBI, saying he has "complete confidence" in Wray and the FBI is "not a broken institution."

"It is a professional agency worthy of respect and support. The derision and aspersions are dangerous and unwarranted," Webster argued, adding that Trump's "thinly veiled suggestion" that Wray may be fired "disturbs me greatly."

FBI directors are appointed to 10-year terms in an attempt to avoid political interference. Webster was appointed FBI director in 1978 by former President Jimmy Carter, a Democrat, and continued in that role under former President Ronald Reagan, a Republican. Reagan later tapped him to lead the CIA in 1987, a role he maintained into former President George H.W. Bush's tenure.

Trump has frequently been at odds with Wray, who he appointed in 2017, as well as other bureau leaders. He fired then-FBI Director James Comey in May 2017, saying in an interview with NBC that he was considering "this Russia thing" when he made the decision.

He also publicly chastised Andrew McCabe, who became the acting director of the FBI after Comey was dismissed. Trump accused McCabe, who was fired in March 2018, of misleading investigators at the Justice Department. The Justice Department inspector general concluded in 2018 that McCabe "lacked candor" when discussing the disclosure of information for a Wall Street Journal article about the FBI's Clinton Foundation investigation. McCabe, who is a CNN contributor, has said he never intentionally misled anyone.

Last week, CNN reported that some federal law enforcement officials are warning of a chilling effect inside the FBI amid the attacks by Trump and Barr over the bureau's handling of the Russia investigation. Current and former FBI officials tell CNN they're concerned that the harsh rhetoric coming from Trump and Barr has only worsened the bureau's already tenuous standing with the President, leaving them wondering whether federal agents could be less aggressive the next time they have to pursue a sensitive investigation.