Interface Authenticator


  • @Deprecated(since="2015")
    public interface Authenticator
    Deprecated.
    Use Apache Sling's org.apache.sling.auth.core package instead.
    The Authenticator interface defines the service interface of the authenticator used by the Sling engine. This service provides a method to find an AuthenticationHandler and call its requestAuthentication or dropAuthentication methods.

    This service is used by applications which want to provide functionality to their users to log into the application and log out from it.

    A very simple login script (using ESP here) could be implemented like this:

      var auth = sling.getService(org.apache.sling.commons.auth.Authenticator);
      if (auth != null) {
          try {
              auth.login(request, response);
              return; // we are done here
          } catch (e) {
              // probably no AuthenticationHandler available
          }
      }
      // Authenticator service is missing or no AuthenticationHandler
      ... do whatever you want to for error handling ...
      

    Likewise implementing a logout script (ESP, too) is equally simple:

      if (request.authType) {
          // not logged in at all, no need to logout
      } else {
          var auth = sling.getService(org.apache.sling.commons.auth.Authenticator);
          if (auth != null) {
              auth.logout(request, response);
          } else {
              // handle the case of no Authenticator to logout with
          }
      }
      

    This interface is not intended to be implemented by applications but may be used to initiate the authentication process form a request processing servlet or script.