Declare an IAuthoritiesProvider bean to choose which users and roles the Users REST API returns, for example to hide technical roles or to suggest colleagues to share with.
By default, the Users REST API returns the caller and their roles.
To return others, declare a bean of type IAuthoritiesProvider.
It replaces the default, whatever the configuration order.
IAuthoritiesProvider is experimental and may change in future versions without notice.
Where the information comes from
The caller and their roles come from AuthorityQuery.getCaller(); any other user or role comes from your configuration or directory.
Any caller reaching the endpoint, anonymous ones included, sees what the provider returns for them.
Hide technical roles
Keep the caller and their business roles:
@Configurationstatic class BusinessRolesConfig { @Bean IAuthoritiesProvider businessRolesProvider() { final IAuthoritiesProvider defaultProvider = IAuthoritiesProvider.userBasedProvider(); return query -> AuthorityPage.builder() .items( defaultProvider.authorities(query).getItems().stream() // Replace with the rule matching your business roles .filter(authority -> Authority.USER.equals(authority.getType()) || authority.getName().startsWith("ROLE_DESK_")) .toList()) .build(); }}
Add roles the caller does not hold
@Configurationstatic class DeskRolesConfig { @Bean IAuthoritiesProvider deskRolesProvider() { final IAuthoritiesProvider defaultProvider = IAuthoritiesProvider.userBasedProvider(); final List<String> deskRoles = List.of("ROLE_DESK_FX", "ROLE_DESK_RATES"); return query -> AuthorityPage.builder() .items(defaultProvider.authorities(query).getItems()) .items(deskRoles.stream().map(Authority::ofRole).toList()) .build(); }}
Suggest other users
Add the members of the caller’s desks:
@Configurationstatic class DeskMembersConfig { private final Map<String, List<String>> membersByRole = Map.of("ROLE_DESK_FX", List.of("alice", "bob")); @Bean IAuthoritiesProvider deskMembersProvider() { final IAuthoritiesProvider defaultProvider = IAuthoritiesProvider.userBasedProvider(); return query -> { final var page = AuthorityPage.builder().items(defaultProvider.authorities(query).getItems()); if (query.getTypes().contains(Authority.USER)) { page.items( query.getCaller().getGrantedAuthorities().stream() .flatMap(role -> membersByRole.getOrDefault(role, List.of()).stream()) .map(Authority::ofUser) .toList()); } return page.build(); }; }}
What the server does with the result
The server skips null authorities, treats a null page as empty, and drops duplicates and authorities of types not requested.
The provider is called on every request, possibly concurrently.All types are in com.activeviam.web.spring.api.users.
Type
Description
IAuthoritiesProvider
Functional interface: AuthorityPage authorities(AuthorityQuery query). userBasedProvider() returns the default.
AuthorityQuery
Immutable request. getCaller() returns an ISecurityDetails (com.activeviam.tech.core.api.security) with getUserName() and getGrantedAuthorities(). getTypes() is never empty. builder() with caller(..) and types(..) creates one, for instance in a test.
Authority
Immutable authority with getName() and getType(). Constants USER ("user") and ROLE ("role"), factories ofUser(name) and ofRole(name), and builder() with name(..) and type(..).
AuthorityPage
The response, with getItems(). builder() with item(authority) and items(collection), which add to the page.