8000 Add id and description when building ResourceType representation by sguilhen · Pull Request #48499 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
8000
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ default String getName() {
return getResourceType().getSimpleName();
}

/**
* Returns a human-readable description of the resource type managed by this provider.
*
* @return the description of the resource type
*/
default String getDescription() {
return getName();
}

/**
* Returns the schema name of the resource type managed by this provider.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ private ResourceType toRepresentation(ScimResourceTypeProviderFactory<? extends
throw new RuntimeException("Could not instantiate resource type representation for provider " + factory.getId(), e);
}

representation.setId(provider.getName());
representation.setName(provider.getName());
representation.setDescription(provider.getDescription());
representation.setEndpoint("/" + factory.getId());
representation.setSchema(provider.getSchema());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ public UserResourceTypeProvider(KeycloakSession session) {
super(session, new UserCoreModelSchema(session), List.of(new UserEnterpriseModelSchema(session)));
}

@Override
public String getDescription() {
return "User Account";
}

@Override
public User onCreate(User resource) {
UserProfileProvider provider = session.getProvider(UserProfileProvider.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,17 @@ public void testGet() {
assertNotNull(response);
assertEquals(2, response.getResources().size());

assertResourceType(response, User.class, List.of(ENTERPRISE_USER_SCHEMA));
assertResourceType(response, Group.class, List.of());
assertResourceType(response, User.class, "User Account", List.of(ENTERPRISE_USER_SCHEMA));
assertResourceType(response, Group.class, "Group", List.of());
}

private static void assertResourceType(ListResponse<ResourceType> response, Class<? extends ResourceTypeRepresentation> resourceType, List<String> expectedSchemaExtensions) {
private static void assertResourceType(ListResponse<ResourceType> response, Class<? extends ResourceTypeRepresentation> resourceType,
String expectedDescription, List<String> expectedSchemaExtensions) {
ResourceType representation = response.getResources().stream().filter(r -> r.getName().equals(resourceType.getSimpleName())).findAny().orElse(null);

assertNotNull(representation);
assertEquals(resourceType.getSimpleName(), representation.getId());
assertEquals(expectedDescription, representation.getDescription());
assertEquals("/" + representation.getName() + "s", representation.getEndpoint());
assertEquals(getCoreSchema(resourceType), representation.getSchema());

Expand Down
Loading
0