java.lang.Object
net.i2p.servlet.filters.AuthFilter
All Implemented Interfaces:
Filter

public class AuthFilterextends Object implements Filter
Filter to check for valid session on all console requests. Redirects to login page if not authenticated.
  • Field Details

    • _log

      private static final Log _log
      Logger for the authentication filter.
    • PROP_AUTH_TYPE

      private static final String PROP_AUTH_TYPE
      Config key for the authentication type.
      See Also:
    • AUTH_TYPE_CUSTOM

      private static final String AUTH_TYPE_CUSTOM
      Auth type value selecting the custom handler.
      See Also:
    • PROP_PW_ENABLE

      private static final String PROP_PW_ENABLE
      Config key enabling the password authentication.
      See Also:
    • PROP_ENFORCE_LOGIN

      private static final String PROP_ENFORCE_LOGIN
      Config key requiring the login for every page.
      See Also:
    • DEFAULT_THEME

      private static final String DEFAULT_THEME
      Theme used when none is configured.
      See Also:
    • PUBLIC_PATHS

      private static final Set<String> PUBLIC_PATHS
      The paths that need no authentication.
    • PUBLIC_FILES

      private static final Set<String> PUBLIC_FILES
      The files that need no authentication.
  • Constructor Details

    • AuthFilter

      public AuthFilter()
      Create an instance; the servlet container calls this with no arguments.
  • Method Details

    • init

      public void init(FilterConfig filterConfig) throws ServletException
      Specified by:
      init in interface Filter
      Throws:
      ServletException
    • doFilter

      public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException
      Specified by:
      doFilter in interface Filter
      Throws:
      IOException
      ServletException
    • isPublicPath

      private boolean isPublicPath(String path)
      Checks whether a path needs no authentication.
      Parameters:
      path - the request path
      Returns:
      true if the path is public
    • getActiveTheme

      private String getActiveTheme()
      Reads the theme in use now.
      Returns:
      the theme name
    • hasAnyPassword

      private boolean hasAnyPassword(RouterContext ctx)
      Checks whether any console password is set.
      Parameters:
      ctx - the router context
      Returns:
      true if a password exists
    • getSessionCookie

      private String getSessionCookie(HttpServletRequest req)
      Returns the session cookie of the request.
      Parameters:
      req - the request to check
      Returns:
      the session id, null if absent
    • authenticateBasicAuth

      private String authenticateBasicAuth(HttpServletRequest req, HttpServletResponse resp, RouterContext ctx)
      Authenticates the basic auth header of the request.
      Parameters:
      req - the request to authenticate
      resp - the response to send the challenge to
      ctx - the router context
      Returns:
      the user name, null if the credentials fail
    • createSessionAndSetCookie

      private String createSessionAndSetCookie(HttpServletRequest req, HttpServletResponse resp, String username)
      Creates a login session and sends its cookie.
      Parameters:
      req - the request to log in
      resp - the response to set the cookie on
      username - the user to log in
      Returns:
      the user name of the session
    • destroy

      public void destroy()
      Specified by:
      destroy in interface Filter