The FBI says it caught a terrorist trying to blow up a synagogue on the outskirts of Miami.

But the FBI supplied the bomb.

The device was fake, part of an undercover FBI sting operation that, like hundreds of controversial investigations before it, used an undercover informant to target an alleged terrorist.

In the Miami case, federal authorities accuse 40-year-old James Medina of planning to bomb the Aventura Turnberry Jewish Center north of the city.

The FBI started their investigation of Medina in March 2015 "based on his suspected desire to attack" the Jewish center, according to an affidavit filed in federal court and a statement released by the US Attorney's Office in the Southern District of Florida.

Medina, who said he converted to Islam four years ago and referred to his alias "James Muhammad" in court, has been charged with "attempted use of a weapon of mass destruction." He pleaded not guilty on Monday morning.

Apart from the fact that the FBI supplied Medina with the weapon that he intended to use against the Jewish center, rights activists and legal experts are troubled by the facts presented by the FBI and Justice Department. Their concern includes instances where the informant, or "confidential human source" in bureau parlance, offered to assist Medina in attacking the center, and even suggested that he link the attack to the Islamic State.

The FBI's affidavit — which reveals only enough information to justify the criminal complaint against Medina, and does not include all of the evidence against him — says that an informant met with Medina in March and secretly recorded conversations with him after he expressed a desire to attack the Jewish center.

But the affidavit does not say how the FBI learned of Medina's "suspected desire" to attack the Jewish center, or what initial remarks or actions led agents to believe that Medina was willing to use violence before he devised his plans with the informant.

David Shapiro, a former New Jersey prosecutor and FBI special agent who is now a professor at the John Jay College of Criminal Justice in New York, said the affidavit makes it appear that the FBI did more than a little pushing to get Medina to develop the synagogue bombing plan.

"It seems this desire was developed," he said. "It was watered with very potent fertilizer."

The affidavit lays out how the FBI informant took an active part in helping Medina cook up the bombing plot. It recounts how the informant drove Medina to the Jewish center and suggested that he launch the attack on a Jewish holiday.

When the two later discussed a claim of responsibility, the affidavit says that the informant "indicated that they should leave a 'clue' as to who was responsible and Medina concurred." It's the informant, rather than Medina, who suggests linking the bombing to the Islamic State, also known as ISIS, or the East African al-Qaeda affiliate al-Shabaab.

"You can, you can do all that," the affidavit quotes Medina as saying. "Yeah, we can print up or something and make it look like it's ISIS here in America. Just like that."

'Today is gonna be a day where Muslims attack America. I'm going to set a bomb in Aventura.'

The informant later suggested that Medina could use "untraceable" firearms instead of AK-47s that an acquaintance of Medina's said he could provide. At another meeting, the informant "addressed the concerns of entering the synagogue with firearms and then getting shot and instead proposed leaving an unspecified object behind and leaving the scene." The informant suggested that Medina could use a bomb with a timer, and then introduced Medina to a man described as having "explosives expertise and access." The bomb expert was really an undercover FBI agent.

Medina didn't do himself any favors by repeatedly telling both the FBI informant and undercover agent that he was willing to leave the bomb at the synagogue, then escape with the informant and watch as they remotely detonated it. He also repeatedly assured the undercover agent that he was willing to go forward with the plot, according to the affidavit.

When asked why, Medina answers, "Because I realize that I have a lot of love for Allah. And I know that all these, all these wars that are going on, it hurts me, too. You know? It's my call of duty. I gotta get back, when I'm doing this, I feel that I'm doing it for a good cause for Allah."

In a subsequent conversation, the agent asked Medina if he was okay with killing women and children. Medina appeared to say yes, but he also seemed hesitant.

Medina: I think so. I think I'm fine, Urn hmm.

Agent: You need to be sure brother.

Medina: I am pretty sure. I think so. I believe so. I'm ready bro!

Agent: Ok. Cause you know you don't have to do any of this.

Medina: What do you mean doing it?

Agent: No, you don't have to do it if you're not comfortable with it.

Medina: What? I'm ready.

Agent: It's Allah's will but you know...

Medina: I'm up for it. I really am. This is no joke. This is serious dog. If I have the equipment, believe me, in the time is, is that day and we doin' it, I'm up for it bro. Just like I said.

The FBI says Medina and the undercover agent decided to bomb the synagogue on Friday, April 29. Medina made three videos on the informant's phone: One as a goodbye to his family in case he was killed, and the other two to explain why he conducted the attack.

"I am a Muslim and I don't like what is going on in this world. I'm going to handle business here in America. Aventura, watch your back. ISIS is in the house," he said in one video. In another, he said, "Today is gonna be a day where Muslims attack America. I'm going to set a bomb in Aventura."

On the appointed day, the agent met with Medina, gave him the fake bomb, instructed him how to use it, and then drove him to the synagogue. Medina exited the vehicle and began to walk toward the synagogue, at which point the authorities arrested him.

