Skip to content

Commit 5a85203

Browse files
committed
LUI-83 : Displaying meaningful info when user is locked out
Displaying meaningful infowen user is locked made the variable local displaying use ful info when user is locked out LUI-83 : modified the method to use global property LUI-83 : modified the method to use global property LUI-83: Correcting the Variable Naming
1 parent 521d14f commit 5a85203

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

api/src/main/resources/messages.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@ legacyui.manageuser.noProviderIdentifier=No Identifier Specified
1010
${project.parent.artifactId}.Location.purgeLocation=Permanently Delete Location
1111
${project.parent.artifactId}.Location.confirmDelete=Are you sure you want to delete this Location? It will be permanently removed from the system.
1212
${project.parent.artifactId}.Location.purgedSuccessfully=Location deleted successfully
13+
14+
legacyui.lockedOutMessage=You have attempted to log in too many times and have been Locked out. Please try again later in 5 minutes

omod/src/main/java/org/openmrs/web/servlet/LoginServlet.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,11 @@ 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);
5355

56+
5457
/**
5558
* The mapping from user's IP address to the number of attempts at logging in from that IP
5659
*/
@@ -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 loginAttemptsByUserName;
7276
String ipAddress = request.getRemoteAddr();
7377
Integer loginAttempts = loginAttemptsByIP.get(ipAddress);
7478
if (loginAttempts == null) {
7579
loginAttempts = 1;
7680
}
7781

7882
loginAttempts++;
79-
83+
loginAttemptsByUserName = 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 (loginAttemptsByUserName <= maximumAlowedAttempts) {
190+
httpSession.setAttribute(WebConstants.OPENMRS_ERROR_ATTR, "auth.password.invalid");
191+
192+
}
193+
194+
if (loginAttemptsByUserName > maximumAlowedAttempts) {
195+
httpSession.setAttribute(WebConstants.OPENMRS_ERROR_ATTR, "legacyui.lockedOutMessage");
196+
}
182197
}
183198

184199
}

0 commit comments

Comments
 (0)