Skip to content

Commit

Permalink
fix MID-3861 GUI Credentials - Attempt to encrypt protected data that…
Browse files Browse the repository at this point in the history
… are already encrypted
  • Loading branch information
KaterynaHonchar committed Apr 24, 2017
1 parent 7ec0bd4 commit 00c8630
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
Expand Up @@ -20,6 +20,7 @@
import java.util.Collections;
import java.util.List;

import com.evolveum.prism.xml.ns._public.types_3.EncryptedDataType;
import org.apache.commons.lang3.StringUtils;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.extensions.markup.html.tabs.AbstractTab;
Expand Down Expand Up @@ -57,6 +58,7 @@
import com.evolveum.midpoint.web.security.SecurityUtils;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
import com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType;
import org.apache.xml.security.encryption.EncryptedData;

/**
* @author Viliam Repan (lazyman)
Expand Down Expand Up @@ -320,8 +322,9 @@ protected void onSavePerformed(AjaxRequestTarget target) {
try {
MyPasswordsDto dto = model.getObject();
ProtectedStringType password = dto.getPassword();
WebComponentUtil.encryptProtectedString(password, true, getMidpointApplication());

if (!password.isEncrypted()) {
WebComponentUtil.encryptProtectedString(password, true, getMidpointApplication());
}
final ItemPath valuePath = new ItemPath(SchemaConstantsGenerated.C_CREDENTIALS,
CredentialsType.F_PASSWORD, PasswordType.F_VALUE);
SchemaRegistry registry = getPrismContext().getSchemaRegistry();
Expand All @@ -343,11 +346,7 @@ protected void onSavePerformed(AjaxRequestTarget target) {

result.computeStatus();
} catch (Exception ex) {
MyPasswordsDto dto = model.getObject();
ProtectedStringType password = dto.getPassword();
if (password != null){
password.setEncryptedData(null);
}
setEncryptedPasswordData(null);
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't save password changes", ex);
result.recordFatalError(getString("PageAbstractSelfCredentials.save.password.failed", ex.getMessage()), ex);
} finally {
Expand All @@ -356,6 +355,14 @@ protected void onSavePerformed(AjaxRequestTarget target) {

finishChangePassword(result, target);
}

protected void setEncryptedPasswordData(EncryptedDataType data){
MyPasswordsDto dto = model.getObject();
ProtectedStringType password = dto.getPassword();
if (password != null){
password.setEncryptedData(data);
}
}

protected abstract boolean isCheckOldPassword();

Expand Down
Expand Up @@ -30,11 +30,11 @@ protected boolean isCheckOldPassword() {
@Override
protected void finishChangePassword(OperationResult result, AjaxRequestTarget target) {
if (!WebComponentUtil.isSuccessOrHandledError(result)) {
setEncryptedPasswordData(null);
showResult(result);
target.add(getFeedbackPanel());
} else {
showResult(result);

showResult(result);
setResponsePage(getMidpointApplication().getHomePage());
}
}
Expand Down

0 comments on commit 00c8630

Please sign in to comment.