@Override public User find(Long id) { User user = super.find(id); if (user != null) { // // To load the LAZY list of the user attributes // if (Hibernate.isInitialized(user)) { List<UserAttribute> attributes = user.getAttribute(); Hibernate.initialize(attributes); Set<UserGroup> groups = user.getGroups(); Hibernate.initialize(groups); } } return user; }
@Override public User get(SecurityContext sc, String name, boolean includeAttributes) throws NotFoundWebEx { if (name == null) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("User Name is null !"); } throw new BadRequestWebEx("User name is null"); } User ret; try { ret = userService.get(name); if (includeAttributes) { ret.setAttribute(ret.getAttribute()); } else { ret.setAttribute(null); } ret.setGroups(removeReservedGroups(ret.getGroups())); } catch (NotFoundServiceEx e) { throw new NotFoundWebEx("User not found"); } return ret; }
@Override public void updateAttributes(long id, List<UserAttribute> attributes) throws NotFoundServiceEx { User user = userDAO.find(id); if (user == null) { throw new NotFoundServiceEx("User not found " + id); } // // Removing old attributes // List<UserAttribute> oldList = user.getAttribute(); // Iterator<UserAttribute> iterator; if (oldList != null) { for (UserAttribute a : oldList) { userAttributeDAO.removeById(a.getId()); } } // // Saving old attributes // for (UserAttribute a : attributes) { a.setUser(user); userAttributeDAO.persist(a); } }
/** * @param list * @param includeAttributes * @return List<User> */ private List<User> configUserList(List<User> list, boolean includeAttributes) { List<User> uList = new ArrayList<User>(list.size()); for (User user : list) { User u = new User(); u.setGroups(user.getGroups()); u.setId(user.getId()); u.setName(user.getName()); u.setEnabled(user.isEnabled()); u.setPassword(user.getPassword()); u.setRole(user.getRole()); if (includeAttributes) { u.setAttribute(user.getAttribute()); } uList.add(u); } return uList; }
List<UserAttribute> attributes = user.getAttribute();
@Override public User get(SecurityContext sc, long id, boolean includeAttributes) throws NotFoundWebEx { if (id == -1) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Retriving dummy data !"); } // // return test instance // User user = new User(); user.setName("dummy name"); return user; } User authUser = userService.get(id); if (authUser == null) { throw new NotFoundWebEx("User not found"); } User ret = new User(); ret.setId(authUser.getId()); ret.setName(authUser.getName()); // ret.setPassword(authUser.getPassword()); // NO! password should not be sent out of the server! ret.setRole(authUser.getRole()); ret.setEnabled(authUser.isEnabled()); ret.setGroups(removeReservedGroups(authUser.getGroups())); if (includeAttributes) { ret.setAttribute(authUser.getAttribute()); } return ret; }
List<UserAttribute> attributeDto = user.getAttribute();
List<UserAttribute> usAttribute = user.getAttribute();
@Override public User getAuthUserDetails(SecurityContext sc, boolean includeAttributes) { User authUser = extractAuthUser(sc); User ret = null; try { authUser = userService.get(authUser.getName()); if (authUser != null) { if(authUser.getRole().equals(Role.GUEST)){ throw new NotFoundWebEx("User not found"); } ret = new User(); ret.setId(authUser.getId()); ret.setName(authUser.getName()); // ret.setPassword(authUser.getPassword()); // NO! password should not be sent out of the server! ret.setRole(authUser.getRole()); ret.setGroups(authUser.getGroups()); if (includeAttributes) { ret.setAttribute(authUser.getAttribute()); } } } catch (NotFoundServiceEx e) { throw new NotFoundWebEx("User not found"); } return ret; }