Skip to content

Lutece 2193 #139

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 11 additions & 21 deletions src/java/fr/paris/lutece/portal/web/upload/DosGuardFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
package fr.paris.lutece.portal.web.upload;

import fr.paris.lutece.portal.service.util.AppLogService;
import fr.paris.lutece.portal.service.util.AppPropertiesService;

import java.io.IOException;

Expand All @@ -54,6 +55,14 @@
*/
public class DosGuardFilter implements Filter
{
// properties
private static String PROPERTY_DOSGUARDFILTER_MINCONTENTLENGTH = "lutece.upload.dosguard.minContentLength";
private static String PROPERTY_DOSGUARDFILTER_MININTERVAL = "lutece.upload.dosguard.minInterval";

// constants
private static int CONSTANT_DEFAULT_DOSGUARDFILTER_MINCONTENTLENGTH = 10240 ;
private static int CONSTANT_DEFAULT_DOSGUARDFILTER_MININTERVAL = 2000 ;

// Initial capacity of the HashMap
private static final int INITIAL_CAPACITY = 100;
private FilterConfig _filterConfig;
Expand Down Expand Up @@ -81,28 +90,9 @@ public void init( FilterConfig config ) throws ServletException
_mapLastRequestTimes = new HashMap<String, Long>( INITIAL_CAPACITY );
_listOrderedRequests = new LinkedList<Entry>( );

try
{
String paramValue = _filterConfig.getInitParameter( "minContentLength" );

if ( paramValue != null )
{
_nMinContentLength = Integer.parseInt( paramValue );
}

paramValue = _filterConfig.getInitParameter( "minInterval" );
_nMinContentLength = AppPropertiesService.getPropertyInt( PROPERTY_DOSGUARDFILTER_MINCONTENTLENGTH, CONSTANT_DEFAULT_DOSGUARDFILTER_MINCONTENTLENGTH ) ;
_nMinInterval = AppPropertiesService.getPropertyInt( PROPERTY_DOSGUARDFILTER_MININTERVAL, CONSTANT_DEFAULT_DOSGUARDFILTER_MININTERVAL ) ;

if ( paramValue != null )
{
_nMinInterval = Integer.parseInt( paramValue );
}
}
catch( NumberFormatException ex )
{
ServletException servletEx = new ServletException( ex.getMessage( ) );
servletEx.initCause( ex );
throw servletEx;
}
}

/**
Expand Down
7 changes: 7 additions & 0 deletions webapp/WEB-INF/conf/lutece.properties
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,13 @@ askPasswordReinitialization.admin.level=0
input.xss.characters=<>#"
xss.error.message= Les caract\u00e8res &lt; &gt; # &amp; et &quot; sont interdits dans le contenu de votre message.

#################################################################################
# DosGuard upload Filter
# minContentLength: Requests below this size (in bytes) will always be allowed
# minInterval: Minimum interval (in ms) allowed between two requests from the same client
lutece.upload.dosguard.minContentLength=10240
lutece.upload.dosguard.minInterval=2000

################################################################################
# Paginators
#
Expand Down
10 changes: 0 additions & 10 deletions webapp/WEB-INF/web.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,6 @@
<filter>
<filter-name>dosFilter</filter-name>
<filter-class>fr.paris.lutece.portal.web.upload.DosGuardFilter</filter-class>
<init-param>
<!-- Requests below this size (in bytes) will always be allowed -->
<param-name>minContentLength</param-name>
<param-value>10240</param-value>
</init-param>
<init-param>
<!-- Minimum interval (in ms) allowed between two requests from the same client -->
<param-name>minInterval</param-name>
<param-value>2000</param-value>
</init-param>
</filter>
<filter>
<filter-name>pluginsFilters</filter-name>
Expand Down