@Transactional public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException, DataAccessException { User u = userDao.getUserByName(username); if (u == null) { throw new UsernameNotFoundException("User '" + username + "' was not found"); } // LOG.debug("admin would be:" + passwordEncoder.encodePassword("admin", new Long(83))); return u; }
@Transactional public void deleteUser(long id) { User u = userDao.getUserById(id); Role adminRole = roleService.getAdminRole(); int articleCount = articleService.getArticleCountByUser(u); int adminCount = userDao.getAdminUserCount(); LOG.debug("trying to delete user " + u.getUsername()); LOG.debug("global admin count: " + adminCount); LOG.debug("is admin user: "******"number articles associated: " + articleCount); if (u.getAuthorities().contains(adminRole) && adminCount == 1) { LOG.error("cant delete last admin user"); return; } if (articleCount > 0) { LOG.error("User still has articles associated"); return; } LOG.debug("deleting user " + u.getUsername()); userDao.deleteUser(u); }
@Transactional public void saveUser(User u) { userDao.saveOrUpdate(u); }
@Transactional public List<User> getAllUsers() { return userDao.getAllUsers(); }
@Transactional public int getUserCount() { return userDao.getUserCount(); }
@Transactional public void addUser(User u, String pass) { userDao.saveOrUpdate(u); u.setPassword(passwordEncoder.encodePassword(pass, u.getId())); userDao.saveOrUpdate(u); }
@Transactional public User getUserById(long id) { return userDao.getUserById(id); }