Skip to content

Commit 0ab1dbb

Browse files
committed
LUTECE-2193 : Move DosGuard upload filter configuration from web.xml to lutece.properties
1 parent 71747b7 commit 0ab1dbb

File tree

3 files changed

+18
-31
lines changed

3 files changed

+18
-31
lines changed

src/java/fr/paris/lutece/portal/web/upload/DosGuardFilter.java

+11-21
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
package fr.paris.lutece.portal.web.upload;
3535

3636
import fr.paris.lutece.portal.service.util.AppLogService;
37+
import fr.paris.lutece.portal.service.util.AppPropertiesService;
3738

3839
import java.io.IOException;
3940

@@ -54,6 +55,14 @@
5455
*/
5556
public class DosGuardFilter implements Filter
5657
{
58+
// properties
59+
private static String PROPERTY_DOSGUARDFILTER_MINCONTENTLENGTH = "lutece.upload.dosguard.minContentLength";
60+
private static String PROPERTY_DOSGUARDFILTER_MININTERVAL = "lutece.upload.dosguard.minInterval";
61+
62+
// constants
63+
private static int CONSTANT_DEFAULT_DOSGUARDFILTER_MINCONTENTLENGTH = 10240 ;
64+
private static int CONSTANT_DEFAULT_DOSGUARDFILTER_MININTERVAL = 2000 ;
65+
5766
// Initial capacity of the HashMap
5867
private static final int INITIAL_CAPACITY = 100;
5968
private FilterConfig _filterConfig;
@@ -81,28 +90,9 @@ public void init( FilterConfig config ) throws ServletException
8190
_mapLastRequestTimes = new HashMap<String, Long>( INITIAL_CAPACITY );
8291
_listOrderedRequests = new LinkedList<Entry>( );
8392

84-
try
85-
{
86-
String paramValue = _filterConfig.getInitParameter( "minContentLength" );
87-
88-
if ( paramValue != null )
89-
{
90-
_nMinContentLength = Integer.parseInt( paramValue );
91-
}
92-
93-
paramValue = _filterConfig.getInitParameter( "minInterval" );
93+
_nMinContentLength = AppPropertiesService.getPropertyInt( PROPERTY_DOSGUARDFILTER_MINCONTENTLENGTH, CONSTANT_DEFAULT_DOSGUARDFILTER_MINCONTENTLENGTH ) ;
94+
_nMinInterval = AppPropertiesService.getPropertyInt( PROPERTY_DOSGUARDFILTER_MININTERVAL, CONSTANT_DEFAULT_DOSGUARDFILTER_MININTERVAL ) ;
9495

95-
if ( paramValue != null )
96-
{
97-
_nMinInterval = Integer.parseInt( paramValue );
98-
}
99-
}
100-
catch( NumberFormatException ex )
101-
{
102-
ServletException servletEx = new ServletException( ex.getMessage( ) );
103-
servletEx.initCause( ex );
104-
throw servletEx;
105-
}
10696
}
10797

10898
/**

webapp/WEB-INF/conf/lutece.properties

+7
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,13 @@ askPasswordReinitialization.admin.level=0
227227
input.xss.characters=<>#"
228228
xss.error.message= Les caract\u00e8res &lt; &gt; # &amp; et &quot; sont interdits dans le contenu de votre message.
229229

230+
#################################################################################
231+
# DosGuard upload Filter
232+
# minContentLength: Requests below this size (in bytes) will always be allowed
233+
# minInterval: Minimum interval (in ms) allowed between two requests from the same client
234+
upload.dosguard.minContentLength=10240
235+
upload.dosguard.minInterval=2000
236+
230237
################################################################################
231238
# Paginators
232239
#

webapp/WEB-INF/web.xml

-10
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,6 @@
7171
<filter>
7272
<filter-name>dosFilter</filter-name>
7373
<filter-class>fr.paris.lutece.portal.web.upload.DosGuardFilter</filter-class>
74-
<init-param>
75-
<!-- Requests below this size (in bytes) will always be allowed -->
76-
<param-name>minContentLength</param-name>
77-
<param-value>10240</param-value>
78-
</init-param>
79-
<init-param>
80-
<!-- Minimum interval (in ms) allowed between two requests from the same client -->
81-
<param-name>minInterval</param-name>
82-
<param-value>2000</param-value>
83-
</init-param>
8474
</filter>
8575
<filter>
8676
<filter-name>pluginsFilters</filter-name>

0 commit comments

Comments
 (0)