Holger's Java API

## com.antelmann.servlet
Class UserAuthenticationFilter

    java.lang.Object
      com.antelmann.servlet.UserAuthenticationFilter

All Implemented Interfaces:
  LoggerProvider, javax.servlet.Filter

    public class UserAuthenticationFilter

extends Object
implements javax.servlet.Filter, LoggerProvider

makes it easy to delegate from `WebFilter` instances for user authentication

Since:
  11.08.2013, 03:04:23
Author:
  holger

Field Summary
`protected PatternExtractor<? super javax.servlet.ServletRequest,Object>` `accessRightExtractor`
`protected Filter<String>` `ipFilter`
`protected Logger` `logger`
`protected Handler<javax.servlet.ServletResponse,? extends IOException>` `notAllowedHandler`
`protected String` `passwordKey`
`protected String` `realm`
`protected UserLoginStore` `uls`
`protected boolean` `useHahsedPassword`
`protected boolean` `useHeader`
`protected boolean` `useParams`
`protected String` `userKey`
`protected String` `userRequestAttribute`
`protected String` `userSessionAttribute`

Constructor Summary
`UserAuthenticationFilter(UserLoginStore uls, Filter<? super User> userFilter)`

Method Summary
`void` `applyUser(javax.servlet.ServletRequest request, User user)`
`void` `destroy()` empty implementation
`void` `doFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.FilterChain chain)`
`Logger` `getLogger()` acess to the (non-null) Logger suitable for logging entries in the context of this instance
`Filter<? super User>` `getUserFilter()`
`User` `getUserFor(javax.servlet.ServletRequest request)`
`void` `init(javax.servlet.FilterConfig fConfig)` empty implementation
`boolean` `isUseHahsedPassword()`
`boolean` `isUseHeader()`
`boolean` `isUseParams()`
`protected void` `sendNotAllowed(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response)`
`void` `setIpFilter(Filter<String> ipFilter)`
`void` `setNotAllowedHandler(Handler<javax.servlet.ServletResponse,? extends IOException> notAllowedHandler)` when the handler is called, the request will be given as the callback source
`UserAuthenticationFilter` `setParameterKeys(String userKey, String passwordKey)` defaults to 'user' and 'password'
`void` `setRealm(String realm)`
`void` `setUseHahsedPassword(boolean useHahsedPassword)`
`void` `setUseHeader(boolean useHeader)`
`void` `setUseParams(boolean useParams)`
`void` `setUserFilter(Filter<? super User> userFilter)`
`void` `setUserRequestAttribute(String userAttributeKey)` if set to a non-null value, the user will be put into each request
`void` `setUserSessionAttribute(String userSessionAttribute)` if set to a non-null value, the user will be put into the session

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### uls

    protected final UserLoginStore uls

### realm

    protected String realm

### userRequestAttribute

    protected String userRequestAttribute

### userSessionAttribute

    protected String userSessionAttribute

### userKey

    protected String userKey

### passwordKey

    protected String passwordKey

### ipFilter

    protected Filter<String> ipFilter

### logger

    protected final Logger logger

### notAllowedHandler

    protected Handler<javax.servlet.ServletResponse,? extends IOException> notAllowedHandler

### useHeader

    protected boolean useHeader

### useParams

    protected boolean useParams

### useHahsedPassword

    protected boolean useHahsedPassword

### accessRightExtractor

    protected PatternExtractor<? super javax.servlet.ServletRequest,Object> accessRightExtractor

Constructor Detail

### UserAuthenticationFilter

    public UserAuthenticationFilter(UserLoginStore uls,
                                    Filter<? super User> userFilter)

Method Detail

### getUserFilter

    public Filter<? super User> getUserFilter()

### setUserFilter

    public void setUserFilter(Filter<? super User> userFilter)

### getLogger

    public Logger getLogger()

  Description copied from interface: `LoggerProvider`
  acess to the (non-null) Logger suitable for logging entries in the context of this instance

  Specified by:
    `getLogger` in interface `LoggerProvider`

### isUseHeader

    public boolean isUseHeader()

### setUseHeader

    public void setUseHeader(boolean useHeader)

### isUseParams

    public boolean isUseParams()

### setUseParams

    public void setUseParams(boolean useParams)

### isUseHahsedPassword

    public boolean isUseHahsedPassword()

### setUseHahsedPassword

    public void setUseHahsedPassword(boolean useHahsedPassword)

### setRealm

    public void setRealm(String realm)

  Parameters:
    `realm` - the realm for BasicAuth or null if you do not want to use BasicAuth

### setParameterKeys

    public UserAuthenticationFilter setParameterKeys(String userKey,
                                                     String passwordKey)

  defaults to 'user' and 'password'

  Parameters:
    `userKey` - set this to null if you don't want to use parameter based authentication

### setUserRequestAttribute

    public void setUserRequestAttribute(String userAttributeKey)

  if set to a non-null value, the user will be put into each request

### setUserSessionAttribute

    public void setUserSessionAttribute(String userSessionAttribute)

  if set to a non-null value, the user will be put into the session

### setNotAllowedHandler

    public void setNotAllowedHandler(Handler<javax.servlet.ServletResponse,? extends IOException> notAllowedHandler)

  when the handler is called, the request will be given as the callback source

### setIpFilter

    public void setIpFilter(Filter<String> ipFilter)

### init

    public void init(javax.servlet.FilterConfig fConfig)
              throws javax.servlet.ServletException

  empty implementation

  Specified by:
    `init` in interface `javax.servlet.Filter`
  Throws:
    `javax.servlet.ServletException`

### destroy

    public void destroy()

  empty implementation

  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

  Specified by:
    `doFilter` in interface `javax.servlet.Filter`
  Throws:
    `IOException`
    `javax.servlet.ServletException`

### getUserFor

    public User getUserFor(javax.servlet.ServletRequest request)
                    throws DatabaseException

  Throws:
    `DatabaseException`

### applyUser

    public void applyUser(javax.servlet.ServletRequest request,
                          User user)

### sendNotAllowed

    protected void sendNotAllowed(javax.servlet.ServletRequest request,
                                  javax.servlet.ServletResponse response)
                           throws IOException,
                                  javax.servlet.ServletException

  Throws:
    `IOException`
    `javax.servlet.ServletException`

(c) Holger Antelmann since 2001- all rights reserved (contact: info@antelmann.com)
see www.antelmann.com/developer for further details and available downloads