Skip to content

Commit

Permalink
MID-4643:change feedback message for reset passwort without privileges
Browse files Browse the repository at this point in the history
  • Loading branch information
skublik committed Mar 11, 2022
1 parent 164dcca commit 8a09610
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.util.Collections;
import java.util.List;

import com.evolveum.midpoint.gui.api.component.result.OpResult;
import com.evolveum.midpoint.schema.*;
import com.evolveum.midpoint.web.component.progress.ProgressReporter;

Expand Down Expand Up @@ -180,6 +181,21 @@ protected void onSubmit(AjaxRequestTarget target) {
}

protected void onSavePerformed(AjaxRequestTarget target) {

if (getPasswordDto().getFocus() == null) {
if (getFeedbackMessages().isEmpty()) {
warn(getString("PageAbstractSelfCredentials.message.couldntLoadFocus.fatalError"));
} else {
getFeedbackMessages().forEach(message -> {
if (message.getMessage() instanceof OpResult) {
((OpResult)message.getMessage()).setAlreadyShown(false);
}
});
}
target.add(getFeedbackPanel());
return;
}

Component actualTab = getActualTabPanel();
if (actualTab instanceof ChangePasswordPanel) {
ProtectedStringType oldPassword = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.schema.util.ResourceTypeUtil;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.util.exception.*;
import com.evolveum.midpoint.util.logging.LoggingUtils;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
Expand Down Expand Up @@ -95,7 +96,7 @@ public ChangePasswordPanel(String id, IModel<MyPasswordsDto> model) {
}

@Override
protected void onInitialize(){
protected void onInitialize() {
super.onInitialize();
initPasswordModel();
initMidpointAccountSelected();
Expand All @@ -111,7 +112,7 @@ private void initPasswordModel() {
private void initMidpointAccountSelected() {
MyPasswordsDto dto = getModelObject();
PasswordAccountDto midpointAccount = null;
for(PasswordAccountDto account : dto.getAccounts()){
for (PasswordAccountDto account : dto.getAccounts()) {
if (account.isMidpoint()) {
midpointAccount = account;
}
Expand Down Expand Up @@ -141,7 +142,7 @@ public boolean isVisible() {
add(passwordLabel);

PasswordPanel passwordPanel = new PasswordPanel(ID_PASSWORD_PANEL, new PropertyModel<>(getModel(), MyPasswordsDto.F_PASSWORD),
getModelObject().getFocus(), getPageBase()){
getModelObject().getFocus(), getPageBase()) {
@Override
protected <F extends FocusType> ValuePolicyType getValuePolicy(PrismObject<F> object) {
return getModelObject().getFocusPolicy();
Expand All @@ -154,7 +155,7 @@ protected void updatePasswordValidation(AjaxRequestTarget target) {
getTable().visitChildren(PasswordPolicyValidationPanel.class,
(IVisitor<PasswordPolicyValidationPanel, PasswordPolicyValidationPanel>) (panel, iVisit) -> {
panel.refreshValidationPopup(target);
});
});
}
};
passwordPanel.getBaseFormComponent().add(new AttributeModifier("autofocus", ""));
Expand All @@ -164,7 +165,7 @@ protected void updatePasswordValidation(AjaxRequestTarget target) {

List<IColumn<PasswordAccountDto, String>> columns = initColumns();
ListDataProvider<PasswordAccountDto> provider = new ListDataProvider<>(this,
new PropertyModel<>(getModel(), MyPasswordsDto.F_ACCOUNTS));
new PropertyModel<>(getModel(), MyPasswordsDto.F_ACCOUNTS));
TablePanel accounts = new TablePanel(ID_ACCOUNTS_TABLE, provider, columns);
accounts.setItemsPerPage(30);
accounts.setShowPaging(false);
Expand All @@ -187,7 +188,7 @@ protected boolean shouldShowPasswordPropagation() {
private List<IColumn<PasswordAccountDto, String>> initColumns() {
List<IColumn<PasswordAccountDto, String>> columns = new ArrayList<>();

columns.add(new CheckBoxColumn<>(Model.of(""), Selectable.F_SELECTED){
columns.add(new CheckBoxColumn<>(Model.of(""), Selectable.F_SELECTED) {
@Override
protected IModel<Boolean> getEnabled(IModel<PasswordAccountDto> rowModel) {
return () -> {
Expand Down Expand Up @@ -249,7 +250,7 @@ protected void onUpdateRow(AjaxRequestTarget target, DataTable table, IModel<Pas

@Override
public void populateItem(Item<ICellPopulator<PasswordAccountDto>> item, String componentId,
final IModel<PasswordAccountDto> rowModel) {
final IModel<PasswordAccountDto> rowModel) {
item.add(new Label(componentId, new IModel<>() {
private static final long serialVersionUID = 1L;

Expand All @@ -270,10 +271,10 @@ public void populateItem(Item<ICellPopulator<PasswordAccountDto>> item, String c
final IModel<PasswordAccountDto> rowModel) {
IModel<String> helpModel = () -> {
String title = "";
if (!rowModel.getObject().isMidpoint() && !rowModel.getObject().isPasswordCapabilityEnabled()){
if (!rowModel.getObject().isMidpoint() && !rowModel.getObject().isPasswordCapabilityEnabled()) {
title = createStringResource("ChangePasswordPanel.legendMessage.no.password.capability").getString();
}
if (rowModel.getObject().isMaintenanceState()){
if (rowModel.getObject().isMaintenanceState()) {
title = title
+ (StringUtils.isEmpty(title) ? "" : " ")
+ createStringResource("ChangePasswordPanel.legendMessage.maintenance").getString();
Expand All @@ -289,7 +290,7 @@ public String getObject() {
PasswordAccountDto dto = rowModel.getObject();
return dto.getResourceName();
}
}){
}) {
@Override
protected IModel<String> getHelpModel() {
return helpModel;
Expand All @@ -298,7 +299,7 @@ protected IModel<String> getHelpModel() {
}
});

IconColumn enabled = new IconColumn<PasswordAccountDto>(createStringResource("ChangePasswordPanel.enabled")){
IconColumn enabled = new IconColumn<PasswordAccountDto>(createStringResource("ChangePasswordPanel.enabled")) {

@Override
protected DisplayType getIconDisplayType(IModel<PasswordAccountDto> rowModel) {
Expand Down Expand Up @@ -380,8 +381,8 @@ protected OperationResult load() {
return progressActivity.getOperationResult();
} else if (progressActivity.getStatus() != null && !rowModel.getObject().isMidpoint()
&& ProgressInformation.ActivityType.RESOURCE_OBJECT_OPERATION.equals(progressActivity.getActivityType())
&& progressActivity.getResourceOperationResultList() != null
&& !progressActivity.getResourceOperationResultList().isEmpty()) {
&& progressActivity.getResourceOperationResultList() != null
&& !progressActivity.getResourceOperationResultList().isEmpty()) {
String resourceOid = rowModel.getObject().getResourceOid();
if (StringUtils.isNotEmpty(resourceOid) && progressActivity.getResourceShadowDiscriminator() != null
&& resourceOid.equals(progressActivity.getResourceShadowDiscriminator().getResourceOid())) {
Expand All @@ -393,14 +394,14 @@ protected OperationResult load() {
return new OperationResult("Empty result");
}
};
ColumnResultPanel resultPanel = new ColumnResultPanel(componentId, resultStatusModel){
ColumnResultPanel resultPanel = new ColumnResultPanel(componentId, resultStatusModel) {
@Override
protected boolean isProjectionResult() {
return !rowModel.getObject().isMidpoint();
}

@Override
protected DisplayType getDisplayForEmptyResult(){
protected DisplayType getDisplayForEmptyResult() {
String policyOid = rowModel.getObject().getPasswordValuePolicyOid();
if (StringUtils.isNotEmpty(policyOid) && ChangePasswordPanel.this.getModelObject().getPasswordPolicies().containsKey(policyOid)) {
if (limitationsByPolicyOid.get(policyOid) != null) {
Expand Down Expand Up @@ -438,7 +439,7 @@ public void updateResultColumnOfTable(AjaxRequestTarget target) {
getTable().visitChildren(ColumnResultPanel.class,
(IVisitor<ColumnResultPanel, ColumnResultPanel>) (panel, iVisit) -> {
if (panel.getModel() instanceof LoadableModel) {
((LoadableModel)panel.getModel()).reset();
((LoadableModel) panel.getModel()).reset();
}
target.add(panel);
});
Expand All @@ -449,11 +450,23 @@ private MyPasswordsDto loadPageModel() {

MyPasswordsDto passwordsDto = new MyPasswordsDto();
OperationResult result = new OperationResult(OPERATION_LOAD_USER_WITH_ACCOUNTS);
String focusOid = SecurityUtils.getPrincipalUser().getOid();
Task task = getPageBase().createSimpleTask(OPERATION_LOAD_USER);
OperationResult subResult = result.createSubresult(OPERATION_LOAD_USER);
PrismObject<? extends FocusType> focus = null;
try {
String focusOid = SecurityUtils.getPrincipalUser().getOid();
Task task = getPageBase().createSimpleTask(OPERATION_LOAD_USER);
OperationResult subResult = result.createSubresult(OPERATION_LOAD_USER);
PrismObject<? extends FocusType> focus = getPageBase().getModelService().getObject(FocusType.class, focusOid, null, task, subResult);
focus = getPageBase().getModelService().getObject(FocusType.class, focusOid, null, task, subResult);
} catch (CommonException e) {
if (shouldShowPasswordPropagation()) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't load user: " + e.getMessage(), e);
result.recordFatalError(getString("ChangePasswordPanel.message.couldntLoadUser.fatalError", e.getMessage()), e);
} else {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't load user: " + e.getMessage(), e);
result.recordFatalError(getString("web.security.provider.access.denied"), e);
}
result.recomputeStatus();
}
if (focus != null) {
passwordsDto = createMyPasswordsDto(focus);
subResult.recordSuccessIfUnknown();

Expand All @@ -469,13 +482,15 @@ private MyPasswordsDto loadPageModel() {
return passwordsDto;
}

addAccountsToMyPasswordsDto(passwordsDto, reference.getValues(), task, result);
result.recordSuccessIfUnknown();
} catch (Exception ex) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't load accounts", ex);
result.recordFatalError(getString("PageAbstractSelfCredentials.message.couldntLoadAccounts.fatalError"), ex);
} finally {
result.recomputeStatus();
try {
addAccountsToMyPasswordsDto(passwordsDto, reference.getValues(), task, result);
result.recordSuccessIfUnknown();
} catch (Exception ex) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't load accounts", ex);
result.recordFatalError(getString("PageAbstractSelfCredentials.message.couldntLoadAccounts.fatalError"), ex);
} finally {
result.recomputeStatus();
}
}

Collections.sort(passwordsDto.getAccounts());
Expand All @@ -493,7 +508,6 @@ private MyPasswordsDto createMyPasswordsDto(PrismObject<? extends FocusType> foc
CredentialsPolicyType credentialsPolicyType = WebComponentUtil.getPasswordCredentialsPolicy(focus, getPageBase(), task);
dto.getAccounts().add(createDefaultPasswordAccountDto(focus, getPasswordPolicyOid(credentialsPolicyType)));


if (credentialsPolicyType != null) {
PasswordCredentialsPolicyType passwordCredentialsPolicy = credentialsPolicyType.getPassword();
if (passwordCredentialsPolicy != null) {
Expand All @@ -506,7 +520,7 @@ private MyPasswordsDto createMyPasswordsDto(PrismObject<? extends FocusType> foc
dto.setPasswordChangeSecurity(passwordChangeSecurity);
}
ObjectReferenceType valuePolicyRef = passwordCredentialsPolicy.getValuePolicyRef();
if (valuePolicyRef != null && valuePolicyRef.getOid() != null){
if (valuePolicyRef != null && valuePolicyRef.getOid() != null) {
task = getPageBase().createSimpleTask("load value policy");
PrismObject<ValuePolicyType> valuePolicy = WebModelServiceUtils.resolveReferenceNoFetch(
valuePolicyRef, getPageBase(), task, task.getResult());
Expand Down Expand Up @@ -536,7 +550,7 @@ private CredentialsPolicyType getPasswordCredentialsPolicy(RefinedObjectClassDef
CredentialsPolicyType credentialsPolicyType = null;
try {
SecurityPolicyType securityPolicy = getPageBase().getModelInteractionService().getSecurityPolicy(rOCDef, task, result);
if (securityPolicy != null){
if (securityPolicy != null) {
credentialsPolicyType = securityPolicy.getCredentials();
}
result.recordSuccessIfUnknown();
Expand Down Expand Up @@ -580,7 +594,7 @@ private void addAccountsToMyPasswordsDto(MyPasswordsDto dto, List<PrismReference
}
}

private PasswordAccountDto createPasswordAccountDto(MyPasswordsDto passwordDto, PrismObject<ShadowType> account, Task task, OperationResult result){
private PasswordAccountDto createPasswordAccountDto(MyPasswordsDto passwordDto, PrismObject<ShadowType> account, Task task, OperationResult result) {
PrismReference resourceRef = account.findReference(ShadowType.F_RESOURCE_REF);
String resourceName;
if (resourceRef == null || resourceRef.getValue() == null || resourceRef.getValue().getObject() == null) {
Expand Down Expand Up @@ -651,15 +665,15 @@ private boolean getPasswordOutbound(PrismObject<ShadowType> shadow, ResourceType
return false;
}

private PasswordPanel getPasswordPanel(){
private PasswordPanel getPasswordPanel() {
return (PasswordPanel) get(ID_PASSWORD_PANEL);
}

private TablePanel getTable() {
return (TablePanel) get(getPageBase().createComponentPath(ID_ACCOUNTS_CONTAINER, ID_ACCOUNTS_TABLE));
}

protected boolean isCheckOldPassword(){
protected boolean isCheckOldPassword() {
return false;
}
}

0 comments on commit 8a09610

Please sign in to comment.