Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import org.apache.commons.lang3.StringUtils;
import org.apache.syncope.client.console.commons.LinkedAccountPlainAttrProperty;
import org.apache.syncope.client.ui.commons.Constants;
import org.apache.syncope.client.ui.commons.ajax.form.IndicatorAjaxFormComponentUpdatingBehavior;
Expand All @@ -42,6 +44,7 @@
import org.apache.syncope.common.lib.to.LinkedAccountTO;
import org.apache.syncope.common.lib.to.PlainSchemaTO;
import org.apache.syncope.common.lib.to.UserTO;
import org.apache.syncope.common.lib.types.AttrSchemaType;
import org.apache.syncope.common.lib.types.SchemaType;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.extensions.markup.html.tabs.AbstractTab;
Expand Down Expand Up @@ -81,8 +84,8 @@ public <T extends AnyTO> LinkedAccountPlainAttrsPanel(

this.linkedAccountTO = modelObject.getInnerObject();
this.fixedAttrs.addAll(this.linkedAccountTO.getPlainAttrs().stream().
filter(attrTO -> checkIsReadonlyAttr(attrTO.getSchema())).
toList());
filter(attr -> isReadonly(attr.getSchema())).
toList());
this.userTO = userTO;

add(new Accordion("plainSchemas", List.of(new AbstractTab(
Expand All @@ -97,6 +100,10 @@ public WebMarkupContainer getPanel(final String panelId) {
}), Model.of(0)).setOutputMarkupId(true));
}

private boolean isReadonly(final String schema) {
return schemas.isEmpty() ? true : !schemas.get(schema).isReadonly();
}

@Override
protected FormComponent<?> checkboxToggle(
final Attr attrTO,
Expand All @@ -115,11 +122,10 @@ protected FormComponent<?> checkboxToggle(
return newProperty;
});

final BootstrapToggleConfig config = new BootstrapToggleConfig().
BootstrapToggleConfig config = new BootstrapToggleConfig().
withOnStyle(BootstrapToggleConfig.Style.success).
withOffStyle(BootstrapToggleConfig.Style.danger).
withSize(BootstrapToggleConfig.Size.mini);

