OnboardingResource extends ComponentSupport implements Resource { @PUT @RequiresAuthentication @RequiresPermissions("nexus:*") @Path("/change-admin-password") @Validate public void changeAdminPassword(@NotEmpty(message = PASSWORD_REQUIRED) final String password) { try { securitySystem.changePassword("admin", password, false); adminPasswordFileManager.removeFile(); } catch (UserNotFoundException e) { log.error("Unable to locate 'admin' user to change password", e); throw new WebApplicationException(Response.Status.NOT_FOUND); } } @Inject  OnboardingResource(final OnboardingManager onboardingManager,
                            final SecuritySystem securitySystem,
                            final AdminPasswordFileManager adminPasswordFileManager); @GET @RequiresAuthentication @RequiresPermissions("nexus:*") @Produces(APPLICATION_JSON) List<OnboardingItem> getOnboardingItems(); @PUT @RequiresAuthentication @RequiresPermissions("nexus:*") @Path("/change-admin-password") @Validate void changeAdminPassword(@NotEmpty(message = PASSWORD_REQUIRED) final String password); static final String PASSWORD_REQUIRED; static final String RESOURCE_URI; }
@Test public void testChangeAdminPassword() throws Exception { underTest.changeAdminPassword("newpass"); verify(securitySystem).changePassword("admin", "newpass", false); }
@Test public void testChangeAdminPassword_empty() { try { underTest.changeAdminPassword(""); fail("empty password should have failed validation"); } catch (ConstraintViolationException e) { assertThat(e.getConstraintViolations().iterator().next().getMessage(), is(PASSWORD_REQUIRED)); } }
@Test public void testChangeAdminPassword_null() { try { underTest.changeAdminPassword(null); fail("null password should have failed validation"); } catch (ConstraintViolationException e) { assertThat(e.getConstraintViolations().iterator().next().getMessage(), is(PASSWORD_REQUIRED)); } }