AbstractJcrBackedUserRoleDao implements IUserRoleDao { public void deleteUser( Session session, final IPentahoUser user ) throws NotFoundException, RepositoryException { if ( canDeleteUser( session, user ) ) { User jackrabbitUser = getJackrabbitUser( user.getTenant(), user.getUsername(), session ); if ( jackrabbitUser != null && TenantUtils.isAccessibleTenant( tenantedUserNameUtils.getTenant( jackrabbitUser.getID() ) ) ) { Iterator<Group> currentGroups = jackrabbitUser.memberOf(); while ( currentGroups.hasNext() ) { currentGroups.next().removeMember( jackrabbitUser ); } getUserCache().remove( jackrabbitUser.getID() ); purgeUserFromCache( user.getUsername() ); jackrabbitUser.remove(); session.save(); } else { throw new NotFoundException( "" ); } } else { throw new RepositoryException( Messages.getInstance().getString( "AbstractJcrBackedUserRoleDao.ERROR_0004_LAST_USER_NEEDED_IN_ROLE", tenantAdminRoleName ) ); } } AbstractJcrBackedUserRoleDao( ITenantedPrincipleNameResolver userNameUtils,
                                       ITenantedPrincipleNameResolver roleNameUtils, String authenticatedRoleName,
                                       String tenantAdminRoleName,
                                       String repositoryAdminUsername, IRepositoryFileAclDao repositoryFileAclDao,
                                       IRepositoryFileDao repositoryFileDao,
                                       final IPathConversionHelper pathConversionHelper, final ILockHelper lockHelper,
                                       final IRepositoryDefaultAclHandler defaultAclHandler,
                                       final List<String> systemRoles,
                                       final List<String> extraRoles, UserCache userDetailsCache ); void setRoleMembers( Session session, final ITenant theTenant, final String roleName,
                              final String[] memberUserNames ); void setUserRoles( Session session, final ITenant theTenant, final String userName, final String[] roles ); IPentahoRole createRole( Session session, final ITenant theTenant, final String roleName,
                                  final String description, final String[] memberUserNames ); IPentahoUser createUser( Session session, final ITenant theTenant, final String userName,
                                  final String password, final String description, final String[] roles ); void deleteRole( Session session, final IPentahoRole role ); void deleteUser( Session session, final IPentahoUser user ); List<IPentahoRole> getRoles( Session session ); List<IPentahoUser> getUsers( Session session ); void setRoleDescription( Session session, final ITenant theTenant, final String roleName,
                                  final String description ); void setUserDescription( Session session, final ITenant theTenant, final String userName,
                                  final String description ); void setPassword( Session session, final ITenant theTenant, final String userName, final String password ); ITenantedPrincipleNameResolver getTenantedUserNameUtils(); ITenantedPrincipleNameResolver getTenantedRoleNameUtils(); List<IPentahoRole> getRoles( Session session, ITenant tenant ); List<IPentahoRole> getRoles( Session session, ITenant theTenant, boolean includeSubtenants ); List<IPentahoUser> getUsers( Session session, ITenant tenant ); List<IPentahoUser> getUsers( Session session, ITenant theTenant, boolean includeSubtenants ); IPentahoRole getRole( Session session, final ITenant tenant, final String name ); IPentahoUser getUser( Session session, final ITenant tenant, final String name ); List<IPentahoUser> getRoleMembers( Session session, final ITenant theTenant, final String roleName ); List<IPentahoRole> getUserRoles( Session session, final ITenant theTenant, final String userName ); boolean isUseJackrabbitUserCache(); void setUseJackrabbitUserCache( boolean useJackrabbitUserCache );  }
@Test public void testDeleteUser() throws Exception { String testUser = TEST_USER_NAME + "_delete"; String password1 = "password"; String password2 = "new_password"; setResolverMocks( testUser ); IPentahoUser newUser = abstractJcrBackedUserRoleDaoMock .createUser( adminSession, tenantMock, testUser, password1, TEST_USER_DEC, newRoles ); IPentahoUser existingUser = abstractJcrBackedUserRoleDaoMock.getUser( adminSession, tenantMock, testUser ); assertThat( existingUser, is( newUser ) ); when( abstractJcrBackedUserRoleDaoMock.canDeleteUser( any( Session.class ), any( IPentahoUser.class ) ) ).thenReturn( true ); abstractJcrBackedUserRoleDaoMock.deleteUser( adminSession, newUser ); assertNull( abstractJcrBackedUserRoleDaoMock.getUser( adminSession, tenantMock, testUser ) ); IPentahoUser newUser2 = abstractJcrBackedUserRoleDaoMock .createUser( adminSession, tenantMock, testUser, password2, TEST_USER_DEC, newRoles ); assertNotEquals( newUser.getPassword(), newUser2.getPassword() ); }