For ordinary sins, the priest is supposed to deny absolution if there's no sign of contrition (see 1451-1454 here), especially when the sins are grave (mortal).
In case of excommunication, some can be lifted by any priest, some by an Ordinary (usually a bishop) or a priest appointed by an Ordinary, and some only by the pope or some priest appointed by him.
I have found some canon lawyery on this here. I can't confess I understand it fully, but I'll try to translate it: if the excommunication was explicitly declared, it can be lifted by the bishop who declared it (or someone appointed by him). If it's latae sententiae (strarted by a sin, not declared like abortion), it's under authority of the Ordinary of the diocesis where the excommunicated person lives. Priests without special authority can lift latae sententiae excommunication temporarily "if it is burdensome for the penitent to remain in the state of grave sin during the time necessary for the competent superior to make provision." I don't know what qualifies for "burdensome" here, whether it's almost automatic or just in rare situations like some known danger of death.