Search in sources :

Example 41 with DataGridUser

use of com.emc.metalnx.core.domain.entity.DataGridUser in project metalnx-web by irods-contrib.

the class UserBookmarkController method listBookmarks.

@RequestMapping(value = "/")
public String listBookmarks(final Model model) {
    String loggedUsername = irodsServices.getCurrentUser();
    String loggedUserZoneName = irodsServices.getCurrentUserZone();
    DataGridUser user = userService.findByUsernameAndAdditionalInfo(loggedUsername, loggedUserZoneName);
    List<DataGridUserBookmark> userBookmakrs = user.getBookmarksSorted();
    logger.info("userBookmarks found....");
    logger.info(userBookmakrs.toString());
    model.addAttribute("userBookmarks", userBookmakrs);
    model.addAttribute("foundUserBookmarks", !userBookmakrs.isEmpty());
    model.addAttribute("topnavHeader", headerService.getheader("shared"));
    return "bookmarks/userBookmarks";
}
Also used : DataGridUserBookmark(com.emc.metalnx.core.domain.entity.DataGridUserBookmark) DataGridUser(com.emc.metalnx.core.domain.entity.DataGridUser) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 42 with DataGridUser

use of com.emc.metalnx.core.domain.entity.DataGridUser in project metalnx-web by irods-contrib.

the class HttpResponseHandlerInterceptor method postHandle.

@Override
public void postHandle(final HttpServletRequest request, final HttpServletResponse response, final Object handler, final ModelAndView modelAndView) throws Exception {
    Authentication auth = SecurityContextHolder.getContext().getAuthentication();
    if (modelAndView != null && auth != null) {
        if (urlMap == null) {
            urlMap = new URLMap();
        }
        if (emcmetalnxVersion == null) {
            emcmetalnxVersion = new EmcMetalnxVersion();
        }
        modelAndView.getModelMap().addAttribute("urlMap", urlMap);
        modelAndView.getModelMap().addAttribute("emcmetalnxVersion", emcmetalnxVersion);
        modelAndView.getModelMap().addAttribute("jargonVersion", new JargonVersion());
        modelAndView.getModelMap().addAttribute("globalConfig", configService.getGlobalConfig());
        DataGridUser loggedUser = loggedUserUtils.getLoggedDataGridUser();
        logger.debug("added user prefs to model as 'dataGridUser':{}", loggedUser);
        modelAndView.getModelMap().addAttribute("dataGridUser", loggedUser);
        if (auth instanceof UsernamePasswordAuthenticationToken) {
            userTokenDetails = (UserTokenDetails) auth.getDetails();
            modelAndView.getModelMap().addAttribute("userDetails", userTokenDetails.getUser());
        }
    }
    // closing sessions to avoid idle agents
    irodsAccessObjectFactory.closeSessionAndEatExceptions();
}
Also used : JargonVersion(org.irods.jargon.core.utils.JargonVersion) Authentication(org.springframework.security.core.Authentication) DataGridUser(com.emc.metalnx.core.domain.entity.DataGridUser) EmcMetalnxVersion(com.emc.metalnx.utils.EmcMetalnxVersion) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) URLMap(com.emc.metalnx.modelattribute.enums.URLMap)

Example 43 with DataGridUser

use of com.emc.metalnx.core.domain.entity.DataGridUser in project metalnx-web by irods-contrib.

the class GroupServiceImpl method updateMemberList.

