mirror of
				https://github.com/Alfresco/alfresco-community-repo.git
				synced 2025-10-29 15:21:53 +00:00 
			
		
		
		
	Compare commits
	
		
			20 Commits
		
	
	
		
			20.59
			...
			feature/Re
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						 | 
					2526218bdb | ||
| 
						 | 
					4d717e0d89 | ||
| 
						 | 
					dbc6407f66 | ||
| 
						 | 
					401614db8a | ||
| 
						 | 
					79fe89c7f1 | ||
| 
						 | 
					a60547a4f0 | ||
| 
						 | 
					0517eb6605 | ||
| 
						 | 
					eae11c4de3 | ||
| 
						 | 
					6885b817e1 | ||
| 
						 | 
					91f3edf8e9 | ||
| 
						 | 
					479724365e | ||
| 
						 | 
					bb1d5899d9 | ||
| 
						 | 
					7ab5e8afd0 | ||
| 
						 | 
					5107fdfe41 | ||
| 
						 | 
					f59ff23a45 | ||
| 
						 | 
					5e2f1db714 | ||
| 
						 | 
					67ee2efc60 | ||
| 
						 | 
					1e7dc6ed8d | ||
| 
						 | 
					e5ea6db30c | ||
| 
						 | 
					78a613b1de | 
@@ -504,6 +504,21 @@ public class ResetPasswordServiceImpl implements ResetPasswordService
 | 
			
		||||
        return UrlUtil.replaceShareUrlPlaceholder(url, sysAdminParams);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private String getRepoBaseUrl(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.replaceRepoBaseUrlPlaceholder(url, sysAdminParams);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected String getResetPasswordEmailTemplate(ClientApp clientApp)
 | 
			
		||||
    {
 | 
			
		||||
        return clientApp.getProperty("requestResetPasswordTemplatePath");
 | 
			
		||||
@@ -522,20 +537,27 @@ 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(!StringUtils.isEmpty(clientApp.getProperty("workspaceUrl")))
 | 
			
		||||
        {
 | 
			
		||||
            String workspaceUrlPlaceholder = clientApp.getProperty("workspaceUrl");
 | 
			
		||||
            String workSpaceUrl = getRepoBaseUrl(workspaceUrlPlaceholder,"");
 | 
			
		||||
            sb.append(UrlUtil.replaceWorkSpaceUrlPlaceholder(pageUrl,workSpaceUrl));
 | 
			
		||||
            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));*/
 | 
			
		||||
        }
 | 
			
		||||
        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();
 | 
			
		||||
 
 | 
			
		||||
@@ -41,6 +41,12 @@ public class UrlUtil
 | 
			
		||||
    public static final Pattern PATTERN = Pattern.compile("\\$\\{shareUrl\\}");
 | 
			
		||||
    // ${alfrescoUrl} placeholder
 | 
			
		||||
    public static final Pattern REPO_PATTERN = Pattern.compile("\\$\\{alfrescoUrl\\}");
 | 
			
		||||
 | 
			
		||||
    public static final Pattern REPOBASE_PATTERN = Pattern.compile("\\$\\{repoBaseUrl\\}");
 | 
			
		||||
 | 
			
		||||
    public static final Pattern WORKSPACE_PATTERN = Pattern.compile("\\$\\{workspaceUrl\\}");
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Builds up the Url to Alfresco based on the settings in the 
 | 
			
		||||
     *  {@link SysAdminParams}. 
 | 
			
		||||
