Class EjwsBasicAuthenticator


public class EjwsBasicAuthenticator extends BasicAuthenticator
Implementation of BasicAuthenticator using either an in-memory table of user names and passwords or a user-supplied table.
  • Constructor Details

    • EjwsBasicAuthenticator

      public EjwsBasicAuthenticator(String realm)
      Constructor.
      Parameters:
      realm - the HTTP realm
    • EjwsBasicAuthenticator

      public EjwsBasicAuthenticator(String realm, Map<String,EjwsBasicAuthenticator.Entry> map)
      Constructor providing a map. A user-supplied map can be implemented so as to allow one to obtain passwords and roles from a database or some other form of persistent storage. If entries can be added while a server using this authenticator is running, the map should have a thread-safe implementation.
      Parameters:
      realm - the HTTP realm
      map - a map associating a user name with a table entry.
  • Method Details

    • setTracer

      public void setTracer(Appendable tracer)
      Set an Appendable for tracing. This method should be used only for debugging.
      Parameters:
      tracer - the Appendable for tracing requests and responses
    • setLoginFunction

      public void setLoginFunction(BiConsumer<EjwsPrincipal,HttpExchange> function)
      Set the login function. This function will be called using the current HttpExchange when a login is (a) successful and (b) the function is not null. It can be used to set headers or perform other operations as required by an application.

      The function will be called when the request URI matches a designated login URI, with the current EjwsPrincipal and HttpExchange as its arguments In any transaction, at most one of the login, logout, and authorized functions will be called.

      Parameters:
      function - the function; null to disable
      See Also:
    • setAuthorizedFunction

      public void setAuthorizedFunction(BiConsumer<EjwsPrincipal,HttpExchange> function)
      Set the authorized function. This function will be called when a request is authorized. Its arguments are a principal and the HTTP exchange. The later can be used to set cookies or perform other operations. In any transaction, at most one of the login, logout, and authorized functions will be called.
      Parameters:
      function - the 'authorized' function.
    • setLogoutFunction

      public void setLogoutFunction(BiConsumer<EjwsPrincipal,HttpExchange> function)
      Set the logout function. This function will be called using the current HttpExchange when a logout is (a) successful and (b) the function is not null. It can be used to set headers or perform other operations as required by an application.

      The function will be called when the request URI matches a designated logout URI, with the current EjwsPrincipal and HttpExchange as its arguments. The HttpExchange will be null if the login session has timed out. In any transaction, at most one of the login, logout, and authorized functions will be called.

      Parameters:
      function - the function; null to disable
      See Also:
    • add

      public void add(String username, String password) throws UnsupportedOperationException
      Add a user name and password for this authenticator's HTTP realm.
      Parameters:
      username - the user name
      password - the password
      Throws:
      UnsupportedOperationException - if the map does not allow entries to be added (the default map does not throw this exception)
    • add

      public void add(String username, String password, Set<String> roles) throws UnsupportedOperationException
      Add a user name, the user's password and the user's roles for this authenticator's HTTP realm.
      Parameters:
      username - the user name
      password - the user's password
      roles - the user's roles
      Throws:
      UnsupportedOperationException - if the map does not allow entries to be added (the default map does not throw this exception)
    • authenticate

      public Authenticator.Result authenticate(HttpExchange t)
      Overrides:
      authenticate in class BasicAuthenticator
    • checkCredentials

      public boolean checkCredentials(String username, String password)
      Check credentials. This method is called for each incoming request to verify the given name and password in the context of this Authenticator's realm.
      Specified by:
      checkCredentials in class BasicAuthenticator
      Parameters:
      username - the user name
      password - the password