@Test public void testCreateUser() throws Exception { User user = createUser(); when(securitySystem.addUser(user, "admin123")).thenReturn(user); ApiCreateUser createUser = new ApiCreateUser("jsmith", "John", "Smith", "jsmith@example.org", "admin123", ApiUserStatus.disabled, Collections.singleton("nx-admin")); ApiUser returned = underTest.createUser(createUser); assertThat(returned, BeanMatchers.similarTo(underTest.fromUser(user))); verify(securitySystem).addUser(user, "admin123"); }
@Override @POST @RequiresAuthentication @RequiresPermissions("nexus:users:create") @Validate public ApiUser createUser(final ApiCreateUser createUser) { if (Strings2.isBlank(createUser.getPassword())) { throw createWebException(Status.BAD_REQUEST, "A non-empty password is required."); } try { User user = securitySystem.addUser(createUser.toUser(), createUser.getPassword()); return fromUser(user); } catch (NoSuchUserManagerException e) { log.error("Unable to locate default usermanager.", e); throw createNoSuchUserManagerException(UserManager.DEFAULT_SOURCE); } }
UserApiResource extends ComponentSupport implements Resource, UserApiResourceDoc { @Override @POST @RequiresAuthentication @RequiresPermissions("nexus:users:create") @Validate public ApiUser createUser(final ApiCreateUser createUser) { if (Strings2.isBlank(createUser.getPassword())) { throw createWebException(Status.BAD_REQUEST, "A non-empty password is required."); } try { User user = securitySystem.addUser(createUser.toUser(), createUser.getPassword()); return fromUser(user); } catch (NoSuchUserManagerException e) { log.error("Unable to locate default usermanager.", e); throw createNoSuchUserManagerException(UserManager.DEFAULT_SOURCE); } } }
UserApiResource extends ComponentSupport implements Resource, UserApiResourceDoc { @Override @POST @RequiresAuthentication @RequiresPermissions("nexus:users:create") @Validate public ApiUser createUser(final ApiCreateUser createUser) { if (Strings2.isBlank(createUser.getPassword())) { throw createWebException(Status.BAD_REQUEST, "A non-empty password is required."); } try { User user = securitySystem.addUser(createUser.toUser(), createUser.getPassword()); return fromUser(user); } catch (NoSuchUserManagerException e) { log.error("Unable to locate default usermanager.", e); throw createNoSuchUserManagerException(UserManager.DEFAULT_SOURCE); } } @Inject  UserApiResource(final SecuritySystem securitySystem, final AdminPasswordFileManager adminPasswordFileManager); }
UserApiResource extends ComponentSupport implements Resource, UserApiResourceDoc { @Override @POST @RequiresAuthentication @RequiresPermissions("nexus:users:create") @Validate public ApiUser createUser(final ApiCreateUser createUser) { if (Strings2.isBlank(createUser.getPassword())) { throw createWebException(Status.BAD_REQUEST, "A non-empty password is required."); } try { User user = securitySystem.addUser(createUser.toUser(), createUser.getPassword()); return fromUser(user); } catch (NoSuchUserManagerException e) { log.error("Unable to locate default usermanager.", e); throw createNoSuchUserManagerException(UserManager.DEFAULT_SOURCE); } } @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); }
UserApiResource extends ComponentSupport implements Resource, UserApiResourceDoc { @Override @POST @RequiresAuthentication @RequiresPermissions("nexus:users:create") @Validate public ApiUser createUser(final ApiCreateUser createUser) { if (Strings2.isBlank(createUser.getPassword())) { throw createWebException(Status.BAD_REQUEST, "A non-empty password is required."); } try { User user = securitySystem.addUser(createUser.toUser(), createUser.getPassword()); return fromUser(user); } catch (NoSuchUserManagerException e) { log.error("Unable to locate default usermanager.", e); throw createNoSuchUserManagerException(UserManager.DEFAULT_SOURCE); } } @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; }