Top Description Fields Constructors Methods
waffle.servlet

public Class NegotiateSecurityFilter

extends Object
implements Filter
Class Inheritance
All Implemented Interfaces
javax.servlet.Filter
Known Direct Subclasses
waffle.servlet.CorsAwareNegotiateSecurityFilter
Imports
java.io.IOException, java.lang.reflect.InvocationTargetException, java.security.Principal, java.util.Collections, .HashMap, .List, .Locale, .Map, javax.security.auth.Subject, javax.servlet.Filter, .FilterChain, .FilterConfig, .ServletException, .ServletRequest, .ServletResponse, javax.servlet.http.HttpServletRequest, .HttpServletResponse, .HttpSession, org.slf4j.Logger, .LoggerFactory, waffle.servlet.spi.SecurityFilterProvider, .SecurityFilterProviderCollection, waffle.util.AuthorizationHeader, .CorsPreFlightCheck, waffle.windows.auth.IWindowsAuthProvider, .IWindowsIdentity, .IWindowsImpersonationContext, .PrincipalFormat, waffle.windows.auth.impl.WindowsAuthProviderImpl

A Negotiate (NTLM/Kerberos) Security Filter.
Author
dblock[at]dblock[dot]org

Field Summary

Modifier and TypeField and Description
private boolean
allowGuestLogin

The allow guest login.

private IWindowsAuthProvider
auth

The auth.

private boolean
disableSSO

The disable SSO.

private boolean
excludeBearerAuthorization

The exclusion bearer authorization.

private boolean
excludeCorsPreflight

The exclusions cors pre flight.

private String[]
excludePatterns

The exclusion filter.

private boolean
impersonate

The impersonate.

private static final Logger
LOGGER

The Constant LOGGER.

private PrincipalFormat
principalFormat

The principal format.

private static final String
PRINCIPALSESSIONKEY

The Constant PRINCIPALSESSIONKEY.

private SecurityFilterProviderCollection
providers

The providers.

private PrincipalFormat
roleFormat

The role format.

private static Boolean
windows

The windows flag.

Constructor Summary

AccessConstructor and Description
public
NegotiateSecurityFilter()

Instantiates a new negotiate security filter.

Method Summary

Modifier and TypeMethod and Description
public void
destroy()

Overrides default javax.servlet.Filter.destroy.

Called by the web container to indicate to a filter that it is being taken out of service.

public void
doFilter(final ServletRequest
the ServletRequest object contains the client's request
sreq
,
final ServletResponse
the ServletResponse object contains the filter's response
sres
,
final FilterChain
the FilterChain for invoking the next filter or the resource
chain
)

Implements javax.servlet.Filter.doFilter.

The doFilter method of the Filter is called by the container each time a request/response pair is passed through the chain due to a client request for a resource at the end of the chain.
private boolean

Returns:

True if a user already authenticated.
doFilterPrincipal
(final HttpServletRequest
HTTP request.
request
,
final HttpServletResponse
HTTP response.
response
,
final FilterChain
Filter chain.
chain
)

Filter for a previously logged on user.

public IWindowsAuthProvider

Returns:

IWindowsAuthProvider.
getAuth
()

Windows auth provider.

public PrincipalFormat

Returns:

Principal format.
getPrincipalFormat
()

Principal format.

public SecurityFilterProviderCollection

Returns:

A collection of security filter providers.
getProviders
()

Security filter providers.

public PrincipalFormat

Returns:

Role format.
getRoleFormat
()

Principal format.

public void
init(final FilterConfig
a FilterConfig object containing the filter's configuration and initialization parameters
filterConfig
)

Overrides default javax.servlet.Filter.init.

Called by the web container to indicate to a filter that it is being placed into service.

public boolean

Returns:

True if guest login is allowed, false otherwise.
isAllowGuestLogin
()

True if guest login is allowed.

public boolean

Returns:

true if impersonation is enabled, false otherwise
isImpersonate
()

Checks if is impersonate.

private static boolean
private void
sendUnauthorized(final HttpServletResponse
HTTP Response
response
,
final boolean
Close connection.
close
)

Send a 401 Unauthorized along with protocol authentication headers.

public void
setAuth(final IWindowsAuthProvider
Class implements IWindowsAuthProvider.
provider
)

Set Windows auth provider.

public void
setImpersonate(final boolean
true to enable impersonation, false otherwise
value
)

Enable/Disable impersonation.

public void
setPrincipalFormat(final String
Principal format.
format
)

Set the principal format.

public void
setRoleFormat(final String
Role format.
format
)

Set the principal format.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

allowGuestLoginback to summary
private boolean allowGuestLogin

The allow guest login.

authback to summary
private IWindowsAuthProvider auth

The auth.

disableSSOback to summary
private boolean disableSSO

The disable SSO.

excludeBearerAuthorizationback to summary
private boolean excludeBearerAuthorization

The exclusion bearer authorization.

excludeCorsPreflightback to summary
private boolean excludeCorsPreflight

The exclusions cors pre flight.

excludePatternsback to summary
private String[] excludePatterns

The exclusion filter.

impersonateback to summary
private boolean impersonate

The impersonate.

LOGGERback to summary
private static final Logger LOGGER

The Constant LOGGER.

principalFormatback to summary
private PrincipalFormat principalFormat

The principal format.

PRINCIPALSESSIONKEYback to summary
private static final String PRINCIPALSESSIONKEY

