Skip to content
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

Lui 83 #99

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
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
mozzy11 committed Feb 11, 2019
commit 5a85203ea2d78303512be05579f7901884c84788
2 changes: 2 additions & 0 deletions api/src/main/resources/messages.properties
Original file line number Diff line number Diff line change
@@ -10,3 +10,5 @@ legacyui.manageuser.noProviderIdentifier=No Identifier Specified
${project.parent.artifactId}.Location.purgeLocation=Permanently Delete Location
${project.parent.artifactId}.Location.confirmDelete=Are you sure you want to delete this Location? It will be permanently removed from the system.
${project.parent.artifactId}.Location.purgedSuccessfully=Location deleted successfully

legacyui.lockedOutMessage=You have attempted to log in too many times and have been Locked out. Please try again later in 5 minutes
21 changes: 18 additions & 3 deletions omod/src/main/java/org/openmrs/web/servlet/LoginServlet.java
Original file line number Diff line number Diff line change
@@ -49,8 +49,11 @@ public class LoginServlet extends HttpServlet {

public static final long serialVersionUID = 134231247523L;

public static final String GP_MAXIMUM_ALLOWED_LOGINS = "security.allowedFailedLoginsBeforeLockout";

protected static final Log log = LogFactory.getLog(LoginServlet.class);


/**
* 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 {
* @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest,
* javax.servlet.http.HttpServletResponse)
*/

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
HttpSession httpSession = request.getSession();

Integer loginAttemptsByUserName;
String ipAddress = request.getRemoteAddr();
Integer loginAttempts = loginAttemptsByIP.get(ipAddress);
if (loginAttempts == null) {
loginAttempts = 1;
}

loginAttempts++;

loginAttemptsByUserName = loginAttempts - 1;
boolean lockedOut = false;
// look up the allowed # of attempts per IP
Integer allowedLockoutAttempts = 100;
@@ -178,7 +182,18 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
catch (ContextAuthenticationException e) {
// set the error message for the user telling them
// to try again
httpSession.setAttribute(WebConstants.OPENMRS_ERROR_ATTR, "auth.password.invalid");

String maximumAttempts = Context.getAdministrationService().getGlobalProperty(GP_MAXIMUM_ALLOWED_LOGINS, "7");
Integer maximumAlowedAttempts = Integer.valueOf(maximumAttempts);

if (loginAttemptsByUserName <= maximumAlowedAttempts) {
httpSession.setAttribute(WebConstants.OPENMRS_ERROR_ATTR, "auth.password.invalid");

}

if (loginAttemptsByUserName > maximumAlowedAttempts) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think use of if else here will be much better because we are to check for only one of the condition and not both separately.

httpSession.setAttribute(WebConstants.OPENMRS_ERROR_ATTR, "legacyui.lockedOutMessage");
}
}

}