@@ -146,4 +152,68 @@ 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 getWorkspaceUrl(SysAdminParams sysAdminParams)
 | 
			
		||||
    {
 | 
			
		||||
        return buildWorkspaceUrl(
 | 
			
		||||
                sysAdminParams.getAlfrescoProtocol(),
 | 
			
		||||
                sysAdminParams.getAlfrescoHost(),
 | 
			
		||||
                sysAdminParams.getAlfrescoPort());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected static String buildWorkspaceUrl(String workSpaceProtocol, String workspaceHost, int workspacePort) {
 | 
			
		||||
        StringBuilder workspaceUrl = new StringBuilder();
 | 
			
		||||
        workspaceUrl.append(workSpaceProtocol);
 | 
			
		||||
        workspaceUrl.append("://");
 | 
			
		||||
        workspaceUrl.append(workspaceHost);
 | 
			
		||||
        if ("http".equals(workSpaceProtocol) && workspacePort == 80)
 | 
			
		||||
        {
 | 
			
		||||
            // Not needed
 | 
			
		||||
        }
 | 
			
		||||
        else if ("https".equals(workSpaceProtocol) && workspacePort == 443)
 | 
			
		||||
        {
 | 
			
		||||
            // Not needed
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            workspaceUrl.append(':');
 | 
			
		||||
            workspaceUrl.append(workspacePort);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return workspaceUrl.toString();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Replaces the repo base url placeholder, namely {@literal ${repoBaseUrl}}, with <b>workspace</b> url.
 | 
			
		||||
     *
 | 
			
		||||
     * @param value          the string value which contains the repoBase 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 replaceRepoBaseUrlPlaceholder(String value, SysAdminParams sysAdminParams)
 | 
			
		||||
    {
 | 
			
		||||
        if (value != null)
 | 
			
		||||
        {
 | 
			
		||||
            return REPOBASE_PATTERN.matcher(value).replaceAll(getWorkspaceUrl(sysAdminParams));
 | 
			
		||||
        }
 | 
			
		||||
        return value;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static String replaceWorkSpaceUrlPlaceholder(String pageUrl,String workspaceUrl)
 | 
			
		||||
    {
 | 
			
		||||
        if (pageUrl != null)
 | 
			
		||||
        {
 | 
			
		||||
            return WORKSPACE_PATTERN.matcher(pageUrl).replaceAll(workspaceUrl);
 | 
			
		||||
        }
 | 
			
		||||
        return pageUrl;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -20,6 +20,15 @@ repo.client-app.share.resetPasswordPageUrl=${shareUrl}/page/reset-password
 | 
			
		||||
repo.client-app.share.confirmResetPasswordTemplatePath=
 | 
			
		||||
 | 
			
		||||
### Digital workspace template configurations
 | 
			
		||||
repo.client-app.workspace.inviteModeratedTemplatePath=
 | 
			
		||||
repo.client-app.workspace.workspaceUrl=workspace
 | 
			
		||||
repo.client-app.workspace.templateAssetsUrl=${alfrescoUrl}/images
 | 
			
		||||
#repo.client-app.workspace.inviteModeratedTemplatePath=
 | 
			
		||||
 | 
			
		||||
repo.client-app.workspace.workspaceUrl=${repoBaseUrl}/workspace
 | 
			
		||||
 | 
			
		||||
repo.client-app.workspace.templateAssetsUrl=${workspaceUrl}/images
 | 
			
		||||
 | 
			
		||||
# reset password request email template path
 | 
			
		||||
repo.client-app.workspace.requestResetPasswordTemplatePath=alfresco/templates/reset-password-email-templates/forgot-password-email-template.ftl
 | 
			
		||||
# reset password UI page url
 | 
			
		||||
repo.client-app.workspace.resetPasswordPageUrl=${workspaceUrl}/reset-password/
 | 
			
		||||
# reset password confirmation email template path
 | 
			
		||||
repo.client-app.workspace.confirmResetPasswordTemplatePath=
 | 
			
		||||
@@ -0,0 +1,12 @@
 | 
			
		||||
<html>
 | 
			
		||||
<head>
 | 
			
		||||
   <title>Forgot Password</title>
 | 
			
		||||
</head>
 | 
			
		||||
<body>
 | 
			
		||||
<p>You are receiving this email because you(or someone else) requested the password reset of your account.</p>
 | 
			
		||||
<p>Please click on the following link, or paste this url into your browser to complete the process:</p>
 | 
			
		||||
<p><a href="${reset_password_url}">${reset_password_url}</a></p>
 | 
			
		||||
<p>If you received this in error, you can safely ignore it.</p>
 | 
			
		||||
<p>Kind regards</p>
 | 
			
		||||
</body>
 | 
			
		||||
</html>
 | 
			
		||||
@@ -92,6 +92,10 @@ public class ResetPasswordServiceImplTest
 | 
			
		||||
    private static TestPerson testPerson;
 | 
			
		||||
    private static EmailUtil emailUtil;
 | 
			
		||||
 | 
			
		||||
    private static TestPerson testPersonForWorkspace;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    @BeforeClass
 | 
			
		||||
    public static void initStaticData() throws Exception
 | 
			
		||||
    {
 | 
			
		||||
@@ -114,9 +118,18 @@ public class ResetPasswordServiceImplTest
 | 
			
		||||
                    .setPassword("password")
 | 
			
		||||
                    .setEmail(userName + "@example.com");
 | 
			
		||||
 | 
			
		||||
        String userNameForWorkspace = "shane.doe" + System.currentTimeMillis();
 | 
			
		||||
        testPersonForWorkspace = new TestPerson()
 | 
			
		||||
                .setUserName(userNameForWorkspace)
 | 
			
		||||
                .setFirstName("Shane")
 | 
			
		||||
                .setLastName("doe")
 | 
			
		||||
                .setPassword("password")
 | 
			
		||||
                .setEmail(userNameForWorkspace + "@example.com");
 | 
			
		||||
 | 
			
		||||
        transactionHelper.doInTransaction((RetryingTransactionCallback<Void>) () ->
 | 
			
		||||
        {
 | 
			
		||||
            createUser(testPerson);
 | 
			
		||||
            createUser(testPersonForWorkspace);
 | 
			
		||||
            return null;
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
@@ -153,6 +166,86 @@ public class ResetPasswordServiceImplTest
 | 
			
		||||
        emailUtil.reset();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    public void testResetPasswordForClientWorkspace() throws Exception
 | 
			
		||||
    {
 | 
			
		||||
        // Try the credential before change of password
 | 
			
		||||
        authenticateUser(testPersonForWorkspace.userName, testPersonForWorkspace.password);
 | 
			
		||||
 | 
			
		||||
        // Make sure to run as system
 | 
			
		||||
        AuthenticationUtil.clearCurrentSecurityContext();
 | 
			
		||||
        AuthenticationUtil.setRunAsUserSystem();
 | 
			
		||||
 | 
			
		||||
        // Request password reset
 | 
			
		||||
        resetPasswordService.requestReset(testPersonForWorkspace.userName, "workspace");
 | 
			
		||||
        assertEquals("A reset password email should have been sent.", 1, emailUtil.getSentCount());
 | 
			
		||||
        // Check the email
 | 
			
		||||
        MimeMessage msg = emailUtil.getLastEmail();
 | 
			
		||||
        assertNotNull("There should be an email.", msg);
 | 
			
		||||
        assertEquals("Should've been only one email recipient.", 1, msg.getAllRecipients().length);
 | 
			
		||||
        // Check the recipient is the person who requested the reset password
 | 
			
		||||
        assertEquals(testPersonForWorkspace.email, msg.getAllRecipients()[0].toString());
 | 
			
		||||
        //Check the sender is what we set as default
 | 
			
		||||
        assertEquals(DEFAULT_SENDER, msg.getFrom()[0].toString());
 | 
			
		||||
        // There should be a subject
 | 
			
		||||
        assertNotNull("There should be a subject.", msg.getSubject());
 | 
			
		||||
        // Check the default email subject - (check that we are sending the right email)
 | 
			
		||||
        String emailSubjectKey = getDeclaredField(SendResetPasswordEmailDelegate.class, "EMAIL_SUBJECT_KEY");
 | 
			
		||||
        assertNotNull(emailSubjectKey);
 | 
			
		||||
        assertEquals(msg.getSubject(), I18NUtil.getMessage(emailSubjectKey));
 | 
			
		||||
 | 
			
		||||
        // Check the reset password url.
 | 
			
		||||
        String resetPasswordUrl = (String) emailUtil.getLastEmailTemplateModelValue("reset_password_url");
 | 
			
		||||
        assertNotNull("Wrong email is sent.", resetPasswordUrl);
 | 
			
		||||
        // Get the workflow id and key
 | 
			
		||||
        Pair<String, String> pair = getWorkflowIdAndKeyFromUrl(resetPasswordUrl);
 | 
			
		||||
        assertNotNull("Workflow Id can't be null.", pair.getFirst());
 | 
			
		||||
        assertNotNull("Workflow Key can't be null.", pair.getSecond());
 | 
			
		||||
 | 
			
		||||
        emailUtil.reset();
 | 
			
		||||
        // Now that we have got the email, try to reset the password
 | 
			
		||||
        ResetPasswordDetails passwordDetails = new ResetPasswordDetails()
 | 
			
		||||
                .setUserId(testPersonForWorkspace.userName)
 | 
			
		||||
                .setPassword("newPassword")
 | 
			
		||||
                .setWorkflowId(pair.getFirst())
 | 
			
		||||
                .setWorkflowKey(pair.getSecond());
 | 
			
		||||
 | 
			
		||||
        resetPasswordService.initiateResetPassword(passwordDetails);
 | 
			
		||||
        assertEquals("A reset password confirmation email should have been sent.", 1, emailUtil.getSentCount());
 | 
			
		||||
        // Check the email
 | 
			
		||||
        msg = emailUtil.getLastEmail();
 | 
			
		||||
        assertNotNull("There should be an email.", msg);
 | 
			
		||||
        assertEquals("Should've been only one email recipient.", 1, msg.getAllRecipients().length);
 | 
			
		||||
        // Check the recipient is the person who requested the reset password
 | 
			
		||||
        assertEquals(testPersonForWorkspace.email, msg.getAllRecipients()[0].toString());
 | 
			
		||||
        // Check the sender is what we set as default
 | 
			
		||||
        assertEquals(DEFAULT_SENDER, msg.getFrom()[0].toString());
 | 
			
		||||
        // There should be a subject
 | 
			
		||||
        assertNotNull("There should be a subject.", msg.getSubject());
 | 
			
		||||
        // Check the default email subject - (check that we are sending the right email)
 | 
			
		||||
        emailSubjectKey = getDeclaredField(SendResetPasswordConfirmationEmailDelegate.class, "EMAIL_SUBJECT_KEY");
 | 
			
		||||
        assertNotNull(emailSubjectKey);
 | 
			
		||||
        assertEquals(msg.getSubject(), I18NUtil.getMessage(emailSubjectKey));
 | 
			
		||||
 | 
			
		||||
        // Try the old credential
 | 
			
		||||
        TestHelper.assertThrows(() -> authenticateUser(testPersonForWorkspace.userName, testPersonForWorkspace.password),
 | 
			
		||||
                AuthenticationException.class,
 | 
			
		||||
                "As the user changed her password, the authentication should have failed.");
 | 
			
		||||
 | 
			
		||||
        // Try the new credential
 | 
			
		||||
        authenticateUser(testPersonForWorkspace.userName, "newPassword");
 | 
			
		||||
 | 
			
		||||
        // Make sure to run as system
 | 
			
		||||
        AuthenticationUtil.clearCurrentSecurityContext();
 | 
			
		||||
        AuthenticationUtil.setRunAsUserSystem();
 | 
			
		||||
        emailUtil.reset();
 | 
			
		||||
        // Try reset again with the used workflow
 | 
			
		||||
        TestHelper.assertThrows(() -> resetPasswordService.initiateResetPassword(passwordDetails),
 | 
			
		||||
                InvalidResetPasswordWorkflowException.class,
 | 
			
		||||
                "The workflow instance is not active (it has already been used).");
 | 
			
		||||
        assertEquals("No email should have been sent.", 0, emailUtil.getSentCount());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    public void testResetPassword() throws Exception
 | 
			
		||||
    {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user