The US government has convicted more than 200 people on terrorism-related charges using similar methods, according to Trevor Aaronson, executive director of the Florida Center for Investigative Reporting and author of The FBI's Manufactured War on Terrorism. He said that the FBI "isn't finding people with a bomb in their garage. They're finding people who are loudmouths and they say, "Oh, we can help you in the name of al-Qaeda or the Islamic State."

"These are sting operations where the FBI provides the means and opportunities for people to commit crimes," Aaronson said. "And the most disturbing part is that most of these people seem to be mentally ill and do not have connections to overseas terrorists on their own."

Medina fits this profile. The 40-year-old is divorced, single, and unemployed. He was arrested previously for behavior consistent with mental illness, including sending more than 50 text messages, some threatening violence, to his estranged family and then telling a cop about it.

Karen J. Greenberg, director of the Center on National Security at Fordham Law School, said the quoted conversations in the affidavit that are supposed to damn Medina instead make it look like he can "barely seem to string a sentence together."

And while it appears to be clear that Medina is a bigot who harbors anti-Jewish feelings, neither of those two things is illegal. Of course, plotting to blow up a synagogue is illegal. Retired FBI counterterrorism executive David Gomez says the FBI's investigative techniques were legitimate, even if Medina does have mental or cognitive issues.

"Just because you're dumb doesn't mean you're not dangerous," he said. "Just because you have some mental incapacitation doesn't mean you're not capable of murder."

'These are sting operations where the FBI provides the means and opportunities for people to commit crimes. And the most disturbing part is that most of these people seem to be mentally ill.'

Gomez said he's seen other cases where lonely, fringe suspects join gangs or right-wing extremist groups to gain approval, and then peer pressure or other factors leads them to commit violent acts. In cases such as Medina's, he argued, the FBI is just getting to these suspects before other malicious actors.

"Let's say we didn't get a source on this person, and somebody else talks to them and says, 'Wanna blow up some Jews?' It doesn't matter if you blow them up for the KKK or ISIS. Some guy says, 'I'll drive you there,' and there are plenty of people out there who would do that," Gomez said. "The FBI and others are worried about a guy who gets in with the wrong crowd."

Greenberg questioned where the rationale for this type of investigation ends.

"If you want to look for individuals who are susceptible to some kind of inducement to violence, and who have to be told whose name the violence is in, there are countless people and countless extremist groups you could identify them with," she said.

Gomez said that the FBI's informants and undercover agents set up the suspect for the "next proactive move," but don't make them take it.

"At some point he has to have an overt act," he said — such as taking what he thinks is a bomb onto the grounds of a synagogue with the intent to detonate it.

Under the law, this act essentially closes the door to an entrapment defense.

"Those are hard to assert in this situation," said Hugh Handeyside, a staff attorney with the American Civil Liberties Union's National Security Project. "That's the situation that the FBI and DOJ are taking advantage of."

According to Greenberg, the FBI has been using these types of investigations to send a message: "If someone approaches you and asks you if want help with a terrorist attack, you're supposed to say no."

Watch the VICE News video _What It's Really Like to Fight for the Islamic State_**:**

Gomez notes that since 9/11, the bureau has been tasked with preventing another terrorist attack on US soil.

"The attitude is, do what you have to legally do to prevent a Paris-style attack in the US," he said, "and I think there are a lot of prosecutors out there who would say, 'I would rather prosecute a case and take the chance on losing on technicality or jury nullification than take a chance to not prosecute on terrorism charges."

But most terrorism cases do not go to trial, meaning prosecutors rarely lose. Most defense lawyers encourage their clients to enter into a plea agreement in order to avoid a lengthy prison sentence.

"The threat of long-term incarceration compels people to cut their losses," said Michael German, a former FBI agent who worked on undercover domestic terrorism investigations. "Part of reason they're encouraged to cut losses is that when these cases go to trial, despite the judges expressing concerns about FBI methodology, the political and social climate is such that fear actually compels them to not acquit people based on entrapment or other government misconduct."

The FBI declined to comment on the Medina case or other counterterrorism investigations like it, but said in a statement that there are "strict guidelines governing the use of undercover operations which involve extensive legal reviews and senior-level approvals."

The bureau's director, James B. Comey, told Congress in February that "preventing terrorist attacks remains the FBI's top priority" as he requested more than $9 billion to fund the bureau's operations in 2017.

Nearly half of the FBI's 2016 budget was committed to "counterterrorism and counterintelligence" operations, along with more than 13,000 members of the bureau's 35,000 employees.

According to German, the funding means the FBI is under pressure to show Congress that it's using its resources to stop terror attacks.

"Is there actually a threat being resolved, or is the FBI manufacturing these terrorism cases to make its counterterrorism efforts look worthwhile?" he asked. "Knowing that there are real threats out there, are they wasting resources when the people they're targeting don't present an immediate threat?"

Handeyside said counterterrorism cases like Medina's are not only a waste of resources, they might actually be making America less safe.

"It's not only that they're manufacturing terror plots, but also sowing fear and distrust within minority communities in ways that I think are damaging to counterterrorism efforts," he said. "So there are not only constitutional issues, but also effectiveness issues."

Follow Benjamin Gilbert on Twitter: @__benrgilbert