UserImpl extends AuthorizableImpl implements User { @Override public void disable(@Nullable String reason) throws RepositoryException { if (isAdmin) { throw new RepositoryException("The administrator user cannot be disabled."); } getUserManager().onDisable(this, reason); Tree tree = getTree(); if (reason == null) { if (tree.hasProperty(REP_DISABLED)) { tree.removeProperty(REP_DISABLED); } } else { tree.setProperty(REP_DISABLED, reason); } } UserImpl(String id, Tree tree, UserManagerImpl userManager); @Override boolean isGroup(); @NotNull @Override Principal getPrincipal(); @Override boolean isAdmin(); @Override boolean isSystemUser(); @NotNull @Override Credentials getCredentials(); @NotNull @Override Impersonation getImpersonation(); @Override void changePassword(String password); @Override void changePassword(@Nullable String password, @NotNull String oldPassword); @Override void disable(@Nullable String reason); @Override boolean isDisabled(); @Nullable @Override String getDisabledReason();  }
@Test public void testDisable() throws Exception { assertNull(user.getDisabledReason()); assertFalse(user.isDisabled()); user.disable("reason"); assertEquals("reason", user.getDisabledReason()); assertTrue(user.isDisabled()); user.disable(null); assertNull(user.getDisabledReason()); assertFalse(user.isDisabled()); }
@Test(expected = RepositoryException.class) public void testDisableAdministrator() throws Exception { getAdminUser().disable("reason"); }