UserApiResource extends ComponentSupport implements Resource, UserApiResourceDoc { @Override @PUT @Path("{userId}") @RequiresAuthentication @RequiresPermissions("nexus:users:update") @Validate public void updateUser(@PathParam("userId") final String userId, final ApiUser apiUser) { if (!userId.equals(apiUser.getUserId())) { log.debug("The path userId '{}' does not match the userId supplied in the body '{}'.", userId, apiUser.getUserId()); throw createWebException(Status.BAD_REQUEST, "The path's userId does not match the body"); } try { validateRoles(apiUser.getRoles()); if (UserManager.DEFAULT_SOURCE.equals(apiUser.getSource())) { securitySystem.updateUser(apiUser.toUser()); } else { securitySystem.getUser(userId, apiUser.getSource()); Set<RoleIdentifier> roleIdentifiers = apiUser.getRoles().stream() .map(roleId -> new RoleIdentifier(UserManager.DEFAULT_SOURCE, roleId)).collect(Collectors.toSet()); securitySystem.setUsersRoles(userId, apiUser.getSource(), roleIdentifiers); } } catch (UserNotFoundException e) { log.debug("Unable to locate userId: {}", userId, e); throw createUnknownUserException(userId); } catch (NoSuchUserManagerException e) { log.debug("Unable to locate source: {}", userId, apiUser.getSource(), e); throw createNoSuchUserManagerException(apiUser.getSource()); } } @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 testUpdateUser() throws Exception { User user = createUser(); underTest.updateUser("jsmith", underTest.fromUser(user)); verify(securitySystem).updateUser(user); }