Skip to content

Commit

Permalink
Rename oldPassword to currentPassword
Browse files Browse the repository at this point in the history
  • Loading branch information
MDeLuise authored and Coduz committed Feb 6, 2023
1 parent d020f18 commit 64c226f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ components:
- description: Represent a request for changing the user password
type: object
properties:
oldPassword:
currentPassword:
type: string
newPassword:
type: string
example:
oldPassword: "Welcome1234!"
currentPassword: "Welcome1234!"
newPassword: "NewWelcome1234!"
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
@XmlAccessorType(XmlAccessType.PROPERTY)
@XmlType(factoryClass = UserCredentialXmlRegistry.class, factoryMethod = "newPasswordChangeRequest")
public interface PasswordChangeRequest {
@XmlElement(name = "oldPassword")
String getOldPassword();
@XmlElement(name = "currentPassword")
String getCurrentPassword();


void setOldPassword(String oldPassword);
void setCurrentPassword(String currentPassword);


@XmlElement(name = "newPassword")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@

public class PasswordChangeRequestImpl implements PasswordChangeRequest {
private String newPassword;
private String oldPassword;
private String currentPassword;


@Override
public String getOldPassword() {
return oldPassword;
public String getCurrentPassword() {
return currentPassword;
}


@Override
public void setOldPassword(String oldPassword) {
this.oldPassword = oldPassword;
public void setCurrentPassword(String currentPassword) {
this.currentPassword = currentPassword;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
package org.eclipse.kapua.service.authentication.user.shiro;

import org.eclipse.kapua.KapuaEntityNotFoundException;
import org.eclipse.kapua.KapuaErrorCodes;
import org.eclipse.kapua.KapuaException;
import org.eclipse.kapua.KapuaIllegalArgumentException;
import org.eclipse.kapua.commons.security.KapuaSecurityUtils;
import org.eclipse.kapua.commons.util.ArgumentValidator;
import org.eclipse.kapua.commons.util.CommonsValidationRegex;
Expand All @@ -26,6 +26,7 @@
import org.eclipse.kapua.service.authentication.credential.CredentialListResult;
import org.eclipse.kapua.service.authentication.credential.CredentialService;
import org.eclipse.kapua.service.authentication.credential.CredentialType;
import org.eclipse.kapua.service.authentication.exception.KapuaAuthenticationException;
import org.eclipse.kapua.service.authentication.exception.PasswordLengthException;
import org.eclipse.kapua.service.authentication.shiro.utils.AuthenticationUtils;
import org.eclipse.kapua.service.authentication.shiro.utils.CryptAlgorithm;
Expand All @@ -47,7 +48,7 @@ public class UserCredentialServiceImpl implements UserCredentialService {
@Override
public Credential changePasswordRequest(PasswordChangeRequest passwordChangeRequest) throws KapuaException {
ArgumentValidator.notNull(passwordChangeRequest.getNewPassword(), "passwordChangeRequest.newPassword");
ArgumentValidator.notNull(passwordChangeRequest.getOldPassword(), "passwordChangeRequest.oldPassword");
ArgumentValidator.notNull(passwordChangeRequest.getCurrentPassword(), "passwordChangeRequest.oldPassword");

return KapuaSecurityUtils.doPrivileged(() -> {
KapuaLocator locator = KapuaLocator.getInstance();
Expand All @@ -59,11 +60,11 @@ public Credential changePasswordRequest(PasswordChangeRequest passwordChangeRequ

AuthenticationService authenticationService = locator.getService(AuthenticationService.class);
CredentialsFactory credentialsFactory = locator.getFactory(CredentialsFactory.class);
UsernamePasswordCredentials usernamePasswordCredentials = credentialsFactory.newUsernamePasswordCredentials(user.getName(), passwordChangeRequest.getOldPassword());
UsernamePasswordCredentials usernamePasswordCredentials = credentialsFactory.newUsernamePasswordCredentials(user.getName(), passwordChangeRequest.getCurrentPassword());
try {
authenticationService.verifyCredentials(usernamePasswordCredentials);
} catch (KapuaException e) {
throw new KapuaException(KapuaErrorCodes.OPERATION_NOT_ALLOWED, "passwordChangeRequest.oldPassword");
} catch (KapuaAuthenticationException e) {
throw new KapuaIllegalArgumentException("passwordChangeRequest.oldPassword", passwordChangeRequest.getCurrentPassword());
}

CredentialService credentialService = locator.getService(CredentialService.class);
Expand All @@ -81,7 +82,7 @@ public Credential changePasswordRequest(PasswordChangeRequest passwordChangeRequ

//
// Validate Password regex
ArgumentValidator.match(passwordChangeRequest.getNewPassword(), CommonsValidationRegex.PASSWORD_REGEXP, "credentialCreator.credentialKey");
ArgumentValidator.match(passwordChangeRequest.getNewPassword(), CommonsValidationRegex.PASSWORD_REGEXP, "passwordChangeRequest.newPassword");

String encryptedPass = AuthenticationUtils.cryptCredential(CryptAlgorithm.BCRYPT, passwordChangeRequest.getNewPassword());
passwordCredential.setCredentialKey(encryptedPass);
Expand Down

0 comments on commit 64c226f

Please sign in to comment.