Package org.apache.wiki.ui

# Class WikiServletFilter

java.lang.Object
org.apache.wiki.ui.WikiServletFilter

All Implemented Interfaces:
  `javax.servlet.Filter`

Direct Known Subclasses:
  `WikiJSPFilter`

public class WikiServletFilter extends Object implements javax.servlet.Filter
Filter that verifies that the `Engine` is running, and sets the authentication status for the user's Session. Each HTTP request processed by this filter is wrapped by a `WikiRequestWrapper`. The wrapper's primary responsibility is to return the correct `userPrincipal` and `remoteUser` for authenticated JSPWiki users (whether authenticated by container or by JSPWiki's custom system). The wrapper's other responsibility is to incorporate JSPWiki built-in roles into the role-checking algorithm for `HttpServletRequest.isUserInRole(String)`. Just before the request is wrapped, the method `AuthenticationManager.login(HttpServletRequest)` executes; this method contains all of the logic needed to grab any user login credentials set by the container or by cookies.

## Field Summary

Fields
Modifier and Type
Field
Description
`protected Engine`
`m_engine`

## Constructor Summary

Constructors
Constructor
Description
`WikiServletFilter()`
Creates a Wiki Servlet Filter.

## Method Summary

Modifier and Type
Method
Description
`void`
`destroy()`
Destroys the WikiServletFilter.
`void`
`doFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.FilterChain chain)`
Checks that the Engine is running ok, wraps the current HTTP request, and sets the correct authentication state for the users's Session.
`protected Context`
`getWikiContext(javax.servlet.ServletRequest request)`
Figures out the wiki context from the request.
`void`
`init(javax.servlet.FilterConfig config)`
Initializes the WikiServletFilter.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### m_engine

protected Engine m_engine

## Constructor Details

### WikiServletFilter

public WikiServletFilter()
Creates a Wiki Servlet Filter.

## Method Details

### init

public void init(javax.servlet.FilterConfig config) throws javax.servlet.ServletException
Initializes the WikiServletFilter.

Specified by:
  `init` in interface `javax.servlet.Filter`
Parameters:
  `config` - The FilterConfig.
Throws:
  `javax.servlet.ServletException` - If a Engine cannot be started.

### destroy

public void destroy()
Destroys the WikiServletFilter.

Specified by:
  `destroy` in interface `javax.servlet.Filter`

### doFilter

public void doFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.FilterChain chain) throws IOException, javax.servlet.ServletException
Checks that the Engine is running ok, wraps the current HTTP request, and sets the correct authentication state for the users's Session. First, the method `AuthenticationManager.login(HttpServletRequest)` executes, which sets the authentication state. Then, the request is wrapped with a `WikiRequestWrapper`.

Specified by:
  `doFilter` in interface `javax.servlet.Filter`
Parameters:
  `request` - the current HTTP request object
  `response` - the current HTTP response object
  `chain` - The Filter chain passed down.
Throws:
  `javax.servlet.ServletException` - if `AuthenticationManager.login(HttpServletRequest)` fails for any reason
  `IOException` - If writing to the servlet response fails.

### getWikiContext

protected Context getWikiContext(javax.servlet.ServletRequest request)
Figures out the wiki context from the request. This method does not create the context if it does not exist.

Parameters:
  `request` - The request to examine
Returns:
  A valid WikiContext value (or null, if the context could not be located).