From 88f06e373ec74d7fa9c72df0deb2bcf74e9fc07a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francesco=20Chicchiricc=C3=B2?= Date: Fri, 4 Aug 2023 18:48:25 +0200 Subject: [PATCH] Missing Console support --- .../AuthProfileDirectoryPanel.java | 61 +++++++++++++++++++ .../client/console/commons/AMConstants.java | 6 +- .../AuthProfileDirectoryPanel.properties | 5 ++ ...AuthProfileDirectoryPanel_fr_CA.properties | 5 ++ .../AuthProfileDirectoryPanel_it.properties | 5 ++ .../AuthProfileDirectoryPanel_ja.properties | 5 ++ ...AuthProfileDirectoryPanel_pt_BR.properties | 5 ++ .../AuthProfileDirectoryPanel_ru.properties | 5 ++ .../syncope/client/ui/commons/DateOps.java | 48 ++++++++++++--- .../client/console/panels/BeanPanel.java | 6 +- .../client/console/rest/ReportRestClient.java | 2 +- .../client/console/rest/TaskRestClient.java | 2 +- .../data/table/DatePropertyColumn.java | 3 + .../wizards/DelegationWizardBuilder.java | 4 +- .../console/panels/SCIMConfGeneralPanel.java | 4 +- 15 files changed, 151 insertions(+), 15 deletions(-) diff --git a/client/am/console/src/main/java/org/apache/syncope/client/console/authprofiles/AuthProfileDirectoryPanel.java b/client/am/console/src/main/java/org/apache/syncope/client/console/authprofiles/AuthProfileDirectoryPanel.java index 80f2dfc9ae..f8f86b7034 100644 --- a/client/am/console/src/main/java/org/apache/syncope/client/console/authprofiles/AuthProfileDirectoryPanel.java +++ b/client/am/console/src/main/java/org/apache/syncope/client/console/authprofiles/AuthProfileDirectoryPanel.java @@ -45,6 +45,7 @@ import org.apache.syncope.common.lib.wa.GoogleMfaAuthAccount; import org.apache.syncope.common.lib.wa.GoogleMfaAuthToken; import org.apache.syncope.common.lib.wa.ImpersonationAccount; +import org.apache.syncope.common.lib.wa.MfaTrustedDevice; import org.apache.syncope.common.lib.wa.U2FDevice; import org.apache.syncope.common.lib.wa.WebAuthnDeviceCredential; import org.apache.wicket.PageReference; @@ -157,6 +158,15 @@ protected boolean isCondition(final IModel rowModel) { return !rowModel.getObject().getU2FRegisteredDevices().isEmpty(); } }); + columns.add(new BooleanConditionColumn<>(new StringResourceModel("mfaTrustedDevices")) { + + private static final long serialVersionUID = -8236820422411536323L; + + @Override + protected boolean isCondition(final IModel rowModel) { + return !rowModel.getObject().getMfaTrustedDevices().isEmpty(); + } + }); columns.add(new BooleanConditionColumn<>(new StringResourceModel("webAuthnAccount")) { private static final long serialVersionUID = -8236820422411536323L; @@ -368,6 +378,57 @@ protected List> getColumns() { } }, ActionLink.ActionType.FO_EDIT, AMEntitlement.AUTH_PROFILE_UPDATE); + panel.add(new ActionLink<>() { + + private static final long serialVersionUID = -3722207913631435501L; + + @Override + public void onClick(final AjaxRequestTarget target, final AuthProfileTO ignore) { + model.setObject(restClient.read(model.getObject().getKey())); + target.add(authProfileModal.setContent(new ModalDirectoryPanel<>( + authProfileModal, + new AuthProfileItemDirectoryPanel( + "panel", restClient, authProfileModal, model.getObject(), pageRef) { + + private static final long serialVersionUID = 5788448799796630011L; + + @Override + protected List getItems() { + return model.getObject().getMfaTrustedDevices(); + } + + @Override + protected MfaTrustedDevice defaultItem() { + return new MfaTrustedDevice(); + } + + @Override + protected String sortProperty() { + return "id"; + } + + @Override + protected String paginatorRowsKey() { + return AMConstants.PREF_AUTHPROFILE_MFA_TRUSTED_FDEVICES_PAGINATOR_ROWS; + } + + @Override + protected List> getColumns() { + List> columns = new ArrayList<>(); + columns.add(new PropertyColumn<>(new ResourceModel("id"), "id", "id")); + columns.add(new PropertyColumn<>(new ResourceModel("name"), "name", "name")); + columns.add(new DatePropertyColumn<>( + new ResourceModel("recordDate"), "recordDate", "recordDate")); + columns.add(new DatePropertyColumn<>( + new ResourceModel("expirationDate"), "expirationDate", "expirationDate")); + return columns; + } + }, pageRef))); + authProfileModal.header(new Model<>(getString("mfaTrustedDevices", model))); + authProfileModal.show(true); + } + }, ActionLink.ActionType.DOWN, AMEntitlement.AUTH_PROFILE_UPDATE); + panel.add(new ActionLink<>() { private static final long serialVersionUID = -3722207913631435501L; diff --git a/client/am/console/src/main/java/org/apache/syncope/client/console/commons/AMConstants.java b/client/am/console/src/main/java/org/apache/syncope/client/console/commons/AMConstants.java index c185b55d1a..08c9663fb5 100644 --- a/client/am/console/src/main/java/org/apache/syncope/client/console/commons/AMConstants.java +++ b/client/am/console/src/main/java/org/apache/syncope/client/console/commons/AMConstants.java @@ -48,7 +48,11 @@ public final class AMConstants { public static final String PREF_AUTHPROFILE_GOOGLEMFAAUTHACCOUNTS_PAGINATOR_ROWS = "authprofile.googlemfaauthaccounts.paginator.rows"; - public static final String PREF_AUTHPROFILE_U2FDEVICES_PAGINATOR_ROWS = "authprofile.u2fdevices.paginator.rows"; + public static final String PREF_AUTHPROFILE_U2FDEVICES_PAGINATOR_ROWS = + "authprofile.u2fdevices.paginator.rows"; + + public static final String PREF_AUTHPROFILE_MFA_TRUSTED_FDEVICES_PAGINATOR_ROWS = + "authprofile.mfaTrustedDevices.paginator.rows"; public static final String PREF_AUTHPROFILE_WEBAUTHNDEVICECREDENTIALS_PAGINATOR_ROWS = "authprofile.webAuthnDeviceCredentials.paginator.rows"; diff --git a/client/am/console/src/main/resources/org/apache/syncope/client/console/authprofiles/AuthProfileDirectoryPanel.properties b/client/am/console/src/main/resources/org/apache/syncope/client/console/authprofiles/AuthProfileDirectoryPanel.properties index e095d91b2b..56627ae0a4 100644 --- a/client/am/console/src/main/resources/org/apache/syncope/client/console/authprofiles/AuthProfileDirectoryPanel.properties +++ b/client/am/console/src/main/resources/org/apache/syncope/client/console/authprofiles/AuthProfileDirectoryPanel.properties @@ -44,3 +44,8 @@ json=JSON html.class=fas fa-at html.title=webauthn webAuthnDeviceCredentials=WebAuthn Device Credentials +expirationDate=Expiration Date +recordDate=Record Date +mfaTrustedDevices=MFA Devices +down.title=mfa devices +down.class=fas fa-barcode diff --git a/client/am/console/src/main/resources/org/apache/syncope/client/console/authprofiles/AuthProfileDirectoryPanel_fr_CA.properties b/client/am/console/src/main/resources/org/apache/syncope/client/console/authprofiles/AuthProfileDirectoryPanel_fr_CA.properties index 8a42e53c73..495d278dbc 100644 --- a/client/am/console/src/main/resources/org/apache/syncope/client/console/authprofiles/AuthProfileDirectoryPanel_fr_CA.properties +++ b/client/am/console/src/main/resources/org/apache/syncope/client/console/authprofiles/AuthProfileDirectoryPanel_fr_CA.properties @@ -44,3 +44,8 @@ json=JSON html.class=fas fa-at html.title=webauthn webAuthnDeviceCredentials=WebAuthn Device Credentials +expirationDate=Expiration Date +recordDate=Record Date +mfaTrustedDevices=MFA Devices +down.title=mfa devices +down.class=fas fa-barcode diff --git a/client/am/console/src/main/resources/org/apache/syncope/client/console/authprofiles/AuthProfileDirectoryPanel_it.properties b/client/am/console/src/main/resources/org/apache/syncope/client/console/authprofiles/AuthProfileDirectoryPanel_it.properties index 0fd02d5f98..cc0d9a5ce7 100644 --- a/client/am/console/src/main/resources/org/apache/syncope/client/console/authprofiles/AuthProfileDirectoryPanel_it.properties +++ b/client/am/console/src/main/resources/org/apache/syncope/client/console/authprofiles/AuthProfileDirectoryPanel_it.properties @@ -44,3 +44,8 @@ json=JSON html.class=fas fa-at html.title=webauthn webAuthnDeviceCredentials=Dispositivi Credenziali WebAuthn +expirationDate=Scadenza +recordDate=Memorizzazione +mfaTrustedDevices=Dispositivi MFA +down.title=dispositivi mfa +down.class=fas fa-barcode diff --git a/client/am/console/src/main/resources/org/apache/syncope/client/console/authprofiles/AuthProfileDirectoryPanel_ja.properties b/client/am/console/src/main/resources/org/apache/syncope/client/console/authprofiles/AuthProfileDirectoryPanel_ja.properties index d2fc5697f7..f3d1ac236c 100644 --- a/client/am/console/src/main/resources/org/apache/syncope/client/console/authprofiles/AuthProfileDirectoryPanel_ja.properties +++ b/client/am/console/src/main/resources/org/apache/syncope/client/console/authprofiles/AuthProfileDirectoryPanel_ja.properties @@ -44,3 +44,8 @@ json=JSON html.class=fas fa-at html.title=webauthn webAuthnDeviceCredentials=WebAuthn Device Credentials +expirationDate=Expiration Date +recordDate=Record Date +mfaTrustedDevices=MFA Devices +down.title=mfa devices +down.class=fas fa-barcode diff --git a/client/am/console/src/main/resources/org/apache/syncope/client/console/authprofiles/AuthProfileDirectoryPanel_pt_BR.properties b/client/am/console/src/main/resources/org/apache/syncope/client/console/authprofiles/AuthProfileDirectoryPanel_pt_BR.properties index 8d919ed952..e227e6f900 100644 --- a/client/am/console/src/main/resources/org/apache/syncope/client/console/authprofiles/AuthProfileDirectoryPanel_pt_BR.properties +++ b/client/am/console/src/main/resources/org/apache/syncope/client/console/authprofiles/AuthProfileDirectoryPanel_pt_BR.properties @@ -44,3 +44,8 @@ json=JSON html.class=fas fa-at html.title=webauthn webAuthnDeviceCredentials=WebAuthn Device Credentials +expirationDate=Expiration Date +recordDate=Record Date +mfaTrustedDevices=MFA Devices +down.title=mfa devices +down.class=fas fa-barcode diff --git a/client/am/console/src/main/resources/org/apache/syncope/client/console/authprofiles/AuthProfileDirectoryPanel_ru.properties b/client/am/console/src/main/resources/org/apache/syncope/client/console/authprofiles/AuthProfileDirectoryPanel_ru.properties index b638d451d5..a60b6d6825 100644 --- a/client/am/console/src/main/resources/org/apache/syncope/client/console/authprofiles/AuthProfileDirectoryPanel_ru.properties +++ b/client/am/console/src/main/resources/org/apache/syncope/client/console/authprofiles/AuthProfileDirectoryPanel_ru.properties @@ -45,3 +45,8 @@ json=JSON html.class=fas fa-at html.title=webauthn webAuthnDeviceCredentials=WebAuthn Device Credentials +expirationDate=Expiration Date +recordDate=Record Date +mfaTrustedDevices=MFA Devices +down.title=mfa devices +down.class=fas fa-barcode diff --git a/client/idrepo/common-ui/src/main/java/org/apache/syncope/client/ui/commons/DateOps.java b/client/idrepo/common-ui/src/main/java/org/apache/syncope/client/ui/commons/DateOps.java index f68187b4cb..17216b409b 100644 --- a/client/idrepo/common-ui/src/main/java/org/apache/syncope/client/ui/commons/DateOps.java +++ b/client/idrepo/common-ui/src/main/java/org/apache/syncope/client/ui/commons/DateOps.java @@ -20,7 +20,9 @@ import java.io.Serializable; import java.time.OffsetDateTime; +import java.time.ZoneId; import java.time.ZoneOffset; +import java.time.ZonedDateTime; import java.util.Date; import java.util.Optional; import org.apache.commons.lang3.StringUtils; @@ -46,39 +48,71 @@ public String format(final Date date) { public String format(final OffsetDateTime date) { return Optional.ofNullable(date).map(v -> fdf.format(convert(date))).orElse(StringUtils.EMPTY); } + + public String format(final ZonedDateTime date) { + return Optional.ofNullable(date).map(v -> fdf.format(convert(date))).orElse(StringUtils.EMPTY); + } } - public static class WrappedDateModel implements IModel, Serializable { + public static final class WrappedDateModel implements IModel, Serializable { private static final long serialVersionUID = 31027882183172L; - private final IModel wrapped; + public static WrappedDateModel ofOffset(final IModel offset) { + WrappedDateModel instance = new WrappedDateModel(); + instance.offset = offset; + return instance; + } + + public static WrappedDateModel ofZoned(final IModel zoned) { + WrappedDateModel instance = new WrappedDateModel(); + instance.zoned = zoned; + return instance; + } + + private IModel offset; - public WrappedDateModel(final IModel wrapped) { - this.wrapped = wrapped; + private IModel zoned; + + private WrappedDateModel() { + // private constructor for static utility class } @Override public Date getObject() { - return convert(wrapped.getObject()); + return offset == null ? convert(zoned.getObject()) : convert(offset.getObject()); } @Override public void setObject(final Date object) { - wrapped.setObject(convert(object)); + if (offset == null) { + zoned.setObject(toZonedDateTime(object)); + } else { + offset.setObject(toOffsetDateTime(object)); + } } } public static final ZoneOffset DEFAULT_OFFSET = OffsetDateTime.now().getOffset(); + public static final ZoneId DEFAULT_ZONE = ZonedDateTime.now().getZone(); + public static Date convert(final OffsetDateTime date) { return Optional.ofNullable(date).map(v -> new Date(v.toInstant().toEpochMilli())).orElse(null); } - public static OffsetDateTime convert(final Date date) { + public static Date convert(final ZonedDateTime date) { + return Optional.ofNullable(date).map(v -> new Date(v.toInstant().toEpochMilli())).orElse(null); + } + + public static OffsetDateTime toOffsetDateTime(final Date date) { return Optional.ofNullable(date).map(v -> v.toInstant().atOffset(DEFAULT_OFFSET)).orElse(null); } + public static ZonedDateTime toZonedDateTime(final Date date) { + return Optional.ofNullable(date).map(v -> ZonedDateTime.ofInstant(v.toInstant(), DEFAULT_ZONE)).orElse(null); + } + private DateOps() { // private constructor for static utility class } diff --git a/client/idrepo/console/src/main/java/org/apache/syncope/client/console/panels/BeanPanel.java b/client/idrepo/console/src/main/java/org/apache/syncope/client/console/panels/BeanPanel.java index 7ee7b5e73b..aef0071628 100644 --- a/client/idrepo/console/src/main/java/org/apache/syncope/client/console/panels/BeanPanel.java +++ b/client/idrepo/console/src/main/java/org/apache/syncope/client/console/panels/BeanPanel.java @@ -27,6 +27,7 @@ import java.lang.reflect.ParameterizedType; import java.time.Duration; import java.time.OffsetDateTime; +import java.time.ZonedDateTime; import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -301,7 +302,10 @@ private Triple> buildSinglePanel( panel = new AjaxDateTimeFieldPanel(id, fieldName, model, DateFormatUtils.ISO_8601_EXTENDED_DATETIME_TIME_ZONE_FORMAT); } else if (OffsetDateTime.class.equals(type)) { - panel = new AjaxDateTimeFieldPanel(id, fieldName, new DateOps.WrappedDateModel(model), + panel = new AjaxDateTimeFieldPanel(id, fieldName, DateOps.WrappedDateModel.ofOffset(model), + DateFormatUtils.ISO_8601_EXTENDED_DATETIME_TIME_ZONE_FORMAT); + } else if (ZonedDateTime.class.equals(type)) { + panel = new AjaxDateTimeFieldPanel(id, fieldName, DateOps.WrappedDateModel.ofZoned(model), DateFormatUtils.ISO_8601_EXTENDED_DATETIME_TIME_ZONE_FORMAT); } else if (type.isEnum()) { panel = new AjaxDropDownChoicePanel(id, fieldName, model). diff --git a/client/idrepo/console/src/main/java/org/apache/syncope/client/console/rest/ReportRestClient.java b/client/idrepo/console/src/main/java/org/apache/syncope/client/console/rest/ReportRestClient.java index cb2a03c886..3e8d480569 100644 --- a/client/idrepo/console/src/main/java/org/apache/syncope/client/console/rest/ReportRestClient.java +++ b/client/idrepo/console/src/main/java/org/apache/syncope/client/console/rest/ReportRestClient.java @@ -85,7 +85,7 @@ public void delete(final String reportKey) { @Override public void startExecution(final String reportKey, final Date startAt) { getService(ReportService.class).execute(new ExecSpecs.Builder().key(reportKey). - startAt(DateOps.convert(startAt)).build()); + startAt(DateOps.toOffsetDateTime(startAt)).build()); } @Override diff --git a/client/idrepo/console/src/main/java/org/apache/syncope/client/console/rest/TaskRestClient.java b/client/idrepo/console/src/main/java/org/apache/syncope/client/console/rest/TaskRestClient.java index e4b6dc67f3..1a9b50014b 100644 --- a/client/idrepo/console/src/main/java/org/apache/syncope/client/console/rest/TaskRestClient.java +++ b/client/idrepo/console/src/main/java/org/apache/syncope/client/console/rest/TaskRestClient.java @@ -203,7 +203,7 @@ public void startExecution(final String taskKey, final Date startAt) { public void startExecution(final String taskKey, final Date startAt, final boolean dryRun) { getService(TaskService.class).execute(new ExecSpecs.Builder().key(taskKey). - startAt(DateOps.convert(startAt)).dryRun(dryRun).build()); + startAt(DateOps.toOffsetDateTime(startAt)).dryRun(dryRun).build()); } @Override diff --git a/client/idrepo/console/src/main/java/org/apache/syncope/client/console/wicket/extensions/markup/html/repeater/data/table/DatePropertyColumn.java b/client/idrepo/console/src/main/java/org/apache/syncope/client/console/wicket/extensions/markup/html/repeater/data/table/DatePropertyColumn.java index 83c1e68cbd..bdc0674ffe 100644 --- a/client/idrepo/console/src/main/java/org/apache/syncope/client/console/wicket/extensions/markup/html/repeater/data/table/DatePropertyColumn.java +++ b/client/idrepo/console/src/main/java/org/apache/syncope/client/console/wicket/extensions/markup/html/repeater/data/table/DatePropertyColumn.java @@ -19,6 +19,7 @@ package org.apache.syncope.client.console.wicket.extensions.markup.html.repeater.data.table; import java.time.OffsetDateTime; +import java.time.ZonedDateTime; import java.util.Date; import org.apache.syncope.client.console.SyncopeConsoleSession; import org.apache.wicket.extensions.markup.html.repeater.data.grid.ICellPopulator; @@ -49,6 +50,8 @@ public void populateItem(final Item> item, final String compon String convertedDate = ""; if (date.getObject() instanceof OffsetDateTime) { convertedDate = SyncopeConsoleSession.get().getDateFormat().format((OffsetDateTime) date.getObject()); + } else if (date.getObject() instanceof ZonedDateTime) { + convertedDate = SyncopeConsoleSession.get().getDateFormat().format((ZonedDateTime) date.getObject()); } else if (date.getObject() instanceof Date) { convertedDate = SyncopeConsoleSession.get().getDateFormat().format((Date) date.getObject()); } diff --git a/client/idrepo/console/src/main/java/org/apache/syncope/client/console/wizards/DelegationWizardBuilder.java b/client/idrepo/console/src/main/java/org/apache/syncope/client/console/wizards/DelegationWizardBuilder.java index c284bfba6f..675f2ecf42 100644 --- a/client/idrepo/console/src/main/java/org/apache/syncope/client/console/wizards/DelegationWizardBuilder.java +++ b/client/idrepo/console/src/main/java/org/apache/syncope/client/console/wizards/DelegationWizardBuilder.java @@ -151,14 +151,14 @@ private static class StartEnd extends WizardStep { add(new AjaxDateTimeFieldPanel( "start", "start", - new DateOps.WrappedDateModel(new PropertyModel<>(modelObject, "start")), + DateOps.WrappedDateModel.ofOffset(new PropertyModel<>(modelObject, "start")), DateFormatUtils.ISO_8601_EXTENDED_DATETIME_TIME_ZONE_FORMAT). addRequiredLabel()); add(new AjaxDateTimeFieldPanel( "end", "end", - new DateOps.WrappedDateModel(new PropertyModel<>(modelObject, "end")), + DateOps.WrappedDateModel.ofOffset(new PropertyModel<>(modelObject, "end")), DateFormatUtils.ISO_8601_EXTENDED_DATETIME_TIME_ZONE_FORMAT)); } } diff --git a/ext/scimv2/client-console/src/main/java/org/apache/syncope/client/console/panels/SCIMConfGeneralPanel.java b/ext/scimv2/client-console/src/main/java/org/apache/syncope/client/console/panels/SCIMConfGeneralPanel.java index 00a76404d1..257d225501 100644 --- a/ext/scimv2/client-console/src/main/java/org/apache/syncope/client/console/panels/SCIMConfGeneralPanel.java +++ b/ext/scimv2/client-console/src/main/java/org/apache/syncope/client/console/panels/SCIMConfGeneralPanel.java @@ -50,7 +50,7 @@ public Date getObject() { @Override public void setObject(final Date object) { - scimGeneralConf.setCreationDate(DateOps.convert(object)); + scimGeneralConf.setCreationDate(DateOps.toOffsetDateTime(object)); } }, DateFormatUtils.ISO_8601_EXTENDED_DATETIME_TIME_ZONE_FORMAT); creationDatePanel.setEnabled(false); @@ -67,7 +67,7 @@ public Date getObject() { @Override public void setObject(final Date object) { - scimGeneralConf.setLastChangeDate(DateOps.convert(object)); + scimGeneralConf.setLastChangeDate(DateOps.toOffsetDateTime(object)); } }, DateFormatUtils.ISO_8601_EXTENDED_DATETIME_TIME_ZONE_FORMAT); lastChangeDatePanel.setEnabled(false);