Using AEM Sites 6.5, I have incorporated a custom authentication solution into my website. It revolves around MSAL (Microsoft Authentication Library) and asking users to login with their Microsoft accounts.
When intercepting requests, detecting that the user is not logged in, and asking them to login before a page is rendered- what is the real benefit / difference in handling this logic in an AuthenticationHandler as opposed to a Filter?
For instance, I am noticing that in a custom authentication handler, I can detect that the page requires login and the user isn't logged in- so I can send them to go login by manipulating the response and exiting. I can do similarly in a filter- if the request is for an authenticated area and the user isn't logged in, then I send them through the login flow.
What's the real benefit in doing this via one method or another? It seems the AuthenticationHandler should be responsible for extracting the user out of the request (e.g., via session cookie) and returning that to AEM... is it sketchy to have the AuthenticationHandler also issue 302 redirects to instruct the user to login?