Skip to content

Commit

Permalink
Correctly form URLs for user creation and password recovery if they a…
Browse files Browse the repository at this point in the history
…lready contained query parameters (GCRC#1213)

* add URIBuilder to manage user creation provided URLs that already have query parameters

* formatting

* fix token encoding issue for user creation

* refactor token creation for user password recovery

---------

Co-authored-by: Jagdish Kunwar <[email protected]>
  • Loading branch information
alexgao1 and Jagdish Kunwar authored Mar 6, 2024
1 parent 623273e commit 3c5bfe9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
5 changes: 5 additions & 0 deletions nunaliit2-couch-user/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,10 @@
<type>jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>${apache-httpclient.version}</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package ca.carleton.gcrc.couch.user.mail;

import java.net.URLEncoder;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand All @@ -10,6 +9,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.apache.http.client.utils.URIBuilder;

import ca.carleton.gcrc.mail.MailDelivery;
import ca.carleton.gcrc.mail.MailMessage;
import ca.carleton.gcrc.mail.MailRecipient;
Expand Down Expand Up @@ -143,8 +144,9 @@ public void sendUserCreationNotice(String emailAddress, String token) throws Exc
Map<String,String> parameters = new HashMap<String,String>();
{
// Compute link
String urlEncodedToken = URLEncoder.encode(token, "UTF-8");
String link = createUserUrl + "?token=" + urlEncodedToken;
URIBuilder builder = new URIBuilder(createUserUrl);
builder.addParameter("token", token);
String link = builder.build().toString();
parameters.put("link", link);
}

Expand Down Expand Up @@ -225,8 +227,9 @@ public void sendPasswordRecoveryNotice(String emailAddress, String token) throws
Map<String,String> parameters = new HashMap<String,String>();
{
// Compute link
String urlEncodedToken = URLEncoder.encode(token, "UTF-8");
String link = passwordRecoveryUrl + "?token=" + urlEncodedToken;
URIBuilder builder = new URIBuilder(passwordRecoveryUrl);
builder.addParameter("token", token);
String link = builder.build().toString();
parameters.put("link", link);
}

Expand Down
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
<slf4j.version>1.7.13</slf4j.version>
<jsoup.version>1.12.1</jsoup.version>
<jena.version>3.17.0</jena.version>
<apache-httpclient.version>4.5.1</apache-httpclient.version>
</properties>
<modules>
<module>nunaliit2-jdbc</module>
Expand Down

0 comments on commit 3c5bfe9

Please sign in to comment.