This is an automated email from the ASF dual-hosted git repository. ilgrosso pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/syncope.git
commit 3aded5e99aff685a6ec2b710224e1b3d8b07f5f1 Author: fmartelli <[email protected]> AuthorDate: Fri Apr 17 09:40:04 2020 +0200 [SYNCOPE-957] provides the possibility to specify a layout for linked account management --- .../console/layout/IdMUserFormLayoutInfo.java | 38 ++++++++++ .../client/console/layout/LinkedAccountForm.java | 25 +++++++ .../layout/LinkedAccountFormLayoutInfo.java | 86 ++++++++++++++++++++++ .../console/panels/LinkedAccountModalPanel.java | 28 ++++++- .../wizards/any/LinkedAccountCredentialsPanel.java | 14 +++- .../wizards/any/LinkedAccountPlainAttrsPanel.java | 6 +- .../wizards/any/LinkedAccountWizardBuilder.java | 29 ++++++-- .../client/console/layout/UserFormLayoutInfo.java | 1 - 8 files changed, 213 insertions(+), 14 deletions(-) diff --git a/client/idm/console/src/main/java/org/apache/syncope/client/console/layout/IdMUserFormLayoutInfo.java b/client/idm/console/src/main/java/org/apache/syncope/client/console/layout/IdMUserFormLayoutInfo.java new file mode 100644 index 0000000..f3ae43b --- /dev/null +++ b/client/idm/console/src/main/java/org/apache/syncope/client/console/layout/IdMUserFormLayoutInfo.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.syncope.client.console.layout; + +public class IdMUserFormLayoutInfo extends UserFormLayoutInfo { + + private static final long serialVersionUID = -6577172426410570773L; + + private LinkedAccountFormLayoutInfo linkedAccountFormLayoutInfo; + + public IdMUserFormLayoutInfo() { + this.linkedAccountFormLayoutInfo = new LinkedAccountFormLayoutInfo(); + } + + public LinkedAccountFormLayoutInfo getLinkedAccountFormLayoutInfo() { + return linkedAccountFormLayoutInfo; + } + + public void setLinkedAccountFormLayoutInfo(final LinkedAccountFormLayoutInfo linkedAccountFormLayoutInfo) { + this.linkedAccountFormLayoutInfo = linkedAccountFormLayoutInfo; + } +} diff --git a/client/idm/console/src/main/java/org/apache/syncope/client/console/layout/LinkedAccountForm.java b/client/idm/console/src/main/java/org/apache/syncope/client/console/layout/LinkedAccountForm.java new file mode 100644 index 0000000..9a8c410 --- /dev/null +++ b/client/idm/console/src/main/java/org/apache/syncope/client/console/layout/LinkedAccountForm.java @@ -0,0 +1,25 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.syncope.client.console.layout; + +import org.apache.syncope.client.ui.commons.wizards.ModalPanelBuilder; +import org.apache.syncope.common.lib.to.LinkedAccountTO; + +public interface LinkedAccountForm extends ModalPanelBuilder<LinkedAccountTO> { +} diff --git a/client/idm/console/src/main/java/org/apache/syncope/client/console/layout/LinkedAccountFormLayoutInfo.java b/client/idm/console/src/main/java/org/apache/syncope/client/console/layout/LinkedAccountFormLayoutInfo.java new file mode 100644 index 0000000..5ba9115 --- /dev/null +++ b/client/idm/console/src/main/java/org/apache/syncope/client/console/layout/LinkedAccountFormLayoutInfo.java @@ -0,0 +1,86 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.syncope.client.console.layout; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; +import org.apache.syncope.client.console.wizards.any.LinkedAccountWizardBuilder; + +public class LinkedAccountFormLayoutInfo implements Serializable { + + private static final long serialVersionUID = -5573691733739618511L; + + private Class<? extends LinkedAccountForm> formClass; + + private boolean credentials = true; + + private final List<String> whichCredentials = new ArrayList<>(); + + private boolean plainAttrs = true; + + private final List<String> whichPlainAttrs = new ArrayList<>(); + + private boolean privileges = true; + + protected Class<? extends LinkedAccountForm> getDefaultFormClass() { + return LinkedAccountWizardBuilder.class; + } + + public Class<? extends LinkedAccountForm> getFormClass() { + return formClass == null ? getDefaultFormClass() : formClass; + } + + public void setFormClass(final Class<? extends LinkedAccountForm> formClass) { + this.formClass = formClass; + } + + public boolean isPlainAttrs() { + return plainAttrs; + } + + public void setPlainAttrs(final boolean plainAttrs) { + this.plainAttrs = plainAttrs; + } + + public List<String> getWhichPlainAttrs() { + return whichPlainAttrs; + } + + public boolean isCredentials() { + return credentials; + } + + public void setCredentials(final boolean credentials) { + this.credentials = credentials; + } + + public List<String> getWhichCredentials() { + return whichCredentials; + } + + public boolean isPrivileges() { + return privileges; + } + + public void setPrivileges(final boolean privileges) { + this.privileges = privileges; + } + +} diff --git a/client/idm/console/src/main/java/org/apache/syncope/client/console/panels/LinkedAccountModalPanel.java b/client/idm/console/src/main/java/org/apache/syncope/client/console/panels/LinkedAccountModalPanel.java index fe87678..f6bcf8c 100644 --- a/client/idm/console/src/main/java/org/apache/syncope/client/console/panels/LinkedAccountModalPanel.java +++ b/client/idm/console/src/main/java/org/apache/syncope/client/console/panels/LinkedAccountModalPanel.java @@ -21,9 +21,16 @@ package org.apache.syncope.client.console.panels; import java.util.ArrayList; import java.util.Comparator; import java.util.List; +import java.util.stream.Collectors; import org.apache.commons.lang3.StringUtils; import org.apache.syncope.client.console.SyncopeConsoleSession; +import org.apache.syncope.client.console.layout.AnyLayout; +import org.apache.syncope.client.console.layout.AnyLayoutUtils; +import org.apache.syncope.client.console.layout.IdMUserFormLayoutInfo; +import org.apache.syncope.client.console.layout.LinkedAccountForm; +import org.apache.syncope.client.console.layout.LinkedAccountFormLayoutInfo; import org.apache.syncope.client.console.pages.BasePage; +import org.apache.syncope.client.console.rest.AnyTypeRestClient; import org.apache.syncope.client.console.rest.UserRestClient; import org.apache.syncope.client.console.status.LinkedAccountStatusPanel; import org.apache.syncope.client.console.status.ReconTaskPanel; @@ -38,6 +45,7 @@ import org.apache.syncope.client.ui.commons.wizards.AjaxWizard; import org.apache.syncope.common.lib.SyncopeClientException; import org.apache.syncope.common.lib.request.LinkedAccountUR; import org.apache.syncope.common.lib.request.UserUR; +import org.apache.syncope.common.lib.to.EntityTO; import org.apache.syncope.common.lib.to.LinkedAccountTO; import org.apache.syncope.common.lib.to.PullTaskTO; import org.apache.syncope.common.lib.to.PushTaskTO; @@ -64,7 +72,7 @@ public class LinkedAccountModalPanel extends Panel implements ModalPanel { private static final Logger LOG = LoggerFactory.getLogger(LinkedAccountModalPanel.class); - private final LinkedAccountWizardBuilder wizard; + private LinkedAccountForm wizard; private final WizardMgtPanel<LinkedAccountTO> list; @@ -74,6 +82,8 @@ public class LinkedAccountModalPanel extends Panel implements ModalPanel { private UserRestClient userRestClient = new UserRestClient(); + private AnyTypeRestClient anyTypeRestClient = new AnyTypeRestClient(); + private final List<LinkedAccountTO> linkedAccountTOs; @SuppressWarnings("unchecked") @@ -93,7 +103,21 @@ public class LinkedAccountModalPanel extends Panel implements ModalPanel { actionTogglePanel = new ActionLinksTogglePanel<>("toggle", pageRef); add(actionTogglePanel); - wizard = new LinkedAccountWizardBuilder(model, pageRef); + AnyLayout anyLayout = AnyLayoutUtils.fetch( + anyTypeRestClient.listAnyTypes().stream().map(EntityTO::getKey).collect(Collectors.toList())); + LinkedAccountFormLayoutInfo linkedAccountFormLayoutInfo = + anyLayout.getUser() instanceof IdMUserFormLayoutInfo + ? IdMUserFormLayoutInfo.class.cast(anyLayout.getUser()).getLinkedAccountFormLayoutInfo() + : new LinkedAccountFormLayoutInfo(); + + try { + wizard = linkedAccountFormLayoutInfo.getFormClass(). + getConstructor(model.getClass(), LinkedAccountFormLayoutInfo.class, PageReference.class). + newInstance(model, linkedAccountFormLayoutInfo, pageRef); + } catch (Exception e) { + LOG.error("Error instantiating form layout", e); + wizard = new LinkedAccountWizardBuilder(model, linkedAccountFormLayoutInfo, pageRef); + } ListViewPanel.Builder<LinkedAccountTO> builder = new ListViewPanel.Builder<LinkedAccountTO>( LinkedAccountTO.class, pageRef) { diff --git a/client/idm/console/src/main/java/org/apache/syncope/client/console/wizards/any/LinkedAccountCredentialsPanel.java b/client/idm/console/src/main/java/org/apache/syncope/client/console/wizards/any/LinkedAccountCredentialsPanel.java index e30cfc4..0414781 100644 --- a/client/idm/console/src/main/java/org/apache/syncope/client/console/wizards/any/LinkedAccountCredentialsPanel.java +++ b/client/idm/console/src/main/java/org/apache/syncope/client/console/wizards/any/LinkedAccountCredentialsPanel.java @@ -20,6 +20,7 @@ package org.apache.syncope.client.console.wizards.any; import de.agilecoders.wicket.extensions.markup.html.bootstrap.form.checkbox.bootstraptoggle.BootstrapToggle; import de.agilecoders.wicket.extensions.markup.html.bootstrap.form.checkbox.bootstraptoggle.BootstrapToggleConfig; +import java.util.List; import org.apache.commons.lang3.StringUtils; import org.apache.syncope.common.lib.to.LinkedAccountTO; import org.apache.syncope.client.console.commons.LinkedAccountPlainAttrProperty; @@ -49,12 +50,14 @@ public class LinkedAccountCredentialsPanel extends WizardStep { private final LinkedAccountTO linkedAccountTO; - public LinkedAccountCredentialsPanel(final EntityWrapper<LinkedAccountTO> modelObject) { + public LinkedAccountCredentialsPanel( + final EntityWrapper<LinkedAccountTO> modelObject, final List<String> whichCredentials) { super(); setOutputMarkupId(true); linkedAccountTO = modelObject.getInnerObject(); + boolean isUsernameManagementEnabled = whichCredentials.contains("username"); AjaxTextFieldPanel usernameField = new AjaxTextFieldPanel( "username", "username", @@ -64,9 +67,12 @@ public class LinkedAccountCredentialsPanel extends WizardStep { usernameProperty.setOverridable(StringUtils.isNotBlank(linkedAccountTO.getUsername())); usernameProperty.setSchema("username"); usernameProperty.getValues().add(linkedAccountTO.getUsername()); - usernameField.showExternAction(checkboxToggle(usernameProperty, usernameField)); + usernameField.showExternAction( + checkboxToggle(usernameProperty, usernameField).setEnabled(isUsernameManagementEnabled)); add(usernameField.setOutputMarkupId(true)); + usernameField.setEnabled(isUsernameManagementEnabled); + boolean isPasswordManagementEnabled = whichCredentials.contains("password"); AjaxPasswordFieldPanel passwordField = new AjaxPasswordFieldPanel( "password", "password", @@ -79,9 +85,11 @@ public class LinkedAccountCredentialsPanel extends WizardStep { passwordProperty.setOverridable(StringUtils.isNotBlank(linkedAccountTO.getPassword())); passwordProperty.setSchema("password"); passwordProperty.getValues().add(linkedAccountTO.getPassword()); - passwordField.showExternAction(checkboxToggle(passwordProperty, passwordField)); + passwordField.showExternAction( + checkboxToggle(passwordProperty, passwordField).setEnabled(isPasswordManagementEnabled)); ((PasswordTextField) passwordField.getField()).setResetPassword(false); add(passwordField.setOutputMarkupId(true)); + passwordField.setEnabled(isPasswordManagementEnabled); } private FormComponent<?> checkboxToggle( diff --git a/client/idm/console/src/main/java/org/apache/syncope/client/console/wizards/any/LinkedAccountPlainAttrsPanel.java b/client/idm/console/src/main/java/org/apache/syncope/client/console/wizards/any/LinkedAccountPlainAttrsPanel.java index aa2024b..6605691 100644 --- a/client/idm/console/src/main/java/org/apache/syncope/client/console/wizards/any/LinkedAccountPlainAttrsPanel.java +++ b/client/idm/console/src/main/java/org/apache/syncope/client/console/wizards/any/LinkedAccountPlainAttrsPanel.java @@ -43,7 +43,6 @@ import org.apache.syncope.client.ui.commons.markup.html.form.FieldPanel; import org.apache.syncope.client.ui.commons.wicket.markup.html.bootstrap.tabs.Accordion; import org.apache.syncope.client.ui.commons.wizards.AjaxWizard; import org.apache.syncope.common.lib.Attr; -import org.apache.syncope.client.console.layout.AnyLayoutUtils; import org.apache.syncope.common.lib.types.SchemaType; import org.apache.wicket.ajax.AjaxRequestTarget; import org.apache.wicket.extensions.markup.html.tabs.AbstractTab; @@ -72,12 +71,13 @@ public class LinkedAccountPlainAttrsPanel extends AbstractAttrsWizardStep<PlainS public <T extends AnyTO> LinkedAccountPlainAttrsPanel( final EntityWrapper<LinkedAccountTO> modelObject, - final UserTO userTO) throws IllegalArgumentException { + final UserTO userTO, + final List<String> whichPlainAttrs) throws IllegalArgumentException { super(userTO, AjaxWizard.Mode.EDIT, AnyTypeRestClient.read(userTO.getType()).getClasses(), - AnyLayoutUtils.fetch(List.of(userTO.getType())).getUser().getWhichPlainAttrs(), + whichPlainAttrs, modelObject); this.linkedAccountTO = modelObject.getInnerObject(); diff --git a/client/idm/console/src/main/java/org/apache/syncope/client/console/wizards/any/LinkedAccountWizardBuilder.java b/client/idm/console/src/main/java/org/apache/syncope/client/console/wizards/any/LinkedAccountWizardBuilder.java index fcfcb9e..9d430d7 100644 --- a/client/idm/console/src/main/java/org/apache/syncope/client/console/wizards/any/LinkedAccountWizardBuilder.java +++ b/client/idm/console/src/main/java/org/apache/syncope/client/console/wizards/any/LinkedAccountWizardBuilder.java @@ -23,6 +23,8 @@ import java.io.Serializable; import java.util.HashSet; import java.util.Set; import java.util.stream.Collectors; +import org.apache.syncope.client.console.layout.LinkedAccountForm; +import org.apache.syncope.client.console.layout.LinkedAccountFormLayoutInfo; import org.apache.syncope.client.console.rest.UserRestClient; import org.apache.syncope.client.console.wicket.markup.html.bootstrap.dialog.BaseModal.ModalEvent; import org.apache.syncope.client.console.wizards.BaseAjaxWizardBuilder; @@ -40,7 +42,7 @@ import org.apache.wicket.model.IModel; /** * Accounts wizard builder. */ -public class LinkedAccountWizardBuilder extends BaseAjaxWizardBuilder<LinkedAccountTO> { +public class LinkedAccountWizardBuilder extends BaseAjaxWizardBuilder<LinkedAccountTO> implements LinkedAccountForm { private static final long serialVersionUID = -9142332740863374891L; @@ -48,9 +50,15 @@ public class LinkedAccountWizardBuilder extends BaseAjaxWizardBuilder<LinkedAcco private final IModel<UserTO> model; - public LinkedAccountWizardBuilder(final IModel<UserTO> model, final PageReference pageRef) { + protected LinkedAccountFormLayoutInfo formLayoutInfo; + + public LinkedAccountWizardBuilder( + final IModel<UserTO> model, + final LinkedAccountFormLayoutInfo formLayoutInfo, + final PageReference pageRef) { super(new LinkedAccountTO(), pageRef); this.model = model; + this.formLayoutInfo = formLayoutInfo; } @Override @@ -61,9 +69,20 @@ public class LinkedAccountWizardBuilder extends BaseAjaxWizardBuilder<LinkedAcco @Override protected WizardModel buildModelSteps(final LinkedAccountTO modelObject, final WizardModel wizardModel) { wizardModel.add(new LinkedAccountDetailsPanel(modelObject)); - wizardModel.add(new LinkedAccountCredentialsPanel(new EntityWrapper<>(modelObject))); - wizardModel.add(new LinkedAccountPlainAttrsPanel(new EntityWrapper<>(modelObject), model.getObject())); - wizardModel.add(new LinkedAccountPrivilegesPanel(modelObject)); + if (formLayoutInfo.isCredentials()) { + wizardModel.add(new LinkedAccountCredentialsPanel( + new EntityWrapper<>(modelObject), formLayoutInfo.getWhichCredentials())); + } + + if (formLayoutInfo.isPlainAttrs()) { + wizardModel.add(new LinkedAccountPlainAttrsPanel( + new EntityWrapper<>(modelObject), model.getObject(), formLayoutInfo.getWhichPlainAttrs())); + } + + if (formLayoutInfo.isPrivileges()) { + wizardModel.add(new LinkedAccountPrivilegesPanel(modelObject)); + } + return wizardModel; } diff --git a/client/idrepo/console/src/main/java/org/apache/syncope/client/console/layout/UserFormLayoutInfo.java b/client/idrepo/console/src/main/java/org/apache/syncope/client/console/layout/UserFormLayoutInfo.java index 53e7182..22e7e89 100644 --- a/client/idrepo/console/src/main/java/org/apache/syncope/client/console/layout/UserFormLayoutInfo.java +++ b/client/idrepo/console/src/main/java/org/apache/syncope/client/console/layout/UserFormLayoutInfo.java @@ -61,5 +61,4 @@ public class UserFormLayoutInfo extends AbstractAnyFormLayout<UserTO, UserForm> public void setRelationships(final boolean relationships) { this.relationships = relationships; } - }