The Constant PRINCIPALSESSIONKEY.

providersback to summary
private SecurityFilterProviderCollection providers

The providers.

roleFormatback to summary
private PrincipalFormat roleFormat

The role format.

windowsback to summary
private static Boolean windows

The windows flag.

Constructor Detail

NegotiateSecurityFilterback to summary
public NegotiateSecurityFilter()

Instantiates a new negotiate security filter.

Method Detail

destroyback to summary
public void destroy()

Overrides default javax.servlet.Filter.destroy.

Doc from javax.servlet.Filter.destroy.

Called by the web container to indicate to a filter that it is being taken out of service.

This method is only called once all threads within the filter's doFilter method have exited or after a timeout period has passed. After the web container calls this method, it will not call the doFilter method again on this instance of the filter.

This method gives the filter an opportunity to clean up any resources that are being held (for example, memory, file handles, threads) and make sure that any persistent state is synchronized with the filter's current state in memory.

Annotations
@Override
doFilterback to summary
public void doFilter(final ServletRequest sreq, final ServletResponse sres, final FilterChain chain) throws IOException, ServletException

Implements javax.servlet.Filter.doFilter.

Doc from javax.servlet.Filter.doFilter.

The doFilter method of the Filter is called by the container each time a request/response pair is passed through the chain due to a client request for a resource at the end of the chain. The FilterChain passed in to this method allows the Filter to pass on the request and response to the next entity in the chain.

A typical implementation of this method would follow the following pattern:

  1. Examine the request
  2. Optionally wrap the request object with a custom implementation to filter content or headers for input filtering
  3. Optionally wrap the response object with a custom implementation to filter content or headers for output filtering
    • Either invoke the next entity in the chain using the FilterChain object (chain.doFilter()),
    • or not pass on the request/response pair to the next entity in the filter chain to block the request processing
  4. Directly set headers on the response after invocation of the next entity in the filter chain.
Parameters
sreq:ServletRequest

the ServletRequest object contains the client's request

sres:ServletResponse

the ServletResponse object contains the filter's response

chain:FilterChain

the FilterChain for invoking the next filter or the resource

Annotations
@Override
Exceptions
IOException:
if an I/O related error has occurred during the processing
ServletException:
if an exception occurs that interferes with the filter's normal operation
doFilterPrincipalback to summary
private boolean doFilterPrincipal(final HttpServletRequest request, final HttpServletResponse response, final FilterChain chain) throws IOException, ServletException

Filter for a previously logged on user.

Parameters
request:HttpServletRequest

HTTP request.

response:HttpServletResponse

HTTP response.

chain:FilterChain

Filter chain.

Returns:boolean

True if a user already authenticated.

Exceptions
IOException:
Signals that an I/O exception has occurred.
ServletException:
the servlet exception
getAuthback to summary
public IWindowsAuthProvider getAuth()

Windows auth provider.

Returns:IWindowsAuthProvider

IWindowsAuthProvider.

getPrincipalFormatback to summary
public PrincipalFormat getPrincipalFormat()

Principal format.

Returns:PrincipalFormat

Principal format.

getProvidersback to summary
public SecurityFilterProviderCollection getProviders()

Security filter providers.

Returns:SecurityFilterProviderCollection

A collection of security filter providers.

getRoleFormatback to summary
public PrincipalFormat getRoleFormat()

Principal format.

Returns:PrincipalFormat

Role format.

initback to summary
public void init(final FilterConfig filterConfig) throws ServletException

Overrides default javax.servlet.Filter.init.

Doc from javax.servlet.Filter.init.

Called by the web container to indicate to a filter that it is being placed into service.

The servlet container calls the init method exactly once after instantiating the filter. The init method must complete successfully before the filter is asked to do any filtering work.

The web container cannot place the filter into service if the init method either

  1. Throws a ServletException
  2. Does not return within a time period defined by the web container
Parameters
filterConfig:FilterConfig

a FilterConfig object containing the filter's configuration and initialization parameters

Annotations
@Override
Exceptions
ServletException:
if an exception has occurred that interferes with the filter's normal operation
isAllowGuestLoginback to summary
public boolean isAllowGuestLogin()

True if guest login is allowed.

Returns:boolean

True if guest login is allowed, false otherwise.

isImpersonateback to summary
public boolean isImpersonate()

Checks if is impersonate.

Returns:boolean

true if impersonation is enabled, false otherwise

isWindowsback to summary
private static boolean isWindows()
sendUnauthorizedback to summary
private void sendUnauthorized(final HttpServletResponse response, final boolean close)

Send a 401 Unauthorized along with protocol authentication headers.

Parameters
response:HttpServletResponse

HTTP Response

close:boolean

Close connection.

setAuthback to summary
public void setAuth(final IWindowsAuthProvider provider)

Set Windows auth provider.

Parameters
provider:IWindowsAuthProvider

Class implements IWindowsAuthProvider.

setImpersonateback to summary
public void setImpersonate(final boolean value)

Enable/Disable impersonation.

Parameters
value:boolean

true to enable impersonation, false otherwise

setPrincipalFormatback to summary
public void setPrincipalFormat(final String format)

Set the principal format.

Parameters
format:String

Principal format.

setRoleFormatback to summary
public void setRoleFormat(final String format)

Set the principal format.

Parameters
format:String

Role format.