diff --git a/account-gui/pom.xml b/account-gui/pom.xml
index cbae486b..bd1a9d66 100644
--- a/account-gui/pom.xml
+++ b/account-gui/pom.xml
@@ -4,7 +4,7 @@
org.openconext
myconext
- 7.2.9
+ 7.2.10
../pom.xml
account-gui
diff --git a/myconext-gui/pom.xml b/myconext-gui/pom.xml
index 3e9e68b6..3c0a4c8e 100644
--- a/myconext-gui/pom.xml
+++ b/myconext-gui/pom.xml
@@ -4,7 +4,7 @@
org.openconext
myconext
- 7.2.9
+ 7.2.10
../pom.xml
myconext-gui
diff --git a/myconext-server/pom.xml b/myconext-server/pom.xml
index 49fb0c7b..cf019038 100644
--- a/myconext-server/pom.xml
+++ b/myconext-server/pom.xml
@@ -4,7 +4,7 @@
org.openconext
myconext
- 7.2.9
+ 7.2.10
../pom.xml
myconext-server
diff --git a/myconext-server/src/main/java/myconext/api/UserController.java b/myconext-server/src/main/java/myconext/api/UserController.java
index 13854c12..d25a33e8 100644
--- a/myconext-server/src/main/java/myconext/api/UserController.java
+++ b/myconext-server/src/main/java/myconext/api/UserController.java
@@ -363,11 +363,22 @@ public ResponseEntity createEduIDAccount(@Valid @RequestBody Cre
@PutMapping("/sp/update")
public ResponseEntity updateUserProfile(Authentication authentication, @Valid @RequestBody UpdateUserNameRequest deltaUser) {
User user = userFromAuthentication(authentication);
+ if (StringUtils.hasText(deltaUser.getGivenName())) {
+ user.setChosenName(deltaUser.getGivenName());
+ }
+ //New API allows for update chosen name, override previous update
if (StringUtils.hasText(deltaUser.getChosenName())) {
user.setChosenName(deltaUser.getChosenName());
}
- user.setGivenName(deltaUser.getGivenName());
- user.setFamilyName(deltaUser.getFamilyName());
+ //Only if there is not validated name, we allow for updates
+ if (CollectionUtils.isEmpty(user.getLinkedAccounts())) {
+ if (StringUtils.hasText(deltaUser.getGivenName())) {
+ user.setGivenName(deltaUser.getGivenName());
+ }
+ if (StringUtils.hasText(deltaUser.getFamilyName())) {
+ user.setFamilyName(deltaUser.getFamilyName());
+ }
+ }
user.validate();
userRepository.save(user);
diff --git a/myconext-server/src/main/java/myconext/model/UpdateUserNameRequest.java b/myconext-server/src/main/java/myconext/model/UpdateUserNameRequest.java
index 9ba2da86..0f0d6740 100644
--- a/myconext-server/src/main/java/myconext/model/UpdateUserNameRequest.java
+++ b/myconext-server/src/main/java/myconext/model/UpdateUserNameRequest.java
@@ -14,9 +14,7 @@ public class UpdateUserNameRequest implements Serializable {
private String chosenName;
- @NotBlank
private String givenName;
- @NotBlank
private String familyName;
}
diff --git a/myconext-server/src/test/java/myconext/api/UserControllerTest.java b/myconext-server/src/test/java/myconext/api/UserControllerTest.java
index 9c316a67..2601b430 100644
--- a/myconext-server/src/test/java/myconext/api/UserControllerTest.java
+++ b/myconext-server/src/test/java/myconext/api/UserControllerTest.java
@@ -256,21 +256,20 @@ public void relayState() throws IOException {
@Test
public void updateUser() {
- User user = userRepository.findOneUserByEmail("jdoe@example.com");
- user.setGivenName("Mary");
- user.setFamilyName("Poppins");
+ UpdateUserNameRequest updateUserNameRequest = new UpdateUserNameRequest("chosenName", "Mary", "Poppins");
given()
.when()
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
- .body(user)
+ .body(updateUserNameRequest)
.put("/myconext/api/sp/update")
.then()
.statusCode(HttpStatus.CREATED.value());
User userFromDB = userRepository.findOneUserByEmail("jdoe@example.com");
-
- assertEquals(user.getGivenName(), userFromDB.getGivenName());
- assertEquals(user.getFamilyName(), userFromDB.getFamilyName());
+ //Has linked accounts, so no update
+ assertEquals(userFromDB.getGivenName(), "John");
+ assertEquals(userFromDB.getFamilyName(), "Doe");
+ assertEquals(userFromDB.getChosenName(), updateUserNameRequest.getChosenName());
}
@Test
@@ -362,17 +361,6 @@ public void removeUserService() {
assertFalse(userFromDB.getEduIDS().stream().anyMatch(val -> val.getServiceProviderEntityId().equals(("http://mock-sp"))));
}
- @Test
- public void updateUser403() {
- given()
- .when()
- .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
- .body(new User())
- .put("/myconext/api/sp/update")
- .then()
- .statusCode(400);
- }
-
@Test
public void updateUserWeakPassword() {
User user = userRepository.findOneUserByEmail("jdoe@example.com");
diff --git a/myconext-server/src/test/java/myconext/api/UserMobileControllerTest.java b/myconext-server/src/test/java/myconext/api/UserMobileControllerTest.java
index c0543acc..2ed024a5 100644
--- a/myconext-server/src/test/java/myconext/api/UserMobileControllerTest.java
+++ b/myconext-server/src/test/java/myconext/api/UserMobileControllerTest.java
@@ -35,23 +35,40 @@ public void me() throws IOException {
@Test
public void updateUserProfile() throws IOException {
- UpdateUserNameRequest userNameRequest = new UpdateUserNameRequest("CallName", "Mary", "Winters");
+ UpdateUserNameRequest userNameRequest = new UpdateUserNameRequest("Annie", "Anna", "Winters");
given()
.when()
.accept(ContentType.JSON)
.contentType(ContentType.JSON)
- .auth().oauth2(opaqueAccessToken(true, "eduid.nl/mobile"))
+ .auth().oauth2(doOpaqueAccessToken(true, new String[] {"eduid.nl/mobile"}, "introspect_no_linked_accounts"))
.body(userNameRequest)
.put("/mobile/api/sp/update")
.then()
.statusCode(201);
- User user = userRepository.findUserByEmail("jdoe@example.com").get();
+ User user = userRepository.findUserByEmail("mdoe@example.com").get();
assertEquals(userNameRequest.getChosenName(), user.getChosenName());
assertEquals(userNameRequest.getGivenName(), user.getGivenName());
assertEquals(userNameRequest.getFamilyName(), user.getFamilyName());
}
+ @Test
+ public void updateUserProfileOldAPI() throws IOException {
+ UpdateUserNameRequest userNameRequest = new UpdateUserNameRequest(null, "Anna", null);
+ given()
+ .when()
+ .accept(ContentType.JSON)
+ .contentType(ContentType.JSON)
+ .auth().oauth2(doOpaqueAccessToken(true, new String[] {"eduid.nl/mobile"}, "introspect_no_linked_accounts"))
+ .body(userNameRequest)
+ .put("/mobile/api/sp/update")
+ .then()
+ .statusCode(201);
+ User user = userRepository.findUserByEmail("mdoe@example.com").get();
+
+ assertEquals(userNameRequest.getGivenName(), user.getChosenName());
+ }
+
@Test
public void institutionNames() throws IOException {
Map names = given()
diff --git a/pom.xml b/pom.xml
index 66e3f781..ae8e6663 100644
--- a/pom.xml
+++ b/pom.xml
@@ -3,7 +3,7 @@
4.0.0
org.openconext
myconext
- 7.2.9
+ 7.2.10
pom
myconext
My OpenConext
diff --git a/tiqr-mock/pom.xml b/tiqr-mock/pom.xml
index 331d5b88..36874fa0 100644
--- a/tiqr-mock/pom.xml
+++ b/tiqr-mock/pom.xml
@@ -4,7 +4,7 @@
org.openconext
myconext
- 7.2.9
+ 7.2.10
../pom.xml
tiqr-mock