aemaem-6

Are multiple implementations of AuthenticationInfoPostProcessor supported?


Working in AEM 6.4 and in process of migrating to 6.5, can i have multiple classes that extend AuthenticationInfoPostProcessor?

I can't find anything in the docs about this.

Any help would be great,


Solution

  • Yes, multiple implementations are supported. Note that each will be invoked (in no specific order) so you will need to have each implementation only process the applicable logins.

    e.g. Suppose you want to have two websites in AEM protected by two distinct postProcess implementations. Consider something like this:

    public abstract class AbstractAuthenticationPostProcessor implements AuthenticationInfoPostProcessor {
      protected PostProcessorHandler getHandler(HttpServletRequest request) {
        String path = request.getRequestURI();
    
        if (path.startsWith("/content/siteA") {
          return PostProcessorHandler.SiteA;
        }
        if (path.startsWith("/content/siteB") {
          return PostProcessorHandler.SiteB;
        }
        return PostProcessorHandler.None
      }
    
      protected enum PostProcessorHandler {
          SiteA,
          SiteB,
          None
      }
    }
    

    Then in each of the implementations of the postprocessors do this:

    public class SiteAPostProcessor extends AbstractAuthenticationPostProcessor {
      @Override
      public void postProcess(
        AuthenticationInfo authenticationInfo,
        HttpServletRequest request,
        HttpServletResponse response) {
    
        if (getHandler(request) != AuthenticationHandler.SiteA) {
            return;
        }
    
        // do post login tasks
      }
    }