Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DS-4027: New user registration & forgot password #2763

Merged
merged 27 commits into from
Jun 30, 2020

Conversation

benbosman
Copy link
Member

@benbosman benbosman commented May 20, 2020

References

Description

This is the backend to:

  • Request a new user registration (which sends an email)
  • Complete a new user registration (creating the user with the token)
  • Requests a new password (which sends an email)
  • Complete a password update (patching the user with the token)

Instructions for Reviewers

List of changes in this PR:

  • Request a new user registration and Requests a new password are handled using POST /api/eperson/registrations
  • Complete a new user registration is handled using POST /api/eperson/epersons?token=<:token>
  • Complete a password update is handled using PATCH /api/eperson/epersons/<:id-eperson>?token=<:token>
  • An authorization feature to verify whether you can register as a new user is created
  • The details of the token can be retrieved using the token (but not using the email address)
  • None of these requests require authentication

Checklist

This checklist provides a reminder of what we are going to look for when reviewing your PR. You need not complete this checklist prior to creating your PR (draft PRs are always welcome). If you are unsure about an item in the checklist, don't hesitate to ask. We're here to help!

  • My PR is small in size (e.g. less than 1,000 lines of code, not including comments & integration tests). Exceptions may be made if previously agreed upon.
  • My PR passes Checkstyle validation based on the Code Style Guide
  • My PR includes Javadoc for all new (or modified) public methods and classes. It also includes Javadoc for large or complex private methods.
  • My PR passes all tests and includes new/updated Unit or Integration Tests for any bug fixes, improvements or new features. A few reminders about what constitutes good tests:
    • Include tests for different user types, including: (1) Anonymous user, (2) Logged in user (non-admin), and (3) Administrator.
    • Include tests for known error scenarios and error codes (e.g. 400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found, etc)
    • For bug fixes, include a test that reproduces the bug and proves it is fixed. For clarity, it may be useful to provide the test in a separate commit from the bug fix.
  • If my PR includes new, third-party dependencies (in any pom.xml), I've made sure their licenses align with the DSpace BSD License based on the Licensing of Contributions documentation.
  • If my PR modifies the REST API, I've linked to the REST Contract page (or open PR) related to this change.

Copy link
Member

@tdonohue tdonohue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@benbosman : I gave this a (partial) code review today. Unfortunately I ran into a lot of minor mistakes/cleanup. Please see my inline comments. There are areas of this code that don't make sense to me...so either they need fixing or need inline code comments to explain the logic.

I stopped reviewing part way through as there was too much to comment on (especially in the ITs, which I found very messy overall & not implemented based on current best practices). So, I'd recommend working with the developer on cleaning up this code based on our best practices & then let me know when you feel it's ready for a public review again.

…w-registration

Conflicts:
	dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/EPersonRestRepository.java
	dspace-server-webapp/src/test/java/org/dspace/app/rest/EPersonRestRepositoryIT.java
@benbosman
Copy link
Member Author

@tdonohue All feedback has been resolved and/or answered
The master branch has also been merged in this branch

… and rewrote EPersonRestRepositoryIT tests to use this
Copy link
Member

@tdonohue tdonohue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@benbosman : This is looking great overall. That said, in my re-review, I stumbled on a few tiny mistakes. Some look like simple copy & paste errors that were overlooked. Once these tiny things are cleaned up, I think this is ready to go. Thanks!

@heathergreerklein heathergreerklein added this to Ready to review in DSpace 7 Beta 3 Jun 15, 2020
…w-registration

Conflicts:
	dspace-api/src/main/java/org/dspace/app/util/AuthorizeUtil.java
	dspace-server-webapp/src/main/java/org/dspace/app/rest/security/EPersonRestPermissionEvaluatorPlugin.java
	dspace-server-webapp/src/test/java/org/dspace/app/rest/EPersonRestRepositoryIT.java
@benbosman
Copy link
Member Author

@tdonohue all feedback has been processed, and the branch has been updated with the latest master

This should be ready to merge now

Copy link
Member

@tdonohue tdonohue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@benbosman : Thanks for the updates! I've found two more minor things that can be cleaned up quickly (a recent commit to add in an odd context.complete() in a test made me realize these additional minor flaws). Then it all looks good to me.

@tdonohue tdonohue added authentication: password Related to default password-based authentication authentication: EPerson Related to how the EPerson object works during authentication new feature interface: REST API v7+ REST API for v7 and later (dspace-server-webapp module) labels Jun 22, 2020
@tdonohue tdonohue moved this from Needs Reviewers Assigned to Under Review in DSpace 7 Beta 3 Jun 23, 2020
@tdonohue tdonohue added this to the 7.0beta3 milestone Jun 23, 2020
@tdonohue tdonohue changed the title beta3: New user registration & forgot password DS-4027: New user registration & forgot password Jun 24, 2020
Copy link
Member

