mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-07 01:54:22 +00:00
Merge branch 'w2p-97298_issue-3281_self-register-issue-7.2' into w2p-97298_issue-3281_self-register-issue-main
# Conflicts: # dspace-server-webapp/src/test/java/org/dspace/app/rest/RegistrationRestRepositoryIT.java
This commit is contained in:
@@ -53,7 +53,7 @@ public class RegistrationRestRepository extends DSpaceRestRepository<Registratio
|
||||
|
||||
private static Logger log = LogManager.getLogger(RegistrationRestRepository.class);
|
||||
|
||||
public static final String TYPE_QUERY_PARAM = "type";
|
||||
public static final String TYPE_QUERY_PARAM = "accountRequestType";
|
||||
public static final String TYPE_REGISTER = "register";
|
||||
public static final String TYPE_FORGOT = "forgot";
|
||||
|
||||
@@ -114,8 +114,9 @@ public class RegistrationRestRepository extends DSpaceRestRepository<Registratio
|
||||
if (StringUtils.isBlank(registrationRest.getEmail())) {
|
||||
throw new UnprocessableEntityException("The email cannot be omitted from the Registration endpoint");
|
||||
}
|
||||
String type = request.getParameter(TYPE_QUERY_PARAM);
|
||||
if (!type.equalsIgnoreCase(TYPE_FORGOT) && !type.equalsIgnoreCase(TYPE_REGISTER)) {
|
||||
String accountType = request.getParameter(TYPE_QUERY_PARAM);
|
||||
if (StringUtils.isBlank(accountType) ||
|
||||
(!accountType.equalsIgnoreCase(TYPE_FORGOT) && !accountType.equalsIgnoreCase(TYPE_REGISTER))) {
|
||||
throw new IllegalArgumentException(String.format("Needs query param '%s' with value %s or %s indicating " +
|
||||
"what kind of registration request it is", TYPE_QUERY_PARAM, TYPE_FORGOT, TYPE_REGISTER));
|
||||
}
|
||||
@@ -125,7 +126,7 @@ public class RegistrationRestRepository extends DSpaceRestRepository<Registratio
|
||||
} catch (SQLException e) {
|
||||
log.error("Something went wrong retrieving EPerson for email: " + registrationRest.getEmail(), e);
|
||||
}
|
||||
if (eperson != null && type.equalsIgnoreCase(TYPE_FORGOT)) {
|
||||
if (eperson != null && accountType.equalsIgnoreCase(TYPE_FORGOT)) {
|
||||
try {
|
||||
if (!AuthorizeUtil.authorizeUpdatePassword(context, eperson.getEmail())) {
|
||||
throw new DSpaceBadRequestException("Password cannot be updated for the given EPerson with email: "
|
||||
@@ -136,7 +137,7 @@ public class RegistrationRestRepository extends DSpaceRestRepository<Registratio
|
||||
log.error("Something went wrong with sending forgot password info email: "
|
||||
+ registrationRest.getEmail(), e);
|
||||
}
|
||||
} else if (type.equalsIgnoreCase(TYPE_REGISTER)) {
|
||||
} else if (accountType.equalsIgnoreCase(TYPE_REGISTER)) {
|
||||
try {
|
||||
String email = registrationRest.getEmail();
|
||||
if (!AuthorizeUtil.authorizeNewAccountRegistration(context, request)) {
|
||||
@@ -144,8 +145,9 @@ public class RegistrationRestRepository extends DSpaceRestRepository<Registratio
|
||||
"Registration is disabled, you are not authorized to create a new Authorization");
|
||||
}
|
||||
if (!authenticationService.canSelfRegister(context, request, email)) {
|
||||
throw new DSpaceBadRequestException(String.format("Registration is not allowed with email address" +
|
||||
" %s", email));
|
||||
throw new UnprocessableEntityException(
|
||||
String.format("Registration is not allowed with email address" +
|
||||
" %s", email));
|
||||
}
|
||||
accountService.sendRegistrationInfo(context, email);
|
||||
} catch (SQLException | IOException | MessagingException | AuthorizeException e) {
|
||||
|
@@ -22,7 +22,6 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilder
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
@@ -203,7 +202,7 @@ public class RegistrationRestRepositoryIT extends AbstractControllerIntegrationT
|
||||
|
||||
@Test
|
||||
public void testRegisterDomainNotRegistered() throws Exception {
|
||||
List<RegistrationData> registrationDataList = new ArrayList<>();
|
||||
List<RegistrationData> registrationDataList;
|
||||
try {
|
||||
configurationService.setProperty("authentication-password.domain.valid", "test.com");
|
||||
RegistrationRest registrationRest = new RegistrationRest();
|
||||
@@ -215,7 +214,7 @@ public class RegistrationRestRepositoryIT extends AbstractControllerIntegrationT
|
||||
.param(TYPE_QUERY_PARAM, TYPE_REGISTER)
|
||||
.content(mapper.writeValueAsBytes(registrationRest))
|
||||
.contentType(contentType))
|
||||
.andExpect(status().isBadRequest());
|
||||
.andExpect(status().isUnprocessableEntity());
|
||||
} finally {
|
||||
registrationDataList = registrationDataDAO.findAll(context, RegistrationData.class);
|
||||
Iterator<RegistrationData> iterator = registrationDataList.iterator();
|
||||
@@ -246,7 +245,7 @@ public class RegistrationRestRepositoryIT extends AbstractControllerIntegrationT
|
||||
.param(TYPE_QUERY_PARAM, TYPE_REGISTER)
|
||||
.content(mapper.writeValueAsBytes(registrationRest))
|
||||
.contentType(contentType))
|
||||
.andExpect(status().isBadRequest());
|
||||
.andExpect(status().isUnprocessableEntity());
|
||||
registrationDataList = registrationDataDAO.findAll(context, RegistrationData.class);
|
||||
assertEquals(0, registrationDataList.size());
|
||||
} finally {
|
||||
@@ -420,4 +419,27 @@ public class RegistrationRestRepositoryIT extends AbstractControllerIntegrationT
|
||||
captchaService.init();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void accountEndpoint_WithoutAccountTypeParam() throws Exception {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
RegistrationRest registrationRest = new RegistrationRest();
|
||||
registrationRest.setEmail(eperson.getEmail());
|
||||
getClient().perform(post("/api/eperson/registrations")
|
||||
.content(mapper.writeValueAsBytes(registrationRest))
|
||||
.contentType(contentType))
|
||||
.andExpect(status().isBadRequest());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void accountEndpoint_WrongAccountTypeParam() throws Exception {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
RegistrationRest registrationRest = new RegistrationRest();
|
||||
registrationRest.setEmail(eperson.getEmail());
|
||||
getClient().perform(post("/api/eperson/registrations")
|
||||
.param(TYPE_QUERY_PARAM, "nonValidValue")
|
||||
.content(mapper.writeValueAsBytes(registrationRest))
|
||||
.contentType(contentType))
|
||||
.andExpect(status().isBadRequest());
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user