UserApiResource extends ComponentSupport implements Resource, UserApiResourceDoc { @Override @GET @RequiresAuthentication @RequiresPermissions("nexus:users:read") public Collection<ApiUser> getUsers( @QueryParam("userId") final String userId, @QueryParam("source") final String source) { UserSearchCriteria criteria = new UserSearchCriteria(userId, null, source); if (!UserManager.DEFAULT_SOURCE.equals(source)) { criteria.setLimit(100); } return securitySystem.searchUsers(criteria).stream().map(u -> fromUser(u)) .collect(Collectors.toList()); } @Inject  UserApiResource(final SecuritySystem securitySystem, final AdminPasswordFileManager adminPasswordFileManager); @Override @GET @RequiresAuthentication @RequiresPermissions("nexus:users:read") Collection<ApiUser> getUsers(
      @QueryParam("userId") final String userId,
      @QueryParam("source") final String source); @Override @POST @RequiresAuthentication @RequiresPermissions("nexus:users:create") @Validate ApiUser createUser(final ApiCreateUser createUser); @Override @PUT @Path("{userId}") @RequiresAuthentication @RequiresPermissions("nexus:users:update") @Validate void updateUser(@PathParam("userId") final String userId, final ApiUser apiUser); @Override @DELETE @Path("{userId}") @RequiresAuthentication @RequiresPermissions("nexus:users:delete") void deleteUser(@PathParam("userId") final String userId); @Override @PUT @RequiresAuthentication @RequiresPermissions("nexus:*") @Path("{userId}/change-password") @Consumes(MediaType.TEXT_PLAIN) @Validate void changePassword(@PathParam("userId") final String userId, final String password); static final String ADMIN_USER_ID; }
@Test public void testGetUsers() { when(securitySystem.searchUsers(any())).thenReturn(Collections.singleton(createUser())); Collection<ApiUser> users = underTest.getUsers("js", UserManager.DEFAULT_SOURCE); assertThat(users, hasSize(1)); assertThat(users, contains(BeanMatchers.similarTo(underTest.fromUser(createUser())))); ArgumentCaptor<UserSearchCriteria> captor = ArgumentCaptor.forClass(UserSearchCriteria.class); verify(securitySystem).searchUsers(captor.capture()); UserSearchCriteria criteria = captor.getValue(); assertThat(criteria.getUserId(), is("js")); assertThat(criteria.getSource(), is(UserManager.DEFAULT_SOURCE)); assertNull(criteria.getLimit()); }