Ubaydullah bin Abi Yazid said: I heard Abdullah bin Abbas (may Allah be pleased with them both): when he was asked about something and it was in the Qur'an, he would rule according to it. If it was not in the Qur'an, he would rule in accordance with the Sunnah of the Messenger (peace and blessings be upon him). If it was in neither the Qur'an nor said by the Messenger of Allah (peace and blessings be upon him), but Abu Bakr and Umar (may Allah be pleased with them both) had said it, he would adopt it; otherwise he would exercise his own judgement (ijtihad).
Hadith Referenceالسنن الكبرى للبيهقي / كتاب آداب القاضي / 20346