java.lang.Object
net.i2p.servlet.filters.AuthFilter
- All Implemented Interfaces:
Filter
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final LogLogger for the authentication filter.private static final StringAuth type value selecting the custom handler.private static final StringTheme used when none is configured.private static final StringConfig key for the authentication type.private static final StringConfig key requiring the login for every page.private static final StringConfig key enabling the password authentication.The files that need no authentication.The paths that need no authentication.Constructor Summary
ConstructorsConstructorDescriptionCreate an instance; the servlet container calls this with no arguments.Method Summary
Modifier and TypeMethodDescriptionprivate StringauthenticateBasicAuth(HttpServletRequest req, HttpServletResponse resp, RouterContext ctx) Authenticates the basic auth header of the request.private StringcreateSessionAndSetCookie(HttpServletRequest req, HttpServletResponse resp, String username) Creates a login session and sends its cookie.voiddestroy()voiddoFilter(ServletRequest request, ServletResponse response, FilterChain chain) private StringReads the theme in use now.private StringReturns the session cookie of the request.private booleanChecks whether any console password is set.voidinit(FilterConfig filterConfig) private booleanisPublicPath(String path) Checks whether a path needs no authentication.
Field Details
_log
Logger for the authentication filter.PROP_AUTH_TYPE
Config key for the authentication type.- See Also:
AUTH_TYPE_CUSTOM
Auth type value selecting the custom handler.- See Also:
PROP_PW_ENABLE
Config key enabling the password authentication.- See Also:
PROP_ENFORCE_LOGIN
Config key requiring the login for every page.- See Also:
DEFAULT_THEME
Theme used when none is configured.- See Also:
PUBLIC_PATHS
PUBLIC_FILES
Constructor Details
AuthFilter
public AuthFilter()Create an instance; the servlet container calls this with no arguments.
Method Details
init
- Specified by:
initin interfaceFilter- Throws:
ServletException
doFilter
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException - Specified by:
doFilterin interfaceFilter- Throws:
IOExceptionServletException
isPublicPath
Checks whether a path needs no authentication.- Parameters:
path- the request path- Returns:
- true if the path is public
getActiveTheme
hasAnyPassword
Checks whether any console password is set.- Parameters:
ctx- the router context- Returns:
- true if a password exists
getSessionCookie
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 authenticateresp- the response to send the challenge toctx- 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 inresp- the response to set the cookie onusername- the user to log in- Returns:
- the user name of the session
destroy