@Test public void testChangePassword_defaultAdminNotRemoved() throws Exception { adminPasswordFileManager.writeFile("oldPassword"); underTest.changePassword("test", "test"); verify(securitySystem).changePassword("test", "test"); assertThat(adminPasswordFileManager.exists(), is(true)); }
@Override @PUT @RequiresAuthentication @RequiresPermissions("nexus:*") @Path("{userId}/change-password") @Consumes(MediaType.TEXT_PLAIN) @Validate public void changePassword(@PathParam("userId") final String userId, final String password) { if (StringUtils.isBlank(password)) { throw createWebException(Status.BAD_REQUEST, "Password must be supplied."); } try { securitySystem.changePassword(userId, password); if (ADMIN_USER_ID.equals(userId)) { adminPasswordFileManager.removeFile(); } } catch (UserNotFoundException e) { log.debug("Request to change password for invalid user '{}'.", userId); throw createUnknownUserException(userId); } }
UserApiResource extends ComponentSupport implements Resource, UserApiResourceDoc { @Override @PUT @RequiresAuthentication @RequiresPermissions("nexus:*") @Path("{userId}/change-password") @Consumes(MediaType.TEXT_PLAIN) @Validate public void changePassword(@PathParam("userId") final String userId, final String password) { if (StringUtils.isBlank(password)) { throw createWebException(Status.BAD_REQUEST, "Password must be supplied."); } try { securitySystem.changePassword(userId, password); if (ADMIN_USER_ID.equals(userId)) { adminPasswordFileManager.removeFile(); } } catch (UserNotFoundException e) { log.debug("Request to change password for invalid user '{}'.", userId); throw createUnknownUserException(userId); } } }
UserApiResource extends ComponentSupport implements Resource, UserApiResourceDoc { @Override @PUT @RequiresAuthentication @RequiresPermissions("nexus:*") @Path("{userId}/change-password") @Consumes(MediaType.TEXT_PLAIN) @Validate public void changePassword(@PathParam("userId") final String userId, final String password) { if (StringUtils.isBlank(password)) { throw createWebException(Status.BAD_REQUEST, "Password must be supplied."); } try { securitySystem.changePassword(userId, password); if (ADMIN_USER_ID.equals(userId)) { adminPasswordFileManager.removeFile(); } } catch (UserNotFoundException e) { log.debug("Request to change password for invalid user '{}'.", userId); throw createUnknownUserException(userId); } } @Inject  UserApiResource(final SecuritySystem securitySystem, final AdminPasswordFileManager adminPasswordFileManager); }
UserApiResource extends ComponentSupport implements Resource, UserApiResourceDoc { @Override @PUT @RequiresAuthentication @RequiresPermissions("nexus:*") @Path("{userId}/change-password") @Consumes(MediaType.TEXT_PLAIN) @Validate public void changePassword(@PathParam("userId") final String userId, final String password) { if (StringUtils.isBlank(password)) { throw createWebException(Status.BAD_REQUEST, "Password must be supplied."); } try { securitySystem.changePassword(userId, password); if (ADMIN_USER_ID.equals(userId)) { adminPasswordFileManager.removeFile(); } } catch (UserNotFoundException e) { log.debug("Request to change password for invalid user '{}'.", userId); throw createUnknownUserException(userId); } } @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 @PUT @RequiresAuthentication @RequiresPermissions("nexus:*") @Path("{userId}/change-password") @Consumes(MediaType.TEXT_PLAIN) @Validate public void changePassword(@PathParam("userId") final String userId, final String password) { if (StringUtils.isBlank(password)) { throw createWebException(Status.BAD_REQUEST, "Password must be supplied."); } try { securitySystem.changePassword(userId, password); if (ADMIN_USER_ID.equals(userId)) { adminPasswordFileManager.removeFile(); } } catch (UserNotFoundException e) { log.debug("Request to change password for invalid user '{}'.", userId); throw createUnknownUserException(userId); } } @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; }