-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Endpoint for provisioning user with roles without invitation
- Loading branch information
Showing
6 changed files
with
187 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
server/src/main/java/access/model/UserRoleProvisioning.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package access.model; | ||
|
||
import jakarta.validation.constraints.NotEmpty; | ||
import lombok.AllArgsConstructor; | ||
import lombok.NoArgsConstructor; | ||
import lombok.ToString; | ||
import org.springframework.util.StringUtils; | ||
|
||
import java.util.List; | ||
|
||
@ToString | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class UserRoleProvisioning { | ||
|
||
@NotEmpty | ||
public List<Long> roleIdentifiers; | ||
public Authority intendedAuthority = Authority.GUEST; | ||
public String sub; | ||
public String email; | ||
public String eduPersonPrincipalName; | ||
public String givenName; | ||
public String familyName; | ||
public String name; | ||
public String schacHomeOrganization; | ||
|
||
public void validate() { | ||
if (!StringUtils.hasText(email) && !StringUtils.hasText(eduPersonPrincipalName)) { | ||
throw new IllegalArgumentException("Requires one off: email, eduPersonPrincipalName. Invalid userRoleProvisioning: " + this); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,10 +2,9 @@ | |
|
||
import access.AbstractTest; | ||
import access.AccessCookieFilter; | ||
import access.model.Authority; | ||
import access.model.Role; | ||
import access.model.UpdateUserRole; | ||
import access.model.UserRole; | ||
import access.exception.NotFoundException; | ||
import access.manage.EntityType; | ||
import access.model.*; | ||
import io.restassured.common.mapper.TypeRef; | ||
import io.restassured.http.ContentType; | ||
import org.junit.jupiter.api.Test; | ||
|
@@ -14,10 +13,11 @@ | |
import java.time.temporal.ChronoUnit; | ||
import java.util.List; | ||
|
||
import static access.Seed.INVITER_SUB; | ||
import static access.Seed.MANAGE_SUB; | ||
import static access.Seed.*; | ||
import static access.security.SecurityConfig.API_TOKEN_HEADER; | ||
import static io.restassured.RestAssured.given; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
class UserRoleControllerTest extends AbstractTest { | ||
|
||
|
@@ -120,4 +120,45 @@ void deleteUserRoleNotAllowed() throws Exception { | |
.then() | ||
.statusCode(403); | ||
} | ||
|
||
@Test | ||
void userRoleProvisioning() throws Exception { | ||
super.stubForManagerProvidersByIdIn(EntityType.SAML20_SP, List.of("1", "2")); | ||
super.stubForManageProviderByOrganisationGUID(ORGANISATION_GUID); | ||
super.stubForManageProvisioning(List.of("1", "2")); | ||
|
||
super.stubForCreateScimUser(); | ||
super.stubForCreateGraphUser(); | ||
super.stubForCreateScimRole(); | ||
super.stubForUpdateScimRole(); | ||
|
||
List<Long> roleIdentifiers = List.of( | ||
roleRepository.findByName("Network").get(0).getId(), | ||
roleRepository.findByName("Wiki").get(0).getId() | ||
); | ||
UserRoleProvisioning userRoleProvisioning = new UserRoleProvisioning( | ||
roleIdentifiers, | ||
Authority.GUEST, | ||
null, | ||
"[email protected]", | ||
null, | ||
null, | ||
null, | ||
"Charly Green", | ||
null | ||
); | ||
given() | ||
.when() | ||
.header(API_TOKEN_HEADER, API_TOKEN_HASH) | ||
.accept(ContentType.JSON) | ||
.contentType(ContentType.JSON) | ||
.body(userRoleProvisioning) | ||
.post("/api/external/v1/user_roles/user_role_provisioning") | ||
.then() | ||
.statusCode(201); | ||
|
||
User user = userRepository.findBySubIgnoreCase("urn:collab:person:domain.org:new_user").orElseThrow(NotFoundException::new); | ||
assertEquals(2, user.getUserRoles().size()); | ||
} | ||
|
||
} |