NAWA 0.9
Web Application Framework for C++
nawa::AccessFilter Class Reference

#include <nawa/filter/AccessFilter/AccessFilter.h>

Inherited by nawa::AuthFilter, nawa::BlockFilter, and nawa::ForwardFilter.

Public Member Functions

virtual ~AccessFilter ()
 
 AccessFilter ()
 
 AccessFilter (AccessFilter const &other)
 
AccessFilteroperator= (const AccessFilter &other)
 
 AccessFilter (AccessFilter &&other) noexcept
 
AccessFilteroperator= (AccessFilter &&other) noexcept
 
bool & invert () noexcept
 
bool invert () const noexcept
 
AccessFilterinvert (bool value) noexcept
 
std::vector< std::vector< std::string > > & pathFilter () noexcept
 
std::vector< std::vector< std::string > > const & pathFilter () const noexcept
 
AccessFilterpathFilter (std::vector< std::vector< std::string > > value) noexcept
 
bool & invertPathFilter () noexcept
 
bool invertPathFilter () const noexcept
 
AccessFilterinvertPathFilter (bool value) noexcept
 
std::vector< std::string > & extensionFilter () noexcept
 
std::vector< std::string > const & extensionFilter () const noexcept
 
AccessFilterextensionFilter (std::vector< std::string > value) noexcept
 
bool & invertExtensionFilter () noexcept
 
bool invertExtensionFilter () const noexcept
 
AccessFilterinvertExtensionFilter (bool value) noexcept
 
bool & regexFilterEnabled () noexcept
 
bool regexFilterEnabled () const noexcept
 
AccessFilterregexFilterEnabled (bool value) noexcept
 
std::regex & regexFilter () noexcept
 
std::regex const & regexFilter () const noexcept
 
AccessFilterregexFilter (std::regex value) noexcept
 
std::string & response () noexcept
 
std::string const & response () const noexcept
 
AccessFilterresponse (std::string value) noexcept
 
bool matches (std::vector< std::string > const &requestPath) const
 

Detailed Description

Defines a filter on the request path. Path filtering will be done first, then extension filtering, then regex filtering. In order to match, all enabled conditions must match (AND connector, use multiple filters for OR). Filters which are left empty will "match everything". A filter with no conditions will match everything.

Definition at line 38 of file AccessFilter.h.

Constructor & Destructor Documentation

◆ ~AccessFilter()

virtual nawa::AccessFilter::~AccessFilter ( )
virtual

◆ AccessFilter() [1/3]

nawa::AccessFilter::AccessFilter ( )

◆ AccessFilter() [2/3]

nawa::AccessFilter::AccessFilter ( AccessFilter const &  other)

◆ AccessFilter() [3/3]

nawa::AccessFilter::AccessFilter ( AccessFilter &&  other)
noexcept

Member Function Documentation

◆ operator=() [1/2]

AccessFilter & nawa::AccessFilter::operator= ( const AccessFilter other)

◆ operator=() [2/2]

AccessFilter & nawa::AccessFilter::operator= ( AccessFilter &&  other)
noexcept

◆ invert() [1/3]

bool & nawa::AccessFilter::invert ( )
noexcept

Negate the filter, i.e., the filter will match if none of the conditions apply (instead of all). This is particularly useful, for example, for defining a BlockFilter with a set of allowed URLs and send a 404 error page for everything else, or to apply authentication to everything except for a path.

Returns
Reference to element.

◆ invert() [2/3]

bool nawa::AccessFilter::invert ( ) const
noexcept

◆ invert() [3/3]

AccessFilter & nawa::AccessFilter::invert ( bool  value)
noexcept

◆ pathFilter() [1/3]

std::vector< std::vector< std::string > > & nawa::AccessFilter::pathFilter ( )
noexcept

For path filtering: A vector containing all paths to match. Each path shall be provided as a vector of strings containing all directory names under the web root (e.g., {"dir1", "dir2"} for /dir1/dir2/). If empty, path filtering will not be applied.

Returns
Reference to element.

◆ pathFilter() [2/3]