return new BootstrapToggle("externalAction", new PropertyModel<>(property, "overridable"), config) {

private static final long serialVersionUID = -875219845189261873L;
Expand Down Expand Up @@ -166,8 +172,8 @@ protected void onComponentTag(final ComponentTag tag) {

private void updateAccountPlainSchemas(final LinkedAccountPlainAttrProperty property, final Boolean modelObject) {
Set<Attr> withoutCurrentSchema = new HashSet<>(linkedAccountTO.getPlainAttrs().stream().
filter(attrTO -> !attrTO.getSchema().equals(property.getSchema())
&& checkIsReadonlyAttr(attrTO.getSchema())).
filter(attr -> !attr.getSchema().equals(property.getSchema())
&& isReadonly(attr.getSchema())).
collect(Collectors.toSet()));
linkedAccountTO.getPlainAttrs().clear();
linkedAccountTO.getPlainAttrs().addAll(withoutCurrentSchema);
Expand All @@ -186,28 +192,28 @@ protected SchemaType getSchemaType() {

@Override
protected void setAttrs() {
List<Attr> attrs = new ArrayList<>();
List<Attr> plainAttrs = new ArrayList<>();
List<PlainSchemaTO> notReadonlyValues = schemas.values().stream().
filter(schema -> checkIsReadonlyAttr(schema.getKey())).
collect(Collectors.toList());
filter(schema -> !schema.isReadonly()).
toList();
setFixedAttr(notReadonlyValues);
Map<String, Attr> attrMap = EntityTOUtils.buildAttrMap(fixedAttrs);

attrs.addAll(notReadonlyValues.stream().
map(schema -> {
Attr attrTO = new Attr();
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;
}).
toList());
plainAttrs.addAll(notReadonlyValues.stream().map(schema -> {
Attr attr = Optional.ofNullable(attrMap.get(schema.getKey())).orElseGet(() -> {
Attr newAttr = new Attr();
newAttr.setSchema(schema.getKey());
return newAttr;
});
if ((schema.getType() != AttrSchemaType.Dropdown || !schema.isMultivalue()) && attr.getValues().isEmpty()) {
attr.getValues().add(StringUtils.EMPTY);
}

return attr;
}).toList());

fixedAttrs.clear();
fixedAttrs.addAll(attrs);
fixedAttrs.addAll(plainAttrs);
}

@Override
Expand All @@ -221,10 +227,6 @@ private void setFixedAttr(final Collection<PlainSchemaTO> values) {
() -> userTO.getPlainAttr(schema.getKey()).ifPresent(fixedAttrs::add)));
}

private boolean checkIsReadonlyAttr(final String schema) {
return schemas.isEmpty() ? true : !schemas.get(schema).isReadonly();
}

private class PlainSchemasOwn extends PlainSchemas<List<Attr>> {

private static final long serialVersionUID = -4730563859116024676L;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,14 +220,10 @@ public LoadableDetachableModel<List<T>> getChoicesModel() {

@Override
public AjaxPalettePanel<T> setModelObject(final List<T> object) {
palette.setDefaultModelObject(object);
palette.setModelObject(object);
return this;
}

public Collection<T> getModelCollection() {
return palette.getModelCollection();
}

public void reload(final AjaxRequestTarget target) {
target.add(palette);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.apache.syncope.common.lib.jackson.SyncopeJsonMapper;
import org.apache.wicket.util.cookies.CookieDefaults;
import org.apache.wicket.util.cookies.CookieUtils;
import org.slf4j.Logger;
Expand All @@ -46,7 +45,7 @@ public final class PreferenceManager implements Serializable {

private static final int ONE_YEAR_TIME = 60 * 60 * 24 * 365;

private static final JsonMapper MAPPER = new SyncopeJsonMapper();
private static final JsonMapper MAPPER = JsonMapper.builder().findAndAddModules().build();

private static final TypeReference<Map<String, String>> MAP_TYPE_REF = new TypeReference<>() {
};
Expand Down Expand Up @@ -160,14 +159,10 @@ public static void set(final String key, final String value) {
}
}

public static void setList(final String key, final List<String> values) {
public static void set(final String key, final List<String> values) {
set(key, String.join(";", values));
}

public static void setList(final Map<String, List<String>> prefs) {
set(prefs);
}

private PreferenceManager() {
// private constructor for static utility class
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.apache.commons.lang3.StringUtils;
import org.apache.syncope.client.console.SyncopeConsoleSession;
import org.apache.syncope.client.console.rest.AbstractAnyRestClient;
Expand Down Expand Up @@ -74,10 +73,7 @@ private static AnyLayout empty(final List<String> anyTypes) {
}

public static AnyLayout fetch(final RoleRestClient roleRestClient, final List<String> anyTypes) {
List<String> ownedRoles = Stream.concat(
SyncopeConsoleSession.get().getSelfTO().getRoles().stream(),
SyncopeConsoleSession.get().getSelfTO().getDynRoles().stream()).
distinct().toList();
List<String> ownedRoles = SyncopeConsoleSession.get().getSelfTO().getRoles();
try {
AnyLayout anyLayout = null;
for (int i = 0; i < ownedRoles.size() && anyLayout == null; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public void onSubmit(final AjaxRequestTarget target) {
prefs.put(detailsPreferenceKey, selectedDetails);
prefs.put(plainAttrsPreferenceKey, selectedPlainSchemas);
prefs.put(derAttrsPreferenceKey, selectedDerSchemas);
PreferenceManager.setList(prefs);
PreferenceManager.set(prefs);

SyncopeConsoleSession.get().success(getString(Constants.OPERATION_SUCCEEDED));
modal.close(target);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ protected List<IColumn<A, String>> getColumns() {
prefcolumns);
}

PreferenceManager.setList(
PreferenceManager.set(
AnyDisplayAttributesModalPanel.getPrefDetailView(type),
List.of(getDefaultAttributeSelection()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ protected List<IColumn<RealmTO, String>> getColumns() {
prefcolumns);
}

PreferenceManager.setList(
PreferenceManager.set(
IdRepoConstants.PREF_REALM_DETAILS_VIEW,
RealmDisplayAttributesModalPanel.DEFAULT_COLUMNS);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public PageReference getPageReference() {
}

@SuppressWarnings("unchecked")
protected AbstractFieldPanel<?> getFieldPanel(final PlainSchemaTO plainSchema) {
protected AbstractFieldPanel<?> getFieldPanel(final PlainSchemaTO plainSchema, final ListItem<Attr> item) {
final boolean required;
final boolean readOnly;
final AttrSchemaType type;
Expand Down Expand Up @@ -281,8 +281,10 @@ public String getObject(
: List.of();
if (plainSchema.isMultivalue()) {
panel = new AjaxPalettePanel.Builder<String>().
setName(plainSchema.getLabel(SyncopeConsoleSession.get().getLocale())).
build("panel", new ListModel<>(), new ListModel<>(dropdownValues));
setName(plainSchema.getLabel(SyncopeConsoleSession.get().getLocale())).build(
"panel",
new PropertyModel<>(item.getModelObject(), "values"),
new ListModel<>(dropdownValues));
} else {
panel = new AjaxDropDownChoicePanel<>("panel",
plainSchema.getLabel(SyncopeConsoleSession.get().getLocale()), new Model<>(), true);
Expand Down Expand Up @@ -432,20 +434,15 @@ protected AbstractFieldPanel<?> setPanel(
Attr attr = item.getModelObject();
PlainSchemaTO schema = schemas.get(attr.getSchema());

AbstractFieldPanel<?> panel = getFieldPanel(schema);
panel.setReadOnly(setReadOnly);
if (mode != AjaxWizard.Mode.TEMPLATE
&& schema.isMultivalue()
&& schema.getType() != AttrSchemaType.Dropdown) {

AbstractFieldPanel<?> panel = getFieldPanel(schema, item).setReadOnly(setReadOnly);
if (panel instanceof FieldPanel fieldPanel && mode != AjaxWizard.Mode.TEMPLATE && schema.isMultivalue()) {
// SYNCOPE-1476 set form as multipart to properly manage membership attributes
panel = new MultiFieldPanel.Builder<>(
new PropertyModel<>(attr, "values")).build(
panel = new MultiFieldPanel.Builder<>(new PropertyModel<>(attr, "values")).build(
"panel",
schema.getLabel(SyncopeConsoleSession.get().getLocale()),
FieldPanel.class.cast(panel)).setFormAsMultipart(true);
// SYNCOPE-1215 the entire multifield panel must be readonly, not only its field
MultiFieldPanel.class.cast(panel).setFormReadOnly(setReadOnly);
fieldPanel).
setFormAsMultipart(true).
setFormReadOnly(setReadOnly);
} else if (panel instanceof AjaxPalettePanel ajaxPalettePanel) {
ajaxPalettePanel.setModelObject(attr.getValues());
} else {
Expand All @@ -465,8 +462,8 @@ protected void setExternalAction(final Attr attr, final AbstractFieldPanel<?> pa

Optional<Attr> prevAttr = previousObject.getPlainAttr(attr.getSchema());
if (prevAttr.map(a -> !ListUtils.isEqualList(
a.getValues().stream().filter(StringUtils::isNotBlank).collect(Collectors.toList()),
attr.getValues().stream().filter(StringUtils::isNotBlank).collect(Collectors.toList()))).
a.getValues().stream().filter(StringUtils::isNotBlank).toList(),
attr.getValues().stream().filter(StringUtils::isNotBlank).toList())).
orElseGet(() -> attr.getValues().stream().anyMatch(StringUtils::isNotBlank))) {

List<String> oldValues = prevAttr.map(Attr::getValues).orElseGet(List::of);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,13 @@ protected void setAttrs() {
Map<String, Attr> attrMap = EntityTOUtils.buildAttrMap(attributable.getDerAttrs());

schemas.values().forEach(schema -> {
Attr attrTO = new Attr();
attrTO.setSchema(schema.getKey());
Attr attr = new Attr();
attr.setSchema(schema.getKey());
if (attrMap.containsKey(schema.getKey())) {
attrTO.getValues().addAll(attrMap.get(schema.getKey()).getValues());
attr.getValues().addAll(attrMap.get(schema.getKey()).getValues());
}

derAttrs.add(attrTO);
derAttrs.add(attr);
});

attributable.getDerAttrs().clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair;
Expand Down Expand Up @@ -186,15 +187,15 @@ protected void setAttrs() {
Map<String, Attr> attrMap = EntityTOUtils.buildAttrMap(attributable.getPlainAttrs());

List<Attr> plainAttrs = schemas.values().stream().map(schema -> {
Attr attr = new Attr();
attr.setSchema(schema.getKey());
if (attrMap.get(schema.getKey()) == null || attrMap.get(schema.getKey()).getValues().isEmpty()) {
if (schema.getType() != AttrSchemaType.Dropdown || !schema.isMultivalue()) {
attr.getValues().add(StringUtils.EMPTY);
}
} else {
attr = attrMap.get(schema.getKey());
Attr attr = Optional.ofNullable(attrMap.get(schema.getKey())).orElseGet(() -> {
Attr newAttr = new Attr();
newAttr.setSchema(schema.getKey());
return newAttr;
});
if ((schema.getType() != AttrSchemaType.Dropdown || !schema.isMultivalue()) && attr.getValues().isEmpty()) {
attr.getValues().add(StringUtils.EMPTY);
}

return attr;
}).toList();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,8 @@
import org.apache.wicket.authroles.authorization.strategies.role.metadata.MetaDataRoleAuthorizationStrategy;
import org.apache.wicket.extensions.wizard.WizardModel.ICondition;
import org.apache.wicket.extensions.wizard.WizardStep;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.model.PropertyModel;
import org.apache.wicket.model.util.ListModel;
import org.apache.wicket.spring.injection.annot.SpringBean;

public class Roles extends WizardStep implements ICondition {
Expand All @@ -55,8 +53,6 @@ public class Roles extends WizardStep implements ICondition {

protected final UserTO userTO;

protected WebMarkupContainer dynrolesContainer;

public <T extends AnyTO> Roles(final UserWrapper modelObject) {
if (modelObject.getPreviousUserTO() != null
&& !modelObject.getInnerObject().getRoles().equals(modelObject.getPreviousUserTO().getRoles())) {
Expand All @@ -82,15 +78,6 @@ public <T extends AnyTO> Roles(final UserWrapper modelObject) {
allRoles = getManagedRoles();

add(buildRolesSelector(modelObject));

dynrolesContainer = new WebMarkupContainer("dynrolesContainer");
dynrolesContainer.setOutputMarkupId(true);
dynrolesContainer.setOutputMarkupPlaceholderTag(true);
add(dynrolesContainer);

dynrolesContainer.add(new AjaxPalettePanel.Builder<String>().build("dynroles",
new PropertyModel<>(userTO, "dynRoles"),
new ListModel<>(allRoles)).hideLabel().setEnabled(false).setOutputMarkupId(true));
}

protected List<String> getManagedRoles() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,5 @@ <h3 class="card-title">
<span wicket:id="roles">[ROLES]</span>
</div>
</div>

<div class="col-xs-12" wicket:id="dynrolesContainer">
<div class="card-header">
<h3 class="card-title">
<wicket:message key="dynroles.palette">[ROLES]</wicket:message>
</h3>
</div>
<div class="card-body">
<span wicket:id="dynroles">[ROLES]</span>
</div>
</div>
</wicket:panel>
</html>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,3 @@
# specific language governing permissions and limitations
# under the License.
roles.palette=Roles
dynroles.palette=Dynamic Roles
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,4 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
roles.palette=Rôles
dynroles.palette=Rôles dynamiques
roles.palette=R\u00f4les
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,3 @@
# specific language governing permissions and limitations
# under the License.
roles.palette=Ruoli
dynroles.palette=Ruoli Dinamici
Loading
Loading