class SecurityServiceImpl extends RemoteServiceServlet implements SecurityService {

	@Override
	public GUIUser getUser(long userId) throws ServerException {
		ServiceUtil.validateSession(getThreadLocalRequest());
		try {
			UserDAO userDao = (UserDAO) Context.get().getBean(UserDAO.class);
			SequenceDAO seqDao = (SequenceDAO) Context.get().getBean(SequenceDAO.class);

			User user = userDao.findById(userId);
			if (user != null) {
				userDao.initialize(user);

				GUIUser guiUser = new GUIUser();
				guiUser.setId(userId);
				guiUser.setTenant(getTenant(user.getTenantId()));
				guiUser.setAddress(user.getStreet());
				guiUser.setCell(user.getTelephone2());
				guiUser.setPhone(user.getTelephone());
				guiUser.setCity(user.getCity());
				guiUser.setCountry(user.getCountry());
				guiUser.setEmail(user.getEmail());
				guiUser.setEmail2(user.getEmail2());
				guiUser.setEnabled(user.getEnabled() == 1);
				guiUser.setFirstName(user.getFirstName());
				guiUser.setLanguage(user.getLanguage());
				guiUser.setName(user.getName());
				guiUser.setPostalCode(user.getPostalcode());
				guiUser.setState(user.getState());
				guiUser.setUsername(user.getUsername());
				guiUser.setPasswordExpires(user.getPasswordExpires() == 1);
				guiUser.setPasswordExpired(user.getPasswordExpired() == 1);
				guiUser.setWelcomeScreen(user.getWelcomeScreen());
				guiUser.setDefaultWorkspace(user.getDefaultWorkspace());
				guiUser.setIpWhitelist(user.getIpWhiteList());
				guiUser.setIpBlacklist(user.getIpBlackList());
				guiUser.setEmailSignature(user.getEmailSignature());
				guiUser.setEmailSignature2(user.getEmailSignature2());
				guiUser.setCertExpire(user.getCertExpire());
				guiUser.setCertDN(user.getCertDN());
				guiUser.setSecondFactor(user.getSecondFactor());
				guiUser.setKey(user.getKey());
				guiUser.setType(user.getType());
				guiUser.setDocsGrid(user.getDocsGrid());
				guiUser.setHitsGrid(user.getHitsGrid());

				GUIGroup[] grps = new GUIGroup[user.getGroups().size()];
				int i = 0;
				for (Group group : user.getGroups()) {
					grps[i] = new GUIGroup();
					grps[i].setId(group.getId());
					grps[i].setName(group.getName());
					grps[i].setDescription(group.getDescription());
					grps[i].setType(group.getType());
					grps[i].setSource(group.getSource());
					i++;
				}
				guiUser.setGroups(grps);

				guiUser.setQuota(user.getQuota());

				guiUser.setQuotaCount(seqDao.getCurrentValue("userquota", user.getId(), user.getTenantId()));

				guiUser.setTenant(getTenant(user.getTenantId()));

				ContextProperties config = Context.get().getProperties();
				guiUser.setPasswordMinLenght(
						Integer.parseInt(config.getProperty(guiUser.getTenant().getName() + ".password.size")));

				loadDashlets(guiUser);

				return guiUser;
			}
		} catch (Throwable t) {
			log.error(t.getMessage(), t);
		}
		return null;
	}

}