std::vector< std::vector< std::string > > const & nawa::AccessFilter::pathFilter ( ) const
noexcept

◆ pathFilter() [3/3]

AccessFilter & nawa::AccessFilter::pathFilter ( std::vector< std::vector< std::string > >  value)
noexcept

◆ invertPathFilter() [1/3]

bool & nawa::AccessFilter::invertPathFilter ( )
noexcept

Invert the path filtering condition, i.e., the condition applies when the request URI is outside of the specified paths.

Returns
Reference to element.

◆ invertPathFilter() [2/3]

bool nawa::AccessFilter::invertPathFilter ( ) const
noexcept

◆ invertPathFilter() [3/3]

AccessFilter & nawa::AccessFilter::invertPathFilter ( bool  value)
noexcept

◆ extensionFilter() [1/3]

std::vector< std::string > & nawa::AccessFilter::extensionFilter ( )
noexcept

For extension filtering: A list of file extensions (the part behind the last '.') to match. If empty, extension filtering will not be applied.

Returns
Reference to element.

◆ extensionFilter() [2/3]

std::vector< std::string > const & nawa::AccessFilter::extensionFilter ( ) const
noexcept

◆ extensionFilter() [3/3]

AccessFilter & nawa::AccessFilter::extensionFilter ( std::vector< std::string >  value)
noexcept

◆ invertExtensionFilter() [1/3]

bool & nawa::AccessFilter::invertExtensionFilter ( )
noexcept

Invert the extension filtering condition, i.e., the condition applies when a file has an extension which is not part of the given list of extensions.

Returns
Reference to element.

◆ invertExtensionFilter() [2/3]

bool nawa::AccessFilter::invertExtensionFilter ( ) const
noexcept

◆ invertExtensionFilter() [3/3]

AccessFilter & nawa::AccessFilter::invertExtensionFilter ( bool  value)
noexcept

◆ regexFilterEnabled() [1/3]

bool & nawa::AccessFilter::regexFilterEnabled ( )
noexcept

Regex filtering will be applied iff this value is set to true.
Please note that this filtering is very resource-intensive. Use it only if you cannot achieve your goal by using (possibly a combination of) the other filters. It makes sense to define a path and/or extension filter additionally, so that the regex is only checked if the path and/or extension preconditions are met.

Returns
Reference to element.

◆ regexFilterEnabled() [2/3]

bool nawa::AccessFilter::regexFilterEnabled ( ) const
noexcept

◆ regexFilterEnabled() [3/3]

AccessFilter & nawa::AccessFilter::regexFilterEnabled ( bool  value)
noexcept

◆ regexFilter() [1/3]

std::regex & nawa::AccessFilter::regexFilter ( )
noexcept

For regex filtering: A std::regex matching the paths to be filtered (in the form "/dir1/dir2/file.ext"). std::regex_match will be used for matching. If regexFilterEnabled is set to false, this value will be ignored. If regexFilterEnabled is set to true and the regex is not assigned, nothing will be matched.

Returns
Reference to element.

◆ regexFilter() [2/3]

std::regex const & nawa::AccessFilter::regexFilter ( ) const
noexcept

◆ regexFilter() [3/3]

AccessFilter & nawa::AccessFilter::regexFilter ( std::regex  value)
noexcept

◆ response() [1/3]

std::string & nawa::AccessFilter::response ( )
noexcept

The response that will be sent to the client if the request is not forwarded to the app (i.e., the request is blocked, the file to forward is not found, or access has been denied). If empty, a standard NAWA error document will be sent.

Returns
Reference to element.

◆ response() [2/3]

std::string const & nawa::AccessFilter::response ( ) const
noexcept

◆ response() [3/3]

AccessFilter & nawa::AccessFilter::response ( std::string  value)
noexcept

◆ matches()

bool nawa::AccessFilter::matches ( std::vector< std::string > const &  requestPath) const

Check whether the conditions of this filter match the given request path.

Parameters
requestPathThe request path of the current request.
Returns
True if the filter matches, false otherwise.

Definition at line 70 of file AccessFilter.cpp.


The documentation for this class was generated from the following files: