Each country in the Olympics has their own National Olympic Committee (NOC) that is responsible for assembling the team from their country.
Each sport in the Olympics is governed by an International Federation (IF) that is recognized by the International Olympic Committee (IOC) as governing that particular sport. For example, athletics (track and field) is governed by the International Association of Athletics Federations. The IF typically has affiliated National Federations (NF) in each country. These federations hold national and international competitions apart from the Olympics. The NF makes recommendations to the NOC as to who should represent their country in the Olympics.
The NOC then approves or disapproves of the recommendations and submits the applications for these athletes to the Organizing Committee of the Olympic Games (OCOG) for the current Games. The NOC can only submit applications for athletes that have been recommended by the NF. If it is a small country that does not have an NF for a sport, the NOC can submit athletes with the approval of the IF and the OCOG, but the IF must approve the athletes before they will be allowed in the Games.
The OCOG and the IOC have the right to refuse any entry they want from the games, for any reason.
All participants have to agree to abide by the Olympic rules and the World Anti-Doping Code.