Requesting a password reset for a person (user) in the repository involves these two API calls:
- PeopleApi.requestPasswordReset
- PeopleApi.resetPassword
For more information about this ReST API endpoint, see Request Password Reset for a Person.
import org.alfresco.core.handler.PeopleApi;
import org.alfresco.core.model.ClientBody;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.stereotype.Component;
import java.io.IOException;
@Component
public class RequestPwdResetCmd {
static final Logger LOGGER = LoggerFactory.getLogger(RequestPwdResetCmd.class);
@Autowired
PeopleApi peopleApi;
public void execute(String personId) throws IOException {
ClientBody clientBody = new ClientBody();
clientBody.setClient("share"); // Alfresco Share UI client
HttpEntity<Void> result = peopleApi.requestPasswordReset(personId, clientBody);
LOGGER.info("Password reset request sent for {} result {}", personId, result);
}
}
Executing this code will request a password request for user martin, an email will be sent to the user assuming the password request should be via the Alfresco Share UI:
% java -jar target/rest-api-0.0.1-SNAPSHOT.jar request-pwd-reset martin 2021-05-06 09:30:38.440 INFO 24356 --- [ main] o.a.tutorial.restapi.RestApiApplication : Started RestApiApplication in 3.438 seconds (JVM running for 3.939) 2021-05-06 09:30:38.442 INFO 24356 --- [ main] o.a.tutorial.restapi.RestApiApplication : args[0]: request-pwd-reset 2021-05-06 09:30:38.443 INFO 24356 --- [ main] o.a.tutorial.restapi.RestApiApplication : args[1]: martin 2021-05-06 09:30:39.726 INFO 24356 --- [ main] o.a.tutorial.restapi.RequestPwdResetCmd : Password reset request sent for martin result <202 AC