This is an automated email from the ASF dual-hosted git repository. ilgrosso pushed a commit to branch 4_0_X in repository https://gitbox.apache.org/repos/asf/syncope.git
commit 07b0d27d7553bd2ead79ff9486b5ca01f69be0dd Author: Francesco Chicchiriccò <ilgro...@apache.org> AuthorDate: Wed Aug 6 11:40:41 2025 +0200 [SYNCOPE-1904] Adding exceptions for value like username which looks like Base64 but it is not --- .../console/panels/WAConfigDirectoryPanel.java | 6 +- .../client/console/rest/WAConfigRestClient.java | 4 ++ .../console/panels/ParametersDirectoryPanel.java | 27 +++++-- .../console/panels/ParametersModalPanel.java | 84 +++++++++++----------- 4 files changed, 70 insertions(+), 51 deletions(-) diff --git a/client/am/console/src/main/java/org/apache/syncope/client/console/panels/WAConfigDirectoryPanel.java b/client/am/console/src/main/java/org/apache/syncope/client/console/panels/WAConfigDirectoryPanel.java index 36c160f67b..bd008fdf79 100644 --- a/client/am/console/src/main/java/org/apache/syncope/client/console/panels/WAConfigDirectoryPanel.java +++ b/client/am/console/src/main/java/org/apache/syncope/client/console/panels/WAConfigDirectoryPanel.java @@ -78,7 +78,11 @@ public class WAConfigDirectoryPanel extends AttrListDirectoryPanel { public void onClick(final AjaxRequestTarget target, final Attr ignore) { target.add(modal); modal.header(new StringResourceModel("any.edit")); - modal.setContent(new WAConfigModalPanel(modal, model.getObject(), AjaxWizard.Mode.EDIT, pageRef)); + modal.setContent(new WAConfigModalPanel( + modal, + ((WAConfigRestClient) restClient).get(model.getObject().getSchema()), + AjaxWizard.Mode.EDIT, + pageRef)); modal.show(true); } }, ActionLink.ActionType.EDIT, AMEntitlement.WA_CONFIG_SET); diff --git a/client/am/console/src/main/java/org/apache/syncope/client/console/rest/WAConfigRestClient.java b/client/am/console/src/main/java/org/apache/syncope/client/console/rest/WAConfigRestClient.java index c803821bfc..4dce2e8b33 100644 --- a/client/am/console/src/main/java/org/apache/syncope/client/console/rest/WAConfigRestClient.java +++ b/client/am/console/src/main/java/org/apache/syncope/client/console/rest/WAConfigRestClient.java @@ -30,6 +30,10 @@ public class WAConfigRestClient extends BaseRestClient { return getService(WAConfigService.class).list(); } + public Attr get(final String schema) { + return getService(WAConfigService.class).get(schema); + } + public void set(final Attr value) { getService(WAConfigService.class).set(value); } diff --git a/client/idrepo/console/src/main/java/org/apache/syncope/client/console/panels/ParametersDirectoryPanel.java b/client/idrepo/console/src/main/java/org/apache/syncope/client/console/panels/ParametersDirectoryPanel.java index 5a9c8d3e3f..b152d25dc1 100644 --- a/client/idrepo/console/src/main/java/org/apache/syncope/client/console/panels/ParametersDirectoryPanel.java +++ b/client/idrepo/console/src/main/java/org/apache/syncope/client/console/panels/ParametersDirectoryPanel.java @@ -59,6 +59,13 @@ public class ParametersDirectoryPanel private static final long serialVersionUID = 2765863608539154422L; + protected static ConfParam toConfParam(final String key, final Object value) { + ConfParam param = new ConfParam(); + param.setSchema(key); + param.setValues(value); + return param; + } + @SpringBean protected ConfParamOps confParamOps; @@ -143,10 +150,20 @@ public class ParametersDirectoryPanel @Override public void onClick(final AjaxRequestTarget target, final ConfParam ignore) { + Object value = confParamOps.get( + SyncopeConsoleSession.get().getDomain(), + model.getObject().getSchema(), + null, + Object.class); + target.add(modal); modal.header(new StringResourceModel("any.edit")); modal.setContent(new ParametersModalPanel( - modal, model.getObject(), confParamOps, AjaxWizard.Mode.EDIT, pageRef)); + modal, + toConfParam(model.getObject().getSchema(), value), + confParamOps, + AjaxWizard.Mode.EDIT, + pageRef)); modal.show(true); } }, ActionLink.ActionType.EDIT, null); @@ -189,12 +206,8 @@ public class ParametersDirectoryPanel public Iterator<ConfParam> iterator(final long first, final long count) { List<ConfParam> list = confParamOps.list(SyncopeConsoleSession.get().getDomain()).entrySet().stream(). skip(first).limit(count). - map(entry -> { - ConfParam param = new ConfParam(); - param.setSchema(entry.getKey()); - param.setValues(entry.getValue()); - return param; - }).collect(Collectors.toList()); + map(entry -> toConfParam(entry.getKey(), entry.getValue())). + collect(Collectors.toList()); list.sort(comparator); return list.iterator(); diff --git a/client/idrepo/console/src/main/java/org/apache/syncope/client/console/panels/ParametersModalPanel.java b/client/idrepo/console/src/main/java/org/apache/syncope/client/console/panels/ParametersModalPanel.java index 9a56ffc95a..58725545f7 100644 --- a/client/idrepo/console/src/main/java/org/apache/syncope/client/console/panels/ParametersModalPanel.java +++ b/client/idrepo/console/src/main/java/org/apache/syncope/client/console/panels/ParametersModalPanel.java @@ -26,6 +26,7 @@ import java.io.IOException; import java.io.StringReader; import java.text.ParseException; import java.util.Base64; +import java.util.Set; import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParserFactory; import org.apache.commons.lang3.time.DateFormatUtils; @@ -43,11 +44,13 @@ public class ParametersModalPanel extends AbstractModalPanel<ConfParam> { private static final long serialVersionUID = 4024126489500665435L; - private static final JsonMapper JSON_MAPPER = JsonMapper.builder().findAndAddModules().build(); + protected static final Set<String> BASE64_EXCEPTIONS = Set.of("username"); - private static final SAXParserFactory SAX_PARSER_FACTORY = SAXParserFactory.newInstance(); + protected static final JsonMapper JSON_MAPPER = JsonMapper.builder().findAndAddModules().build(); - private static boolean isDate(final String value) { + protected static final SAXParserFactory SAX_PARSER_FACTORY = SAXParserFactory.newInstance(); + + protected static boolean isDate(final String value) { try { DateFormatUtils.ISO_8601_EXTENDED_DATETIME_TIME_ZONE_FORMAT.parse(value); return true; @@ -56,16 +59,16 @@ public class ParametersModalPanel extends AbstractModalPanel<ConfParam> { } } - private static boolean isBase64(final String value) { + protected static boolean isBase64(final String value) { try { Base64.getDecoder().decode(value); - return value.length() % 4 == 0; + return value.length() % 4 == 0 && !BASE64_EXCEPTIONS.contains(value); } catch (IllegalArgumentException iae) { return false; } } - private static boolean isJSON(final String value) { + protected static boolean isJSON(final String value) { try { JSON_MAPPER.readTree(value); return true; @@ -74,7 +77,7 @@ public class ParametersModalPanel extends AbstractModalPanel<ConfParam> { } } - private static boolean isXML(final String value) { + protected static boolean isXML(final String value) { try { SAX_PARSER_FACTORY.newSAXParser().getXMLReader().parse(new InputSource(new StringReader(value))); return true; @@ -83,7 +86,7 @@ public class ParametersModalPanel extends AbstractModalPanel<ConfParam> { } } - private static boolean isPEM(final String value) { + protected static boolean isPEM(final String value) { try (PemReader reader = new PemReader(new StringReader(value))) { return reader.readPemObject() != null; } catch (IOException e) { @@ -91,7 +94,7 @@ public class ParametersModalPanel extends AbstractModalPanel<ConfParam> { } } - private final ParametersWizardPanel.ParametersForm form; + protected final ParametersWizardPanel.ParametersForm form; public ParametersModalPanel( final BaseModal<ConfParam> modal, @@ -105,44 +108,39 @@ public class ParametersModalPanel extends AbstractModalPanel<ConfParam> { PlainSchemaTO schema = new PlainSchemaTO(); schema.setMultivalue(param.isMultivalue()); schema.setMimeType(MediaType.APPLICATION_OCTET_STREAM); - if (param.getSchema() != null) { - if (param.isInstance(Boolean.class)) { - schema.setType(AttrSchemaType.Boolean); - } else if (param.isInstance(Integer.class) || param.isInstance(Long.class)) { - schema.setType(AttrSchemaType.Long); - } else if (param.isInstance(Float.class) || param.isInstance(Double.class)) { - schema.setType(AttrSchemaType.Double); - } else // attempt to guess type from content: otherwise, it's bare String - if (!param.getValues().isEmpty()) { - // 1. is it Date? - if (isDate(param.getValues().getFirst().toString())) { - schema.setType(AttrSchemaType.Date); - } else // 2. does it look like Base64? - if (isBase64(param.getValues().getFirst().toString())) { - schema.setType(AttrSchemaType.Binary); - String value = new String(Base64.getDecoder().decode(param.getValues().getFirst().toString())); - - // 3. is it JSON? - if (isJSON(value)) { - schema.setMimeType(MediaType.APPLICATION_JSON); - } else // 4. is it XML? - if (isXML(value)) { - schema.setMimeType(MediaType.APPLICATION_XML); - } else // 5. is it PEM? - if (isPEM(value)) { - schema.setMimeType("application/x-pem-file"); - } - } else { - schema.setType(AttrSchemaType.String); + + if (param.isInstance(Boolean.class)) { + schema.setType(AttrSchemaType.Boolean); + } else if (param.isInstance(Integer.class) || param.isInstance(Long.class)) { + schema.setType(AttrSchemaType.Long); + } else if (param.isInstance(Float.class) || param.isInstance(Double.class)) { + schema.setType(AttrSchemaType.Double); + } else // attempt to guess type from content: otherwise, it's bare String + if (!param.getValues().isEmpty()) { + // 1. is it Date? + if (isDate(param.getValues().getFirst().toString())) { + schema.setType(AttrSchemaType.Date); + } else // 2. does it look like Base64? + if (isBase64(param.getValues().getFirst().toString())) { + schema.setType(AttrSchemaType.Binary); + String value = new String(Base64.getDecoder().decode(param.getValues().getFirst().toString())); + + // 3. is it JSON? + if (isJSON(value)) { + schema.setMimeType(MediaType.APPLICATION_JSON); + } else // 4. is it XML? + if (isXML(value)) { + schema.setMimeType(MediaType.APPLICATION_XML); + } else // 5. is it PEM? + if (isPEM(value)) { + schema.setMimeType("application/x-pem-file"); } + } else { + schema.setType(AttrSchemaType.String); } } - if (schema.getType() == AttrSchemaType.Binary) { - modal.size(Modal.Size.Extra_large); - } else { - modal.size(Modal.Size.Default); - } + modal.size(schema.getType() == AttrSchemaType.Binary ? Modal.Size.Extra_large : Modal.Size.Default); form = new ParametersWizardPanel.ParametersForm(schema, param); add(new ParametersWizardPanel(form, confParamOps, pageRef).build("parametersCreateWizardPanel", mode));