Code development platform for open source projects from the European Union institutions :large_blue_circle: EU Login authentication by SMS has been phased out. To see alternatives please check here

Skip to content
Snippets Groups Projects
Commit cc47e262 authored by Joze RIHTARSIC's avatar Joze RIHTARSIC
Browse files

[EDELIVERY-13367] SA report

parent 55d1c1ab
No related branches found
No related tags found
No related merge requests found
...@@ -47,7 +47,7 @@ export class PasswordChangeDialogComponent { ...@@ -47,7 +47,7 @@ export class PasswordChangeDialogComponent {
let currentPasswdFormControl: UntypedFormControl = new UntypedFormControl({value: null, readonly: false}, let currentPasswdFormControl: UntypedFormControl = new UntypedFormControl({value: null, readonly: false},
this.securityService.getCurrentUser().casAuthenticated && this.adminUser ? null : [Validators.required]); this.securityService.getCurrentUser().casAuthenticated && this.adminUser ? null : [Validators.required]);
let newPasswdFormControl: UntypedFormControl = new UntypedFormControl({value: null, readonly: false}, let newPasswdFormControl: UntypedFormControl = new UntypedFormControl({value: null, readonly: false},
[Validators.required, Validators.pattern(this.passwordValidationRegExp), equal(currentPasswdFormControl, false)]); [Validators.required, Validators.pattern(this.passwordValidationRegExp)]);
let confirmNewPasswdFormControl: UntypedFormControl = new UntypedFormControl({value: null, readonly: false}, let confirmNewPasswdFormControl: UntypedFormControl = new UntypedFormControl({value: null, readonly: false},
[Validators.required, equal(newPasswdFormControl, true)]); [Validators.required, equal(newPasswdFormControl, true)]);
......
...@@ -154,7 +154,7 @@ public enum SMPPropertyEnum { ...@@ -154,7 +154,7 @@ public enum SMPPropertyEnum {
"Password minimum complexity rules!", "Password minimum complexity rules!",
OPTIONAL, NOT_ENCRYPTED, NO_RESTART_NEEDED, REGEXP), OPTIONAL, NOT_ENCRYPTED, NO_RESTART_NEEDED, REGEXP),
PASSWORD_POLICY_MESSAGE("smp.passwordPolicy.validationMessage", "Minimum length: 16 characters;Maximum length: 32 characters;At least one letter in lowercase;At least one letter in uppercase;At least one digit;At least one special character", PASSWORD_POLICY_MESSAGE("smp.passwordPolicy.validationMessage", "Minimum length: 16 characters;Maximum length: 32 characters;At least one letter in lowercase;At least one letter in uppercase;At least one digit;At least one special character;Must not be same as existing password",
"The error message shown to the user in case the password does not follow the regex put in the domibus.passwordPolicy.pattern property", "The error message shown to the user in case the password does not follow the regex put in the domibus.passwordPolicy.pattern property",
OPTIONAL, NOT_ENCRYPTED, NO_RESTART_NEEDED, STRING), OPTIONAL, NOT_ENCRYPTED, NO_RESTART_NEEDED, STRING),
PASSWORD_POLICY_VALID_DAYS("smp.passwordPolicy.validDays", "90", "Number of days password is valid", PASSWORD_POLICY_VALID_DAYS("smp.passwordPolicy.validDays", "90", "Number of days password is valid",
......
...@@ -246,6 +246,15 @@ public class UIUserService extends UIServiceBase<DBUser, UserRO> { ...@@ -246,6 +246,15 @@ public class UIUserService extends UIServiceBase<DBUser, UserRO> {
CredentialType.USERNAME_PASSWORD, CredentialType.USERNAME_PASSWORD,
CredentialTargetType.UI)); CredentialTargetType.UI));
// check if new password is the same as the old one
// but allow admin to overwrite it
if (!adminUpdate
&& StringUtils.isNotBlank(dbCredential.getValue())
&& BCrypt.checkpw(password, dbCredential.getValue())) {
LOG.info(SMPLogger.SECURITY_MARKER, "Change/set password failed because 'new' password match the old password for user: [{}]", userID);
throw new SMPRuntimeException(ErrorCode.INVALID_REQUEST, "PasswordChange", configurationService.getPasswordPolicyValidationMessage());
}
dbCredential.setValue(BCryptPasswordHash.hashPassword(password)); dbCredential.setValue(BCryptPasswordHash.hashPassword(password));
OffsetDateTime currentTime = OffsetDateTime.now(); OffsetDateTime currentTime = OffsetDateTime.now();
dbCredential.setChangedOn(currentTime); dbCredential.setChangedOn(currentTime);
......
...@@ -250,6 +250,24 @@ class UIUserServiceIntegrationTest extends AbstractJunit5BaseDao { ...@@ -250,6 +250,24 @@ class UIUserServiceIntegrationTest extends AbstractJunit5BaseDao {
testInstance.updateUserPassword(authorizedUserId, userToUpdateId, authorizedPassword, newPassword); testInstance.updateUserPassword(authorizedUserId, userToUpdateId, authorizedPassword, newPassword);
} }
@Test
void testUpdateUserPasswordFaileSame() {
DBUser user = TestDBUtils.createDBUserByUsername(UUID.randomUUID().toString());
DBCredential credential = TestDBUtils.createDBCredentialForUser(user, null, null, null);
credential.setValue(BCrypt.hashpw("TTTTtttt1111$$$$$", BCrypt.gensalt()));
userDao.persistFlushDetach(user);
credentialDao.persistFlushDetach(credential);
long authorizedUserId = user.getId();
long userToUpdateId = user.getId();
String authorizedPassword = "TTTTtttt1111$$$$$";
String newPassword = "TTTTtttt1111$$$$$";
SMPRuntimeException result = assertThrows(SMPRuntimeException.class,
() -> testInstance.updateUserPassword(authorizedUserId, userToUpdateId, authorizedPassword, newPassword));
MatcherAssert.assertThat(result.getMessage(), CoreMatchers.containsString("Must not be same as existing password"));
}
@Test @Test
void testUpdateUserPasswordByAdminUserNotExists() { void testUpdateUserPasswordByAdminUserNotExists() {
// system admin // system admin
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment