Skip to content
Merged
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 @@ -613,6 +613,10 @@ public int getActiveUsersCount(Date since) {
@Override
@Transactional(readOnly = true)
public boolean userNonExpired(User user) {
if (user == null) {
return true;
}

int credentialsExpires = systemSettingManager.credentialsExpires();

if (credentialsExpires == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public PasswordValidationResult validate(CredentialsInfo credentials) {
private boolean isRuleApplicable(CredentialsInfo credentials) {
User user = userService.getUserByUsername(credentials.getUsername());

if (!userService.userNonExpired(user)) {
if (user != null && !userService.userNonExpired(user)) {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.hisp.dhis.setting.SystemSettingManager;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.ArgumentCaptor;
Expand Down Expand Up @@ -273,4 +274,16 @@ void testPasswordHistoryValidationRule() {
Assertions.assertEquals(23, userArgumentCaptor.getValue().getPreviousPasswords().size());
assertFalse(userArgumentCaptor.getValue().getPreviousPasswords().contains(STRONG_PASSWORD));
}

@Test
@DisplayName("PasswordHistoryValidationRule with new user and credentials expires")
void testPasswordHistoryValidationRuleWithNewUserAndCredentialsExpires() {
// The user does not exist yet, so getUserByUsername returns null
CredentialsInfo credentialsInfo = new CredentialsInfo(USERNAME, STRONG_PASSWORD, EMAIL, true);

// This should not throw NullPointerException
PasswordValidationResult result = historyValidationRule.validate(credentialsInfo);

assertThat(result.isValid(), is(true));
}
}