@Override
public boolean updateMemberList(DataGridGroup group, List<DataGridUser> users) throws DataGridConnectionRefusedException {
    try {
        UserGroupAO groupAO = irodsServices.getGroupAO();
        // Users that are currently on this group
        List<User> usersFromIrods = groupAO.listUserGroupMembers(group.getGroupname());
        // Building set with iRODS IDs already on this group
        HashMap<Long, User> idsFromIrods = new HashMap<Long, User>();
        for (User userFromIrods : usersFromIrods) {
            idsFromIrods.put(Long.valueOf(userFromIrods.getId()), userFromIrods);
        }
        // Building set with iRODS IDs coming from UI
        HashMap<Long, DataGridUser> idsFromUi = new HashMap<Long, DataGridUser>();
        for (DataGridUser userFromUi : users) {
            idsFromUi.put(userFromUi.getDataGridId(), userFromUi);
        }
        // Resolving differences from UI to iRODS
        Set<Long> keysFromUi = idsFromUi.keySet();
        Set<Long> keysFromIrods = idsFromIrods.keySet();
        for (Long dataGridId : keysFromUi) {
            if (!keysFromIrods.contains(dataGridId)) {
                attachUserToGroup(idsFromUi.get(dataGridId), group);
            }
        }
        for (Long dataGridId : keysFromIrods) {
            if (!keysFromUi.contains(dataGridId)) {
                DataGridUser user = new DataGridUser();
                user.setUsername(idsFromIrods.get(dataGridId).getName());
                removeUserFromGroup(user, group);
            }
        }
        return true;
    } catch (Exception e) {
        logger.info("Could not update [" + group.getGroupname() + "]: ", e);
    }
    return false;
}
Also used : DataGridUser(com.emc.metalnx.core.domain.entity.DataGridUser) User(org.irods.jargon.core.pub.domain.User) DataGridUser(com.emc.metalnx.core.domain.entity.DataGridUser) UserGroupAO(org.irods.jargon.core.pub.UserGroupAO) DataGridException(com.emc.metalnx.core.domain.exceptions.DataGridException) DuplicateDataException(org.irods.jargon.core.exception.DuplicateDataException) DataGridConnectionRefusedException(com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException) JargonException(org.irods.jargon.core.exception.JargonException)

Example 44 with DataGridUser

use of com.emc.metalnx.core.domain.entity.DataGridUser in project metalnx-web by irods-contrib.

the class UserServiceImpl method createUser.

@Override
public boolean createUser(DataGridUser user, String password) throws JargonException, DataGridConnectionRefusedException {
    logger.info("createUser()");
    UserAO userAO = irodsServices.getUserAO();
    // Translating to iRODS model format
    User irodsUser = new User();
    irodsUser.setName(user.getUsername());
    irodsUser.setZone(user.getAdditionalInfo());
    if (user.getUserType().compareTo(UserTypeEnum.RODS_ADMIN.getTextValue()) == 0) {
        irodsUser.setUserType(UserTypeEnum.RODS_ADMIN);
    } else {
        irodsUser.setUserType(UserTypeEnum.RODS_USER);
    }
    logger.debug("adding...");
    // Creating user
    irodsUser = userAO.addUser(irodsUser);
    logger.debug("...added");
    user.setDataGridId(Long.parseLong(irodsUser.getId()));
    user.setEnabled(true);
    userDao.save(user);
    logger.info("setting password if provided (may be a PAM user!)");
    if (password == null || password.isEmpty()) {
        logger.info("no password, assume is not standard auth");
    } else {
        logger.info("password was provided, set in irods");
        // Setting password
        userAO.changeAUserPasswordByAnAdmin(user.getUsername(), password);
    }
    return true;
}
Also used : DataGridUser(com.emc.metalnx.core.domain.entity.DataGridUser) User(org.irods.jargon.core.pub.domain.User) UserAO(org.irods.jargon.core.pub.UserAO)

Example 45 with DataGridUser

use of com.emc.metalnx.core.domain.entity.DataGridUser in project metalnx-web by irods-contrib.

the class UserServiceImpl method modifyUser.