@abollini abollini left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added some minor comments and questions inline

Comment on lines +627 to +632
// This allowSetPassword is currently the only mthod that would return true only when it's
// actually expected to be returning true.
// For example the LDAP canSelfRegister will return true due to auto-register, while that
// does not imply a new user can register explicitly
return AuthenticateServiceFactory.getInstance().getAuthenticationService()
.allowSetPassword(context, request, null);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have read the previous discussion but I still don't understand why we cannot simply rely only on the dspace.cfg property. Why should I put user.registration to true if I wan't allow user registration?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed with Tim in https://github.com/DSpace/DSpace/pull/2763/files/891ab3f3e261e8a78321091b8835fab413937899#r428844401, there is no method in the authentication services which correctly verifies whether you can register a new account. A ticket can be created for that problem, but it was considered out of scope for this PR to fix that issue in the API

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've created #2793

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with moving this to a separate discussion

Comment on lines +74 to +76
if (!configurationService.getBooleanProperty("user.registration", true)) {
throw new IllegalStateException("The user.registration parameter was set to false");
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems me to confirm that we only need to check the dspace.cfg parameter (see previous comment)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A ticket can be created to deal with the lack of this detail in the API

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've created #2793

Comment on lines 160 to 167
RegistrationData registrationData = registrationDataService.findByToken(context, token);
if (registrationData == null) {
throw new DSpaceBadRequestException("The token given as parameter: " + token + " does not exist" +
" in the database");
}
if (es.findByEmail(context, registrationData.getEmail()) != null) {
throw new DSpaceBadRequestException("The token given already contains an email address that resolves" +
"to an eperson");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this meet the current contract, I'm just thinking that a 422 would be more appropriate here as there is a semantic / status issue more than a formal error. But if you don't agree, ignore it and we can eventually open an issue to discuss it in future and apply later the changes (if agreed)

Copy link
Member Author

@benbosman benbosman Jun 26, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The contract explicitly mentions status 400 for this use case, that would contradict the contract

Comment on lines 202 to 203
throw new DSpaceBadRequestException("The eperson.firstname and eperson.lastname values need to be " +
"filled in");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also in this case, as the issue is inside the json I would prefer a 422. It would be useful in any case note in the contract that this error is throw when the metadata are missing (it is noted that they are mandatory)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not defined in the contract, 422 is fine for me. We'll update this in the code

getClient().perform(post("/api/eperson/registrations")
.content(mapper.writeValueAsBytes(registrationRest))
.contentType(contentType))
.andExpect(status().is(401));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

small thing but I would appreciate if we can use the constant here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code has been moved, but can indeed be adjusted

Comment on lines 161 to 168
registrationDataList = registrationDataDAO.findAll(context, RegistrationData.class);
assertEquals(1, registrationDataList.size());
assertTrue(StringUtils.equalsIgnoreCase(registrationDataList.get(0).getEmail(), eperson.getEmail()));
Iterator<RegistrationData> iterator = registrationDataList.iterator();
while (iterator.hasNext()) {
RegistrationData registrationData = iterator.next();
registrationDataDAO.delete(context, registrationData);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

put in a finally block

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll move this to a finally

Copy link
Member

@tdonohue tdonohue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Thanks @benbosman! This looks good to me now. So, once @abollini 's minor feedback is addressed, this can be merged.
(Also, as noted on Slack, if you rebase on current master then LGTM should build properly and stop putting a ❌ here. It also will analyze your PR and provide feedback as well.)

@lgtm-com
Copy link

lgtm-com bot commented Jun 30, 2020

This pull request introduces 1 alert when merging 0555644 into 000b5c7 - view on LGTM.com

new alerts:

  • 1 for Missing space in string literal

@benbosman benbosman requested a review from abollini June 30, 2020 08:22
@tdonohue tdonohue moved this from Under Review to Reviewer approved in DSpace 7 Beta 3 Jun 30, 2020
@abollini
Copy link
Member

it is ready to go for me now. Thanks @benbosman

@tdonohue tdonohue merged commit cc362d8 into DSpace:master Jun 30, 2020
DSpace 7 Beta 3 automation moved this from Reviewer approved to Done Jun 30, 2020
@benbosman benbosman deleted the w2p-70273_create-new-registration branch September 11, 2020 07:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
authentication: EPerson Related to how the EPerson object works during authentication authentication: password Related to default password-based authentication high priority interface: REST API v7+ REST API for v7 and later (dspace-server-webapp module) new feature
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

4 participants