This is an automated email from the ASF dual-hosted git repository. skylark17 pushed a commit to branch SYNCOPE-1537 in repository https://gitbox.apache.org/repos/asf/syncope.git
commit 7aefff395d612da6831bfbf1e66d48b432800d64 Author: skylark17 <skylar...@apache.org> AuthorDate: Wed Feb 26 12:33:26 2020 +0100 [SYNCOPE-1544] Also removed readonly attributes from showing in the list of plain attributes for linkedaccounts --- .../wizards/any/LinkedAccountCredentialsPanel.java | 15 +++++++- .../wizards/any/LinkedAccountPlainAttrsPanel.java | 43 ++++++++++++++-------- 2 files changed, 41 insertions(+), 17 deletions(-) diff --git a/client/console/src/main/java/org/apache/syncope/client/console/wizards/any/LinkedAccountCredentialsPanel.java b/client/console/src/main/java/org/apache/syncope/client/console/wizards/any/LinkedAccountCredentialsPanel.java index 089968b..b8d0d89 100644 --- a/client/console/src/main/java/org/apache/syncope/client/console/wizards/any/LinkedAccountCredentialsPanel.java +++ b/client/console/src/main/java/org/apache/syncope/client/console/wizards/any/LinkedAccountCredentialsPanel.java @@ -42,6 +42,10 @@ public class LinkedAccountCredentialsPanel extends WizardStep { private static final long serialVersionUID = 5116461957402341603L; + private String usernameValue; + + private String passwordValue; + private final LinkedAccountTO linkedAccountTO; public LinkedAccountCredentialsPanel(final EntityWrapper<LinkedAccountTO> modelObject) { @@ -68,7 +72,6 @@ public class LinkedAccountCredentialsPanel extends WizardStep { new PropertyModel<>(linkedAccountTO, "password"), false); passwordField.setMarkupId("password"); - passwordField.setPlaceholder("password"); passwordField.setRequired(true); FieldPanel.class.cast(passwordField).setReadOnly(StringUtils.isBlank(linkedAccountTO.getPassword())); LinkedAccountPlainAttrProperty passwordProperty = new LinkedAccountPlainAttrProperty(); @@ -102,10 +105,18 @@ public class LinkedAccountCredentialsPanel extends WizardStep { @Override protected void onUpdate(final AjaxRequestTarget target) { FieldPanel.class.cast(panel).setReadOnly(!model.getObject()); - if (!model.getObject()) { + if (model.getObject()) { + if (property.getSchema().equals("password")) { + linkedAccountTO.setPassword(passwordValue); + } else if (property.getSchema().equals("username")) { + linkedAccountTO.setUsername(usernameValue); + } + } else { if (property.getSchema().equals("password")) { + passwordValue = linkedAccountTO.getPassword(); linkedAccountTO.setPassword(null); } else if (property.getSchema().equals("username")) { + usernameValue = linkedAccountTO.getUsername(); linkedAccountTO.setUsername(null); } } diff --git a/client/console/src/main/java/org/apache/syncope/client/console/wizards/any/LinkedAccountPlainAttrsPanel.java b/client/console/src/main/java/org/apache/syncope/client/console/wizards/any/LinkedAccountPlainAttrsPanel.java index fec7bfa..61c45e6 100644 --- a/client/console/src/main/java/org/apache/syncope/client/console/wizards/any/LinkedAccountPlainAttrsPanel.java +++ b/client/console/src/main/java/org/apache/syncope/client/console/wizards/any/LinkedAccountPlainAttrsPanel.java @@ -81,9 +81,12 @@ public class LinkedAccountPlainAttrsPanel extends AbstractAttrsWizardStep<PlainS new AnyTypeRestClient().read(userTO.getType()).getClasses(), AnyLayoutUtils.fetch(Arrays.asList(userTO.getType())).getUser().getWhichPlainAttrs(), modelObject); + System.out.println("CCCCCCCCCCC"); this.linkedAccountTO = modelObject.getInnerObject(); - this.fixedAttrs.addAll(this.linkedAccountTO.getPlainAttrs()); + this.fixedAttrs.addAll(this.linkedAccountTO.getPlainAttrs().stream(). + filter(attrTO -> checkIsReadonlyAttr(attrTO.getSchema())). + collect(Collectors.toList())); this.userTO = userTO; add(new Accordion("plainSchemas", Collections.<ITab>singletonList(new AbstractTab( @@ -166,11 +169,12 @@ public class LinkedAccountPlainAttrsPanel extends AbstractAttrsWizardStep<PlainS } private void updateAccountPlainSchemas(final LinkedAccountPlainAttrProperty property, final Boolean modelObject) { - Set<AttrTO> withoutCurrentSChema = new HashSet<>(linkedAccountTO.getPlainAttrs().stream(). - filter(attr -> !attr.getSchema().equals(property.getSchema())). + Set<AttrTO> withoutCurrentSchema = new HashSet<>(linkedAccountTO.getPlainAttrs().stream(). + filter(attrTO -> !attrTO.getSchema().equals(property.getSchema()) + && checkIsReadonlyAttr(attrTO.getSchema())). collect(Collectors.toSet())); linkedAccountTO.getPlainAttrs().clear(); - linkedAccountTO.getPlainAttrs().addAll(withoutCurrentSChema); + linkedAccountTO.getPlainAttrs().addAll(withoutCurrentSchema); if (modelObject) { linkedAccountTO.getPlainAttrs().add( fixedAttrs.stream().filter(attrTO -> attrTO.getSchema().equals(property.getSchema())).findFirst(). @@ -187,19 +191,24 @@ public class LinkedAccountPlainAttrsPanel extends AbstractAttrsWizardStep<PlainS @Override protected void setAttrs() { List<AttrTO> attrs = new ArrayList<>(); - setFixedAttr(schemas.values()); + List<PlainSchemaTO> notReadonlyValues = schemas.values().stream(). + filter(schema -> checkIsReadonlyAttr(schema.getKey())). + collect(Collectors.toList()); + setFixedAttr(notReadonlyValues); Map<String, AttrTO> attrMap = EntityTOUtils.buildAttrMap(fixedAttrs); - attrs.addAll(schemas.values().stream().map(schema -> { - AttrTO attrTO = new AttrTO(); - attrTO.setSchema(schema.getKey()); - if (attrMap.get(schema.getKey()) == null || attrMap.get(schema.getKey()).getValues().isEmpty()) { - attrTO.getValues().add(""); - } else { - attrTO = attrMap.get(schema.getKey()); - } - return attrTO; - }).collect(Collectors.toList())); + attrs.addAll(notReadonlyValues.stream(). + map(schema -> { + AttrTO attrTO = new AttrTO(); + attrTO.setSchema(schema.getKey()); + if (attrMap.get(schema.getKey()) == null || attrMap.get(schema.getKey()).getValues().isEmpty()) { + attrTO.getValues().add(""); + } else { + attrTO = attrMap.get(schema.getKey()); + } + return attrTO; + }). + collect(Collectors.toList())); fixedAttrs.clear(); fixedAttrs.addAll(attrs); @@ -220,6 +229,10 @@ public class LinkedAccountPlainAttrsPanel extends AbstractAttrsWizardStep<PlainS }); } + private boolean checkIsReadonlyAttr(final String schema) { + return schemas.isEmpty() ? true : !schemas.get(schema).isReadonly(); + } + private class PlainSchemasOwn extends PlainSchemas<List<AttrTO>> { private static final long serialVersionUID = -4730563859116024676L;