Skip to content
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ public void windowClosing(WindowEvent e) {
});

pack();

// Message can be several lines, grow to fit
passwordTextArea.setSize(passwordTextArea.getWidth(), Short.MAX_VALUE);
passwordPane.setPreferredSize(new Dimension(passwordPane.getWidth(), passwordTextArea.getPreferredSize().height));
pack();

Dimension dlgSize = getPreferredSize();
Dimension frmSize = parent.getSize();
Point loc = parent.getLocation();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,51 +333,61 @@ public LoginStatus authorizeUser(String username, String plainPassword, String s
LoginStatus loginStatus = null;

if (authorized) {
long currentTime = System.currentTimeMillis();
String changeReason = null;

// If password expiration is enabled, do checks now
if (passwordRequirements.getExpiration() > 0) {
long passwordTime = credentials.getPasswordDate().getTimeInMillis();
long currentTime = System.currentTimeMillis();

// If the password is expired, do grace period checks
if (loginRequirementsChecker.isPasswordExpired(passwordTime, currentTime)) {
// Let 0 be infinite grace period, -1 be no grace period
if (passwordRequirements.getGracePeriod() == 0) {
loginStatus = new LoginStatus(LoginStatus.Status.SUCCESS_GRACE_PERIOD, "Your password has expired. Please change your password now.", validUser.getUsername());
} else if (passwordRequirements.getGracePeriod() > 0) {
// If there has never been a grace time, start it now
long gracePeriodStartTime;
if (validUser.getGracePeriodStart() == null) {
gracePeriodStartTime = currentTime;

Map<String, Object> gracePeriodMap = new HashMap<String, Object>();
gracePeriodMap.put("id", validUser.getId());
gracePeriodMap.put("gracePeriodStart", Calendar.getInstance());

SqlConfig.getInstance().getSqlSessionManager().update("User.startGracePeriod", gracePeriodMap);
} else {
gracePeriodStartTime = validUser.getGracePeriodStart().getTimeInMillis();
}

long graceTimeRemaining = loginRequirementsChecker.getGraceTimeRemaining(gracePeriodStartTime, currentTime);
if (graceTimeRemaining > 0) {
loginStatus = new LoginStatus(LoginStatus.Status.SUCCESS_GRACE_PERIOD, "Your password has expired. You are required to change your password in the next " + loginRequirementsChecker.getPrintableGraceTimeRemaining(graceTimeRemaining) + ".", validUser.getUsername());
}
}
if ((passwordRequirements.getExpiration() > 0)
&& loginRequirementsChecker.isPasswordExpired(credentials.getPasswordDate().getTimeInMillis(), currentTime)) {
changeReason = "Your password has expired.";
} else {
// Check if it meets the current requirements
List<String> requirementFailures = PasswordRequirementsChecker.getInstance().doesPasswordMeetRequirements(null, plainPassword, passwordRequirements);

if (requirementFailures != null) {
changeReason = "Your password does not meet requirements: " + StringUtils.join(requirementFailures, "; ") + ".";
}
}

// If there is no grace period or it has passed, FAIL_EXPIRED
if (loginStatus == null) {
loginStatus = new LoginStatus(LoginStatus.Status.FAIL_EXPIRED, "Your password has expired. Please contact an administrator to have your password reset.");
// If a change is required, handle grace period checks
if (changeReason != null) {
// Let 0 be infinite grace period, -1 be no grace period
if (passwordRequirements.getGracePeriod() == 0) {
loginStatus = new LoginStatus(LoginStatus.Status.SUCCESS_GRACE_PERIOD, changeReason + " Please change your password now.", validUser.getUsername());
} else if (passwordRequirements.getGracePeriod() > 0) {
// If there has never been a grace time, start it now
long gracePeriodStartTime;
if (validUser.getGracePeriodStart() == null) {
gracePeriodStartTime = currentTime;

Map<String, Object> gracePeriodMap = new HashMap<String, Object>();
gracePeriodMap.put("id", validUser.getId());
gracePeriodMap.put("gracePeriodStart", Calendar.getInstance());

SqlConfig.getInstance().getSqlSessionManager().update("User.startGracePeriod", gracePeriodMap);
} else {
gracePeriodStartTime = validUser.getGracePeriodStart().getTimeInMillis();
}

/*
* Reset the user's grace period if it isn't being used but one was
* previously set. This should only happen if a user is in a grace period
* before grace periods are disabled.
*/
if ((passwordRequirements.getGracePeriod() <= 0) && (validUser.getGracePeriodStart() != null)) {
SqlConfig.getInstance().getSqlSessionManager().update("User.clearGracePeriod", validUser.getId());
long graceTimeRemaining = loginRequirementsChecker.getGraceTimeRemaining(gracePeriodStartTime, currentTime);
if (graceTimeRemaining > 0) {
loginStatus = new LoginStatus(LoginStatus.Status.SUCCESS_GRACE_PERIOD, changeReason + " You are required to change your password in the next " + loginRequirementsChecker.getPrintableGraceTimeRemaining(graceTimeRemaining) + ".", validUser.getUsername());
}
}

// If there is no grace period or it has passed, FAIL_EXPIRED
if (loginStatus == null) {
loginStatus = new LoginStatus(LoginStatus.Status.FAIL_EXPIRED, changeReason + " Please contact an administrator to have your password reset.");
}

/*
* Reset the user's grace period if it isn't being used but one was
* previously set. This should only happen if a user is in a grace period
* before grace periods are disabled.
*/
if ((passwordRequirements.getGracePeriod() <= 0) && (validUser.getGracePeriodStart() != null)) {
SqlConfig.getInstance().getSqlSessionManager().update("User.clearGracePeriod", validUser.getId());
}
}
// End of password expiration and grace period checks

Expand Down
Loading