From 78a613b1dea4b753a108b3c3402e3669d7da6f5d Mon Sep 17 00:00:00 2001 From: rrajoria Date: Mon, 26 Sep 2022 12:29:13 +0530 Subject: [PATCH] ACA-4619: Forgot Password Changes --- .../ResetPasswordServiceImpl.java | 45 ++++++++++++++----- .../main/java/org/alfresco/util/UrlUtil.java | 34 ++++++++++++++ .../config/repo-clients-apps.properties | 7 +++ .../forgot-password-email-template.ftl | 12 +++++ 4 files changed, 86 insertions(+), 12 deletions(-) create mode 100644 repository/src/main/resources/alfresco/templates/reset-password-email-templates/forgot-password-email-template.ftl diff --git a/repository/src/main/java/org/alfresco/repo/security/authentication/ResetPasswordServiceImpl.java b/repository/src/main/java/org/alfresco/repo/security/authentication/ResetPasswordServiceImpl.java index 530002af89..a7ace09702 100644 --- a/repository/src/main/java/org/alfresco/repo/security/authentication/ResetPasswordServiceImpl.java +++ b/repository/src/main/java/org/alfresco/repo/security/authentication/ResetPasswordServiceImpl.java @@ -504,6 +504,21 @@ public class ResetPasswordServiceImpl implements ResetPasswordService return UrlUtil.replaceShareUrlPlaceholder(url, sysAdminParams); } + private String getAdwUrl(String url, String propName) + { + if (url == null) + { + LOGGER.warn("The url for the property [" + propName + "] is not configured."); + return ""; + } + + if (url.endsWith("/")) + { + url = url.substring(0, url.length() - 1); + } + return UrlUtil.replaceAdwUrlPlaceholder(url, sysAdminParams); + } + protected String getResetPasswordEmailTemplate(ClientApp clientApp) { return clientApp.getProperty("requestResetPasswordTemplatePath"); @@ -522,22 +537,28 @@ public class ResetPasswordServiceImpl implements ResetPasswordService StringBuilder sb = new StringBuilder(100); String pageUrl = clientApp.getProperty("resetPasswordPageUrl"); - if (StringUtils.isEmpty(pageUrl)) - { - sb.append(UrlUtil.getShareUrl(sysAdminParams)); - LOGGER.warn("'resetPasswordPageUrl' property is not set for the client [" + clientApp.getName() + if(clientApp.getName().equals("adw")) { + sb.append(getAdwUrl(pageUrl, "")); + LOGGER.warn("Client Name is " + clientApp.getName() + " The url used is " + sb.toString()); + sb.append("?key=").append(key) + .append("&id=").append(BPMEngineRegistry.createGlobalId(ActivitiConstants.ENGINE_ID, id)).append("&userName=").append(userName); + + } + else { + if (StringUtils.isEmpty(pageUrl)) { + sb.append(UrlUtil.getShareUrl(sysAdminParams)); + + LOGGER.warn("'resetPasswordPageUrl' property is not set for the client [" + clientApp.getName() + "]. The default base url of Share will be used [" + sb.toString() + "]"); - } - else - { - // We pass an empty string as we know that the pageUrl is not null - sb.append(getUrl(pageUrl, "")); - } + } else { + // We pass an empty string as we know that the pageUrl is not null + sb.append(getUrl(pageUrl, "")); + } - sb.append("?key=").append(key) + sb.append("?key=").append(key) .append("&id=").append(BPMEngineRegistry.createGlobalId(ActivitiConstants.ENGINE_ID, id)); - + } return sb.toString(); } diff --git a/repository/src/main/java/org/alfresco/util/UrlUtil.java b/repository/src/main/java/org/alfresco/util/UrlUtil.java index f040c31858..c8d57b7596 100644 --- a/repository/src/main/java/org/alfresco/util/UrlUtil.java +++ b/repository/src/main/java/org/alfresco/util/UrlUtil.java @@ -146,4 +146,38 @@ public class UrlUtil url.append(context); return url.toString(); } + + /** + * Builds up the Url to Adw based on the settings in the + * {@link SysAdminParams}. + * @return Adw Url such as https://col.ab.or.ate/#/ + * or http://localhost:8081/#/ + */ + public static String getAdwUrl(SysAdminParams sysAdminParams) + { + return buildUrl( + sysAdminParams.getAlfrescoProtocol(), + sysAdminParams.getAlfrescoHost(), + sysAdminParams.getAlfrescoPort(), + "#"); + } + + /** + * Replaces the adw url placeholder, namely {@literal ${alfrescoUrl}}, with adw url. + * + * @param value the string value which contains the share url placeholder + * @param sysAdminParams the {@code SysAdminParams} object + * @return if the given {@code value} contains share url placeholder, + * the placeholder is replaced with share url; otherwise, the given {@code value} is simply returned + */ + + public static String replaceAdwUrlPlaceholder(String value, SysAdminParams sysAdminParams) + { + if (value != null) + { + return REPO_PATTERN.matcher(value).replaceAll(getAdwUrl(sysAdminParams)); + } + return value; + } + } diff --git a/repository/src/main/resources/alfresco/client/config/repo-clients-apps.properties b/repository/src/main/resources/alfresco/client/config/repo-clients-apps.properties index 16e27a74e1..b47f062167 100644 --- a/repository/src/main/resources/alfresco/client/config/repo-clients-apps.properties +++ b/repository/src/main/resources/alfresco/client/config/repo-clients-apps.properties @@ -23,3 +23,10 @@ repo.client-app.share.confirmResetPasswordTemplatePath= repo.client-app.workspace.inviteModeratedTemplatePath= repo.client-app.workspace.workspaceUrl=workspace repo.client-app.workspace.templateAssetsUrl=${alfrescoUrl}/images + +# reset password request email template path +repo.client-app.adw.requestResetPasswordTemplatePath=alfresco/templates/reset-password-email-templates/forgot-password-email-template.ftl +# reset password UI page url +repo.client-app.adw.resetPasswordPageUrl=${alfrescoUrl}/reset-password/ +# reset password confirmation email template path +repo.client-app.adw.confirmResetPasswordTemplatePath= \ No newline at end of file diff --git a/repository/src/main/resources/alfresco/templates/reset-password-email-templates/forgot-password-email-template.ftl b/repository/src/main/resources/alfresco/templates/reset-password-email-templates/forgot-password-email-template.ftl new file mode 100644 index 0000000000..170532a6ac --- /dev/null +++ b/repository/src/main/resources/alfresco/templates/reset-password-email-templates/forgot-password-email-template.ftl @@ -0,0 +1,12 @@ + + + Forgot Password + + +

You are receiving this email because you(or someone else) requested the password reset of your account.

+

Please click on the following link, or paste this url into your browser to complete the process:

+

${reset_password_url}

+

If you received this in error, you can safely ignore it.

+

Kind regards

+ + \ No newline at end of file