Psalm 27 is nestled securely within the traditionally numbered Book 1 of the Psalms (1-41) and is attributed to David, the second King of Israel. Even a cursory reading of the text fits well with the portrait the Bible offers of David and lends substantial credibility to his authorship; it is confident, bold, pious, and fearless in declarations of faith; but also questioning, pleading, seeking reassurance.
The content and tone of the psalm suggest the poet-king wrote these words in the midst of circumstances during which his leadership, perhaps his very life, were under significant challenge. Despite such troubles, David ultimately remains steadfast in faith and confident that the Lord will see him through to victory over those opposing him. The Lord will guide the shepherd-warrior-become-ruler to prosper in that which he undertakes to do.