Skip to content

Commit

Permalink
another changes for reset password - hide password propagation
Browse files Browse the repository at this point in the history
  • Loading branch information
katkav committed Apr 3, 2020
1 parent fb00be2 commit 245d675
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 9 deletions.
Expand Up @@ -8,6 +8,7 @@

import com.evolveum.midpoint.web.application.Url;
import com.evolveum.midpoint.web.page.admin.home.dto.MyPasswordsDto;
import com.evolveum.midpoint.web.page.admin.home.dto.PasswordAccountDto;
import com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType;

import org.apache.wicket.ajax.AjaxRequestTarget;
Expand All @@ -28,6 +29,9 @@
import com.evolveum.midpoint.web.page.self.PageSelf;
import com.evolveum.midpoint.xml.ns._public.common.common_3.UserType;

import java.util.Collections;
import java.util.List;

@PageDescriptor(
urls = {
@Url(mountUrl = PageResetPassword.URL, matchUrlForSecurity = PageResetPassword.URL)
Expand Down Expand Up @@ -108,4 +112,20 @@ protected void createBreadcrumb() {
protected boolean shouldLoadAccounts(MyPasswordsDto dto) {
return false;
}

@Override
protected List<PasswordAccountDto> getSelectedAccountsList() {
List<PasswordAccountDto> accounts = getModelObject().getAccounts();
if (accounts.isEmpty()) {
return Collections.EMPTY_LIST;
}

for (PasswordAccountDto account : accounts) {
if (account.isMidpoint()) {
return Collections.singletonList(account);
}
}

return accounts;
}
}
Expand Up @@ -201,7 +201,12 @@ private void initLayout() {

@Override
public WebMarkupContainer getPanel(String panelId) {
return new ChangePasswordPanel(panelId, isCheckOldPassword(), model, model.getObject());
return new ChangePasswordPanel(panelId, isCheckOldPassword(), model, model.getObject()) {
@Override
protected boolean shouldShowPasswordPropagation() {
return shouldLoadAccounts(getModelObject());
}
};
}
});

Expand Down Expand Up @@ -275,8 +280,6 @@ private PasswordAccountDto createPasswordAccountDto(PrismObject<ShadowType> acco
}

protected void onSavePerformed(AjaxRequestTarget target) {
List<PasswordAccountDto> selectedAccounts = getSelectedAccountsList();

ProtectedStringType oldPassword = null;
if (isCheckOldPassword()) {
LOGGER.debug("Check old password");
Expand Down Expand Up @@ -310,13 +313,16 @@ protected void onSavePerformed(AjaxRequestTarget target) {
}
}
}
if (selectedAccounts.isEmpty()) {
warn(getString("PageSelfCredentials.noAccountSelected"));

if (getModelObject().getPassword() == null ) {
warn(getString("PageSelfCredentials.emptyPasswordFiled"));
target.add(getFeedbackPanel());
return;
}
if (getModelObject().getPassword() == null ) {
warn(getString("PageSelfCredentials.emptyPasswordFiled"));

List<PasswordAccountDto> selectedAccounts = getSelectedAccountsList();
if (selectedAccounts.isEmpty()) {
warn(getString("PageSelfCredentials.noAccountSelected"));
target.add(getFeedbackPanel());
return;
}
Expand All @@ -333,7 +339,6 @@ protected void onSavePerformed(AjaxRequestTarget target) {
SchemaRegistry registry = getPrismContext().getSchemaRegistry();
Collection<ObjectDelta<? extends ObjectType>> deltas = new ArrayList<>();


for (PasswordAccountDto accDto : selectedAccounts) {
PrismObjectDefinition objDef = accDto.isMidpoint() ?
registry.findObjectDefinitionByCompileTimeClass(UserType.class) :
Expand Down Expand Up @@ -376,7 +381,7 @@ protected void setNullEncryptedPasswordData() {

protected abstract void finishChangePassword(OperationResult result, AjaxRequestTarget target);

private List<PasswordAccountDto> getSelectedAccountsList(){
protected List<PasswordAccountDto> getSelectedAccountsList(){
List<PasswordAccountDto> passwordAccountDtos = model.getObject().getAccounts();
List<PasswordAccountDto> selectedAccountList = new ArrayList<>();
if (model.getObject().getPropagation() != null
Expand Down
Expand Up @@ -146,10 +146,20 @@ public void onClick(AjaxRequestTarget target) {
};

accountContainer.add(help);
accountContainer.add(new VisibleEnableBehaviour() {
@Override
public boolean isVisible() {
return shouldShowPasswordPropagation();
}
});

add(accountContainer);
}

protected boolean shouldShowPasswordPropagation() {
return true;
}

private List<IColumn<PasswordAccountDto, String>> initColumns() {
List<IColumn<PasswordAccountDto, String>> columns = new ArrayList<>();

Expand Down

0 comments on commit 245d675

Please sign in to comment.