7 But let us distinguish God's different ways of hearing prayer. For we find some not heard for their wish, heard for salvation: and again some we find heard for their wish, not heard for salvation. Mark this difference, hold fast this example of a man not heard for his wish but heard for salvation. Hear the apostle Paul; for what is the hearing of prayer unto salvation, God Himself showed him: “Sufficient for you,” says He, “is my grace; for strength is perfected in weakness.”
You have besought, hast cried, hast thrice cried: the very cry you raised once for all I heard, I turned not away my ears from you; I know what I should do: you would have it taken away, the healing thing by which you are burned; I know the infirmity by which you are burdened. Well then: here is a man who was heard for salvation, while as to his will he was not heard. Where find we persons heard for their will, not heard for salvation? Do we find, think we, some wicked, some impious man, heard of God for his will, not heard for salvation?
If I put to you the instance of some man, perchance you will say to me, “It is you that callest him wicked, for he was righteous; had he not been righteous, his prayer would not have been heard by God.” The instance I am about to allege is of one, of whose iniquity and impiety none can doubt. The devil himself: he asked for Job, and received. Have ye not here also heard concerning the devil, that “he that commits sin is of the devil”? Not that the devil created, but that the sinner imitates.
Is it not said of him, “He stood not in the truth”? Is not even he “that old serpent,” who, through the woman pledged the first man in the drink of poison? Who even in the case of Job, kept for him his wife, that by her the husband might be, not comforted, but tempted? The devil asked for a holy man, to tempt him; and he received: the apostle asked that the thorn in the flesh might be taken from him, and he received not. But the apostle was more heard than the devil. For the apostle was heard for salvation, though not for his wish: the devil was heard for his wish, but for damnation.
For that Job was yielded up to him to be tempted, was in order that by his standing the proof the devil should be tormented. But this, my brethren, we find not only in the Old Testament books, but also in the Gospel. The demons besought the Lord, when He expelled them from the man, that they might be permitted to go into the swine. Should the Lord not have power to tell them not to approach even those creatures? For, had it not been His will to permit this, they were not about to rebel against the King of heaven and earth.
But with a view to a certain mystery, with a certain ulterior meaning, He let the demons go into the swine: to show that the devil has dominion in them that lead the life of swine. Demons then were heard in their request; was the apostle not heard? Or rather (what is truer) shall we say, The apostle was heard, the demons not heard? Their will was effected; his good was perfected.
Source: Homilies on the First Epistle of John (New Advent)