@@ -49,7 +49,10 @@ public class LoginServlet extends HttpServlet {
4949
5050 public static final long serialVersionUID = 134231247523L ;
5151
52+ public static final String GP_MAXIMUM_ALLOWED_LOGINS = "security.allowedFailedLoginsBeforeLockout" ;
53+
5254 protected static final Log log = LogFactory .getLog (LoginServlet .class );
55+ //AdministrationService administrationService = Context.getAdministrationService();
5356
5457 /**
5558 * The mapping from user's IP address to the number of attempts at logging in from that IP
@@ -65,18 +68,19 @@ public class LoginServlet extends HttpServlet {
6568 * @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest,
6669 * javax.servlet.http.HttpServletResponse)
6770 */
71+
6872 @ Override
6973 protected void doPost (HttpServletRequest request , HttpServletResponse response ) throws ServletException , IOException {
7074 HttpSession httpSession = request .getSession ();
71-
75+ Integer loginAttemptsByUser ;
7276 String ipAddress = request .getRemoteAddr ();
7377 Integer loginAttempts = loginAttemptsByIP .get (ipAddress );
7478 if (loginAttempts == null ) {
7579 loginAttempts = 1 ;
7680 }
7781
7882 loginAttempts ++;
79-
83+ loginAttemptsByUser = loginAttempts - 1 ;
8084 boolean lockedOut = false ;
8185 // look up the allowed # of attempts per IP
8286 Integer allowedLockoutAttempts = 100 ;
@@ -178,7 +182,18 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
178182 catch (ContextAuthenticationException e ) {
179183 // set the error message for the user telling them
180184 // to try again
181- httpSession .setAttribute (WebConstants .OPENMRS_ERROR_ATTR , "auth.password.invalid" );
185+
186+ String maximumAttempts = Context .getAdministrationService ().getGlobalProperty (GP_MAXIMUM_ALLOWED_LOGINS , "7" );
187+ Integer maximumAlowedAttempts = Integer .valueOf (maximumAttempts );
188+
189+ if (loginAttemptsByUser <= maximumAlowedAttempts ) {
190+ httpSession .setAttribute (WebConstants .OPENMRS_ERROR_ATTR , "auth.password.invalid" );
191+
192+ }
193+
194+ if (loginAttemptsByUser > maximumAlowedAttempts ) {
195+ httpSession .setAttribute (WebConstants .OPENMRS_ERROR_ATTR , "legacyui.lockedOutMessage" );
196+ }
182197 }
183198
184199 }
0 commit comments