dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #05268
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 1728: Simplified implementation of max attempts/timeframe in userauditservice by using default values f...
------------------------------------------------------------
revno: 1728
committer: Lars <larshelg@larshelg-laptop>
branch nick: trunk
timestamp: Sat 2010-04-03 11:58:13 +0200
message:
Simplified implementation of max attempts/timeframe in userauditservice by using default values for system settings
modified:
dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/useraudit/DefaultUserAuditService.java
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/useraudit/DefaultUserAuditService.java'
--- dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/useraudit/DefaultUserAuditService.java 2010-04-03 09:35:43 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/useraudit/DefaultUserAuditService.java 2010-04-03 09:58:13 +0000
@@ -39,16 +39,17 @@
import static org.hisp.dhis.options.SystemSettingManager.KEY_TIMEFRAME_MINUTES;
/**
+ * @author Saptarshi Purkayastha
* @author Lars Helge Overland
- *
- * TODO: Cleanup code by MAX_NUMBER_OF_ATTEMPTS and TIMEFRAME_MINUTES
- * loading in system setting with default values through startup routine
*/
-public class DefaultUserAuditService
+public class DefaultUserAuditService
implements UserAuditService
{
private static final Log log = LogFactory.getLog( DefaultUserAuditService.class );
+ private static final int DEFAULT_MAX_NUMBER_OF_ATTEMPTS = 5;
+ private static final int DEFAULT_TIMEFRAME_MINUTES = 10;
+
// -------------------------------------------------------------------------
// Dependencies
// -------------------------------------------------------------------------
@@ -91,18 +92,9 @@
int no = userAuditStore.getLoginFailures( username, getDate() );
- int MAX_NUMBER_OF_ATTEMPTS = 5; // DEFAULT
-
- if ( systemSettingManager.getSystemSetting( KEY_MAX_NUMBER_OF_ATTEMPTS ) != null )
- {
- MAX_NUMBER_OF_ATTEMPTS = (Integer) systemSettingManager.getSystemSetting( KEY_MAX_NUMBER_OF_ATTEMPTS );
- }
- else
- {
- systemSettingManager.saveSystemSetting( KEY_MAX_NUMBER_OF_ATTEMPTS, 5 );
- }
-
- if ( no >= MAX_NUMBER_OF_ATTEMPTS )
+ int max = (Integer) systemSettingManager.getSystemSetting( KEY_MAX_NUMBER_OF_ATTEMPTS, DEFAULT_MAX_NUMBER_OF_ATTEMPTS );
+
+ if ( no >= max )
{
log.info( "Max number of login attempts exceeded: '" + username + "'" );
}
@@ -118,35 +110,13 @@
@Override
public int getMaxAttempts()
{
- int MAX_NUMBER_OF_ATTEMPTS = 5;
-
- if ( systemSettingManager.getSystemSetting( KEY_MAX_NUMBER_OF_ATTEMPTS ) != null )
- {
- MAX_NUMBER_OF_ATTEMPTS = (Integer) systemSettingManager.getSystemSetting( KEY_MAX_NUMBER_OF_ATTEMPTS );
- }
- else
- {
- systemSettingManager.saveSystemSetting( KEY_MAX_NUMBER_OF_ATTEMPTS, 5 );
- }
-
- return MAX_NUMBER_OF_ATTEMPTS;
+ return (Integer) systemSettingManager.getSystemSetting( KEY_MAX_NUMBER_OF_ATTEMPTS, DEFAULT_MAX_NUMBER_OF_ATTEMPTS );
}
@Override
public int getLockoutTimeframe()
{
- int TIMEFRAME_MINUTES = 10; // DEFAULT
-
- if ( systemSettingManager.getSystemSetting( KEY_TIMEFRAME_MINUTES ) != null )
- {
- TIMEFRAME_MINUTES = (Integer) systemSettingManager.getSystemSetting( KEY_TIMEFRAME_MINUTES );
- }
- else
- {
- systemSettingManager.saveSystemSetting( KEY_TIMEFRAME_MINUTES, 10 );
- }
-
- return TIMEFRAME_MINUTES;
+ return (Integer) systemSettingManager.getSystemSetting( KEY_TIMEFRAME_MINUTES, DEFAULT_TIMEFRAME_MINUTES );
}
@Override
@@ -157,19 +127,10 @@
private Date getDate()
{
- int TIMEFRAME_MINUTES = 10;
-
- if ( systemSettingManager.getSystemSetting( KEY_TIMEFRAME_MINUTES ) != null )
- {
- TIMEFRAME_MINUTES = (Integer) systemSettingManager.getSystemSetting( KEY_TIMEFRAME_MINUTES );
- }
- else
- {
- systemSettingManager.saveSystemSetting( KEY_TIMEFRAME_MINUTES, 10 );
- }
+ int timeframe = (Integer) systemSettingManager.getSystemSetting( KEY_TIMEFRAME_MINUTES, DEFAULT_TIMEFRAME_MINUTES );
Calendar cal = Calendar.getInstance();
- cal.add( Calendar.MINUTE, TIMEFRAME_MINUTES * -1 );
+ cal.add( Calendar.MINUTE, timeframe * -1 );
return cal.getTime();
}