@Override
public boolean modifyUser(DataGridUser modifyUser) throws DataGridConnectionRefusedException {
    UserAO userAO = irodsServices.getUserAO();
    try {
        User iRodsUser = userAO.findById(String.valueOf(modifyUser.getDataGridId()));
        boolean iRodsFieldsModified = false;
        // check which fields were modified (iRODS)
        if (iRodsUser.getZone().compareTo(modifyUser.getAdditionalInfo()) != 0) {
            iRodsUser.setZone(modifyUser.getAdditionalInfo());
            iRodsFieldsModified = true;
        }
        if (!iRodsUser.getUserType().getTextValue().equals(modifyUser.getUserType())) {
            if (modifyUser.getUserType().compareTo(UserTypeEnum.RODS_ADMIN.getTextValue()) == 0) {
                iRodsUser.setUserType(UserTypeEnum.RODS_ADMIN);
            } else {
                iRodsUser.setUserType(UserTypeEnum.RODS_USER);
            }
            iRodsFieldsModified = true;
        }
        // updating user in iRODS if any field was modified
        if (iRodsFieldsModified) {
            userAO.updateUser(iRodsUser);
        }
        DataGridUser applicationUser = userDao.findByUsernameAndZone(modifyUser.getUsername(), modifyUser.getAdditionalInfo());
        // check which fields were modified (our database)
        if (applicationUser.getAdditionalInfo() == null || applicationUser.getAdditionalInfo().compareTo(modifyUser.getAdditionalInfo()) != 0) {
            applicationUser.setAdditionalInfo(modifyUser.getAdditionalInfo());
        }
        if (applicationUser.getFirstName() == null || applicationUser.getFirstName().compareTo(modifyUser.getFirstName()) != 0) {
            applicationUser.setFirstName(modifyUser.getFirstName());
        }
        if (applicationUser.getLastName() == null || applicationUser.getLastName().compareTo(modifyUser.getLastName()) != 0) {
            applicationUser.setLastName(modifyUser.getLastName());
        }
        if (applicationUser.getEmail() == null || applicationUser.getEmail().compareTo(modifyUser.getEmail()) != 0) {
            applicationUser.setEmail(modifyUser.getEmail());
        }
        if (applicationUser.getCompany() == null || applicationUser.getCompany().compareTo(modifyUser.getCompany()) != 0) {
            applicationUser.setCompany(modifyUser.getCompany());
        }
        if (applicationUser.getDepartment() == null || applicationUser.getDepartment().compareTo(modifyUser.getDepartment()) != 0) {
            applicationUser.setDepartment(modifyUser.getDepartment());
        }
        applicationUser.setUserProfile(modifyUser.getUserProfile());
        applicationUser.setLocale(modifyUser.getLocale());
        applicationUser.setOrganizationalRole(modifyUser.getOrganizationalRole());
        applicationUser.setUserType(modifyUser.getUserType());
        applicationUser.setForceFileOverwriting(modifyUser.isForceFileOverwriting());
        applicationUser.setAdvanceView(modifyUser.isAdvancedView());
        userDao.merge(applicationUser);
        // Changing password if a new password is set
        String newPassword = modifyUser.getPassword();
        if (newPassword != null && !newPassword.isEmpty()) {
            userAO.changeAUserPasswordByAnAdmin(modifyUser.getUsername(), newPassword);
        }
        return true;
    } catch (JargonException e) {
        e.printStackTrace();
    }
    return false;
}
Also used : DataGridUser(com.emc.metalnx.core.domain.entity.DataGridUser) User(org.irods.jargon.core.pub.domain.User) DataGridUser(com.emc.metalnx.core.domain.entity.DataGridUser) JargonException(org.irods.jargon.core.exception.JargonException) UserAO(org.irods.jargon.core.pub.UserAO)

Aggregations

DataGridUser (com.emc.metalnx.core.domain.entity.DataGridUser)48 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)28 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)8 JargonException (org.irods.jargon.core.exception.JargonException)7 ArrayList (java.util.ArrayList)6 HashSet (java.util.HashSet)6 DataGridGroup (com.emc.metalnx.core.domain.entity.DataGridGroup)5 User (org.irods.jargon.core.pub.domain.User)5 DataGridException (com.emc.metalnx.core.domain.exceptions.DataGridException)4 HashMap (java.util.HashMap)4 Query (org.hibernate.Query)4 UserAO (org.irods.jargon.core.pub.UserAO)4 Authentication (org.springframework.security.core.Authentication)4 UserProfile (com.emc.metalnx.core.domain.entity.UserProfile)3 DataGridConnectionRefusedException (com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 DataGridUserBookmark (com.emc.metalnx.core.domain.entity.DataGridUserBookmark)2 DataGridUserFavorite (com.emc.metalnx.core.domain.entity.DataGridUserFavorite)2 URLMap (com.emc.metalnx.modelattribute.enums.URLMap)2 GroupForm (com.emc.metalnx.modelattribute.group.GroupForm)2