Search in sources :

Example 6 with XXPortalUser

use of org.apache.ranger.entity.XXPortalUser in project ranger by apache.

the class UserMgr method mapVXPortalUserToXXPortalUser.

public XXPortalUser mapVXPortalUserToXXPortalUser(VXPortalUser userProfile) {
    XXPortalUser gjUser = new XXPortalUser();
    gjUser.setEmailAddress(userProfile.getEmailAddress());
    if ("null".equalsIgnoreCase(userProfile.getFirstName())) {
        userProfile.setFirstName("");
    }
    gjUser.setFirstName(userProfile.getFirstName());
    if ("null".equalsIgnoreCase(userProfile.getLastName())) {
        userProfile.setLastName("");
    }
    gjUser.setLastName(userProfile.getLastName());
    if (userProfile.getLoginId() == null || userProfile.getLoginId().trim().isEmpty() || "null".equalsIgnoreCase(userProfile.getLoginId())) {
        throw restErrorUtil.createRESTException("LoginId should not be null or blank, It is", MessageEnums.INVALID_INPUT_DATA);
    }
    gjUser.setLoginId(userProfile.getLoginId());
    gjUser.setPassword(userProfile.getPassword());
    gjUser.setUserSource(userProfile.getUserSource());
    gjUser.setPublicScreenName(userProfile.getPublicScreenName());
    if (userProfile.getFirstName() != null && userProfile.getLastName() != null && !userProfile.getFirstName().trim().isEmpty() && !userProfile.getLastName().trim().isEmpty()) {
        gjUser.setPublicScreenName(userProfile.getFirstName() + " " + userProfile.getLastName());
    } else {
        gjUser.setPublicScreenName(userProfile.getLoginId());
    }
    return gjUser;
}
Also used : XXPortalUser(org.apache.ranger.entity.XXPortalUser)

Example 7 with XXPortalUser

use of org.apache.ranger.entity.XXPortalUser in project ranger by apache.

the class XUserMgr method updateXUser.

public VXUser updateXUser(VXUser vXUser) {
    if (vXUser == null || vXUser.getName() == null || "null".equalsIgnoreCase(vXUser.getName()) || vXUser.getName().trim().isEmpty()) {
        throw restErrorUtil.createRESTException("Please provide a valid " + "username.", MessageEnums.INVALID_INPUT_DATA);
    }
    checkAccess(vXUser.getName());
    xaBizUtil.blockAuditorRoleUser();
    VXPortalUser oldUserProfile = userMgr.getUserProfileByLoginId(vXUser.getName());
    VXPortalUser vXPortalUser = new VXPortalUser();
    if (oldUserProfile != null && oldUserProfile.getId() != null) {
        vXPortalUser.setId(oldUserProfile.getId());
    }
    // TODO : There is a possibility that old user may not exist.
    vXPortalUser.setFirstName(vXUser.getFirstName());
    if ("null".equalsIgnoreCase(vXPortalUser.getFirstName())) {
        vXPortalUser.setFirstName("");
    }
    vXPortalUser.setLastName(vXUser.getLastName());
    if ("null".equalsIgnoreCase(vXPortalUser.getLastName())) {
        vXPortalUser.setLastName("");
    }
    vXPortalUser.setEmailAddress(vXUser.getEmailAddress());
    vXPortalUser.setLoginId(vXUser.getName());
    vXPortalUser.setStatus(vXUser.getStatus());
    vXPortalUser.setUserRoleList(vXUser.getUserRoleList());
    if (vXPortalUser.getFirstName() != null && vXPortalUser.getLastName() != null && !vXPortalUser.getFirstName().trim().isEmpty() && !vXPortalUser.getLastName().trim().isEmpty()) {
        vXPortalUser.setPublicScreenName(vXPortalUser.getFirstName() + " " + vXPortalUser.getLastName());
    } else {
        vXPortalUser.setPublicScreenName(vXUser.getName());
    }
    vXPortalUser.setUserSource(oldUserProfile.getUserSource());
    String hiddenPasswordString = PropertiesUtil.getProperty("ranger.password.hidden", "*****");
    String password = vXUser.getPassword();
    if (oldUserProfile != null && password != null && password.equals(hiddenPasswordString)) {
        vXPortalUser.setPassword(oldUserProfile.getPassword());
    } else if (oldUserProfile != null && oldUserProfile.getUserSource() == RangerCommonEnums.USER_EXTERNAL && password != null) {
        vXPortalUser.setPassword(oldUserProfile.getPassword());
        logger.debug("User is trrying to change external user password which we are not allowing it to change");
    } else if (password != null) {
        validatePassword(vXUser);
        vXPortalUser.setPassword(password);
    }
    Collection<Long> groupIdList = vXUser.getGroupIdList();
    XXPortalUser xXPortalUser = new XXPortalUser();
    xXPortalUser = userMgr.updateUserWithPass(vXPortalUser);
    // update permissions start
    Collection<String> roleListUpdatedProfile = new ArrayList<String>();
    if (oldUserProfile != null && oldUserProfile.getId() != null) {
        if (vXUser != null && vXUser.getUserRoleList() != null) {
            Collection<String> roleListOldProfile = oldUserProfile.getUserRoleList();
            Collection<String> roleListNewProfile = vXUser.getUserRoleList();
            if (roleListNewProfile != null && roleListOldProfile != null) {
                for (String role : roleListNewProfile) {
                    if (role != null && !roleListOldProfile.contains(role)) {
                        roleListUpdatedProfile.add(role);
                    }
                }
            }
        }
    }
    if (roleListUpdatedProfile != null && roleListUpdatedProfile.size() > 0) {
        vXPortalUser.setUserRoleList(roleListUpdatedProfile);
        List<XXUserPermission> xuserPermissionList = daoManager.getXXUserPermission().findByUserPermissionId(vXPortalUser.getId());
        if (xuserPermissionList != null && xuserPermissionList.size() > 0) {
            for (XXUserPermission xXUserPermission : xuserPermissionList) {
                if (xXUserPermission != null) {
                    try {
                        xUserPermissionService.deleteResource(xXUserPermission.getId());
                    } catch (Exception e) {
                        logger.error(e.getMessage());
                    }
                }
            }
        }
        assignPermissionToUser(vXPortalUser, true);
    }
    // update permissions end
    Collection<String> roleList = new ArrayList<String>();
    if (xXPortalUser != null) {
        roleList = userMgr.getRolesForUser(xXPortalUser);
    }
    if (roleList == null || roleList.size() == 0) {
        roleList = new ArrayList<String>();
        roleList.add(RangerConstants.ROLE_USER);
    }
    // TODO I've to get the transaction log from here.
    // There is nothing to log anything in XXUser so far.
    vXUser = xUserService.updateResource(vXUser);
    vXUser.setUserRoleList(roleList);
    if (oldUserProfile != null) {
        if (oldUserProfile.getUserSource() == RangerCommonEnums.USER_APP) {
            vXUser.setPassword(password);
        } else if (oldUserProfile.getUserSource() == RangerCommonEnums.USER_EXTERNAL) {
            vXUser.setPassword(oldUserProfile.getPassword());
        }
    }
    List<XXTrxLog> trxLogList = xUserService.getTransactionLog(vXUser, oldUserProfile, "update");
    vXUser.setPassword(hiddenPasswordString);
    Long userId = vXUser.getId();
    List<Long> groupUsersToRemove = new ArrayList<Long>();
    if (groupIdList != null) {
        SearchCriteria searchCriteria = new SearchCriteria();
        searchCriteria.addParam("xUserId", userId);
        VXGroupUserList vXGroupUserList = xGroupUserService.searchXGroupUsers(searchCriteria);
        List<VXGroupUser> vXGroupUsers = vXGroupUserList.getList();
        if (vXGroupUsers != null) {
            // Create
            for (Long groupId : groupIdList) {
                boolean found = false;
                for (VXGroupUser vXGroupUser : vXGroupUsers) {
                    if (groupId.equals(vXGroupUser.getParentGroupId())) {
                        found = true;
                        break;
                    }
                }
                if (!found) {
                    VXGroupUser vXGroupUser = createXGroupUser(userId, groupId);
                    trxLogList.addAll(xGroupUserService.getTransactionLog(vXGroupUser, "create"));
                }
            }
            // Delete
            for (VXGroupUser vXGroupUser : vXGroupUsers) {
                boolean found = false;
                for (Long groupId : groupIdList) {
                    if (groupId.equals(vXGroupUser.getParentGroupId())) {
                        trxLogList.addAll(xGroupUserService.getTransactionLog(vXGroupUser, "update"));
                        found = true;
                        break;
                    }
                }
                if (!found) {
                    // TODO I've to get the transaction log from here.
                    trxLogList.addAll(xGroupUserService.getTransactionLog(vXGroupUser, "delete"));
                    groupUsersToRemove.add(vXGroupUser.getId());
                // xGroupUserService.deleteResource(vXGroupUser.getId());
                }
            }
        } else {
            for (Long groupId : groupIdList) {
                VXGroupUser vXGroupUser = createXGroupUser(userId, groupId);
                trxLogList.addAll(xGroupUserService.getTransactionLog(vXGroupUser, "create"));
            }
        }
        vXUser.setGroupIdList(groupIdList);
    } else {
        logger.debug("Group id list can't be null for user. Group user " + "mapping not updated for user : " + userId);
    }
    xaBizUtil.createTrxLog(trxLogList);
    for (Long groupUserId : groupUsersToRemove) {
        xGroupUserService.deleteResource(groupUserId);
    }
    return vXUser;
}
Also used : ArrayList(java.util.ArrayList) XXTrxLog(org.apache.ranger.entity.XXTrxLog) XXUserPermission(org.apache.ranger.entity.XXUserPermission) SearchCriteria(org.apache.ranger.common.SearchCriteria) XXPortalUser(org.apache.ranger.entity.XXPortalUser)

Example 8 with XXPortalUser

use of org.apache.ranger.entity.XXPortalUser in project ranger by apache.

the class XUserMgr method deleteXUser.

public synchronized void deleteXUser(Long id, boolean force) {
    checkAdminAccess();
    xaBizUtil.blockAuditorRoleUser();
    XXUserDao xXUserDao = daoManager.getXXUser();
    XXUser xXUser = xXUserDao.getById(id);
    VXUser vXUser = xUserService.populateViewBean(xXUser);
    if (vXUser == null || StringUtil.isEmpty(vXUser.getName())) {
        throw restErrorUtil.createRESTException("No user found with id=" + id);
    }
    XXPortalUserDao xXPortalUserDao = daoManager.getXXPortalUser();
    XXPortalUser xXPortalUser = xXPortalUserDao.findByLoginId(vXUser.getName().trim());
    VXPortalUser vXPortalUser = null;
    if (xXPortalUser != null) {
        vXPortalUser = xPortalUserService.populateViewBean(xXPortalUser);
    }
    if (vXPortalUser == null || StringUtil.isEmpty(vXPortalUser.getLoginId())) {
        throw restErrorUtil.createRESTException("No user found with id=" + id);
    }
    if (logger.isDebugEnabled()) {
        logger.debug("Force delete status=" + force + " for user=" + vXUser.getName());
    }
    restrictSelfAccountDeletion(vXUser.getName().trim());
    SearchCriteria searchCriteria = new SearchCriteria();
    searchCriteria.addParam("xUserId", id);
    VXGroupUserList vxGroupUserList = searchXGroupUsers(searchCriteria);
    searchCriteria = new SearchCriteria();
    searchCriteria.addParam("userId", id);
    VXPermMapList vXPermMapList = searchXPermMaps(searchCriteria);
    searchCriteria = new SearchCriteria();
    searchCriteria.addParam("userId", id);
    VXAuditMapList vXAuditMapList = searchXAuditMaps(searchCriteria);
    long xXPortalUserId = 0;
    xXPortalUserId = vXPortalUser.getId();
    XXAuthSessionDao xXAuthSessionDao = daoManager.getXXAuthSession();
    XXUserPermissionDao xXUserPermissionDao = daoManager.getXXUserPermission();
    XXPortalUserRoleDao xXPortalUserRoleDao = daoManager.getXXPortalUserRole();
    List<XXAuthSession> xXAuthSessions = xXAuthSessionDao.getAuthSessionByUserId(xXPortalUserId);
    List<XXUserPermission> xXUserPermissions = xXUserPermissionDao.findByUserPermissionId(xXPortalUserId);
    List<XXPortalUserRole> xXPortalUserRoles = xXPortalUserRoleDao.findByUserId(xXPortalUserId);
    XXPolicyDao xXPolicyDao = daoManager.getXXPolicy();
    List<XXPolicy> xXPolicyList = xXPolicyDao.findByUserId(id);
    logger.warn("Deleting User : " + vXUser.getName());
    if (force) {
        // delete XXGroupUser mapping
        XXGroupUserDao xGroupUserDao = daoManager.getXXGroupUser();
        for (VXGroupUser groupUser : vxGroupUserList.getList()) {
            if (groupUser != null) {
                logger.warn("Removing user '" + vXUser.getName() + "' from group '" + groupUser.getName() + "'");
                xGroupUserDao.remove(groupUser.getId());
            }
        }
        // delete XXPermMap records of user
        XXPermMapDao xXPermMapDao = daoManager.getXXPermMap();
        for (VXPermMap vXPermMap : vXPermMapList.getList()) {
            if (vXPermMap != null) {
                logger.warn("Deleting '" + AppConstants.getLabelFor_XAPermType(vXPermMap.getPermType()) + "' permission from policy ID='" + vXPermMap.getResourceId() + "' for user '" + vXPermMap.getUserName() + "'");
                xXPermMapDao.remove(vXPermMap.getId());
            }
        }
        // delete XXAuditMap records of user
        XXAuditMapDao xXAuditMapDao = daoManager.getXXAuditMap();
        for (VXAuditMap vXAuditMap : vXAuditMapList.getList()) {
            if (vXAuditMap != null) {
                xXAuditMapDao.remove(vXAuditMap.getId());
            }
        }
        // delete XXPortalUser references
        if (vXPortalUser != null) {
            xPortalUserService.updateXXPortalUserReferences(xXPortalUserId);
            if (xXAuthSessions != null && xXAuthSessions.size() > 0) {
                logger.warn("Deleting " + xXAuthSessions.size() + " login session records for user '" + vXPortalUser.getLoginId() + "'");
            }
            for (XXAuthSession xXAuthSession : xXAuthSessions) {
                xXAuthSessionDao.remove(xXAuthSession.getId());
            }
            for (XXUserPermission xXUserPermission : xXUserPermissions) {
                if (xXUserPermission != null) {
                    XXModuleDef xXModuleDef = daoManager.getXXModuleDef().findByModuleId(xXUserPermission.getModuleId());
                    if (xXModuleDef != null) {
                        logger.warn("Deleting '" + xXModuleDef.getModule() + "' module permission for user '" + vXPortalUser.getLoginId() + "'");
                    }
                    xXUserPermissionDao.remove(xXUserPermission.getId());
                }
            }
            for (XXPortalUserRole xXPortalUserRole : xXPortalUserRoles) {
                if (xXPortalUserRole != null) {
                    logger.warn("Deleting '" + xXPortalUserRole.getUserRole() + "' role for user '" + vXPortalUser.getLoginId() + "'");
                    xXPortalUserRoleDao.remove(xXPortalUserRole.getId());
                }
            }
        }
        // delete XXPolicyItemUserPerm records of user
        for (XXPolicy xXPolicy : xXPolicyList) {
            RangerPolicy rangerPolicy = policyService.getPopulatedViewObject(xXPolicy);
            List<RangerPolicyItem> policyItems = rangerPolicy.getPolicyItems();
            removeUserGroupReferences(policyItems, vXUser.getName(), null);
            rangerPolicy.setPolicyItems(policyItems);
            List<RangerPolicyItem> denyPolicyItems = rangerPolicy.getDenyPolicyItems();
            removeUserGroupReferences(denyPolicyItems, vXUser.getName(), null);
            rangerPolicy.setDenyPolicyItems(denyPolicyItems);
            List<RangerPolicyItem> allowExceptions = rangerPolicy.getAllowExceptions();
            removeUserGroupReferences(allowExceptions, vXUser.getName(), null);
            rangerPolicy.setAllowExceptions(allowExceptions);
            List<RangerPolicyItem> denyExceptions = rangerPolicy.getDenyExceptions();
            removeUserGroupReferences(denyExceptions, vXUser.getName(), null);
            rangerPolicy.setDenyExceptions(denyExceptions);
            List<RangerDataMaskPolicyItem> dataMaskItems = rangerPolicy.getDataMaskPolicyItems();
            removeUserGroupReferences(dataMaskItems, vXUser.getName(), null);
            rangerPolicy.setDataMaskPolicyItems(dataMaskItems);
            List<RangerRowFilterPolicyItem> rowFilterItems = rangerPolicy.getRowFilterPolicyItems();
            removeUserGroupReferences(rowFilterItems, vXUser.getName(), null);
            rangerPolicy.setRowFilterPolicyItems(rowFilterItems);
            try {
                svcStore.updatePolicy(rangerPolicy);
            } catch (Throwable excp) {
                logger.error("updatePolicy(" + rangerPolicy + ") failed", excp);
                throw restErrorUtil.createRESTException(excp.getMessage());
            }
        }
        // delete XXUser entry of user
        xXUserDao.remove(id);
        // delete XXPortal entry of user
        logger.warn("Deleting Portal User : " + vXPortalUser.getLoginId());
        xXPortalUserDao.remove(xXPortalUserId);
        List<XXTrxLog> trxLogList = xUserService.getTransactionLog(xUserService.populateViewBean(xXUser), "delete");
        xaBizUtil.createTrxLog(trxLogList);
        if (xXPortalUser != null) {
            trxLogList = xPortalUserService.getTransactionLog(xPortalUserService.populateViewBean(xXPortalUser), "delete");
            xaBizUtil.createTrxLog(trxLogList);
        }
    } else {
        boolean hasReferences = false;
        if (vxGroupUserList != null && vxGroupUserList.getListSize() > 0) {
            hasReferences = true;
        }
        if (hasReferences == false && xXPolicyList != null && xXPolicyList.size() > 0) {
            hasReferences = true;
        }
        if (hasReferences == false && vXPermMapList != null && vXPermMapList.getListSize() > 0) {
            hasReferences = true;
        }
        if (hasReferences == false && vXAuditMapList != null && vXAuditMapList.getListSize() > 0) {
            hasReferences = true;
        }
        if (hasReferences == false && xXAuthSessions != null && xXAuthSessions.size() > 0) {
            hasReferences = true;
        }
        if (hasReferences == false && xXUserPermissions != null && xXUserPermissions.size() > 0) {
            hasReferences = true;
        }
        if (hasReferences == false && xXPortalUserRoles != null && xXPortalUserRoles.size() > 0) {
            hasReferences = true;
        }
        if (hasReferences) {
            if (vXUser.getIsVisible() != RangerCommonEnums.IS_HIDDEN) {
                logger.info("Updating visibility of user '" + vXUser.getName() + "' to Hidden!");
                vXUser.setIsVisible(RangerCommonEnums.IS_HIDDEN);
                xUserService.updateResource(vXUser);
            }
        } else {
            xPortalUserService.updateXXPortalUserReferences(xXPortalUserId);
            // delete XXUser entry of user
            xXUserDao.remove(id);
            // delete XXPortal entry of user
            logger.warn("Deleting Portal User : " + vXPortalUser.getLoginId());
            xXPortalUserDao.remove(xXPortalUserId);
            List<XXTrxLog> trxLogList = xUserService.getTransactionLog(xUserService.populateViewBean(xXUser), "delete");
            xaBizUtil.createTrxLog(trxLogList);
            trxLogList = xPortalUserService.getTransactionLog(xPortalUserService.populateViewBean(xXPortalUser), "delete");
            xaBizUtil.createTrxLog(trxLogList);
        }
    }
}
Also used : XXUser(org.apache.ranger.entity.XXUser) XXUserDao(org.apache.ranger.db.XXUserDao) XXPolicy(org.apache.ranger.entity.XXPolicy) XXAuthSessionDao(org.apache.ranger.db.XXAuthSessionDao) XXPortalUserRoleDao(org.apache.ranger.db.XXPortalUserRoleDao) XXGroupUserDao(org.apache.ranger.db.XXGroupUserDao) XXModuleDef(org.apache.ranger.entity.XXModuleDef) RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) XXPermMapDao(org.apache.ranger.db.XXPermMapDao) XXPortalUserRole(org.apache.ranger.entity.XXPortalUserRole) XXUserPermissionDao(org.apache.ranger.db.XXUserPermissionDao) XXAuditMapDao(org.apache.ranger.db.XXAuditMapDao) RangerRowFilterPolicyItem(org.apache.ranger.plugin.model.RangerPolicy.RangerRowFilterPolicyItem) XXTrxLog(org.apache.ranger.entity.XXTrxLog) XXAuthSession(org.apache.ranger.entity.XXAuthSession) XXUserPermission(org.apache.ranger.entity.XXUserPermission) RangerPolicyItem(org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyItem) SearchCriteria(org.apache.ranger.common.SearchCriteria) XXPortalUser(org.apache.ranger.entity.XXPortalUser) RangerDataMaskPolicyItem(org.apache.ranger.plugin.model.RangerPolicy.RangerDataMaskPolicyItem) XXPortalUserDao(org.apache.ranger.db.XXPortalUserDao) XXPolicyDao(org.apache.ranger.db.XXPolicyDao)

Example 9 with XXPortalUser

use of org.apache.ranger.entity.XXPortalUser in project ranger by apache.

the class XUserMgr method createXGroupUserFromMap.

@Transactional(readOnly = false, propagation = Propagation.REQUIRED)
public VXGroupUserInfo createXGroupUserFromMap(VXGroupUserInfo vXGroupUserInfo) {
    checkAdminAccess();
    xaBizUtil.blockAuditorRoleUser();
    VXGroupUserInfo vxGUInfo = new VXGroupUserInfo();
    VXGroup vXGroup = vXGroupUserInfo.getXgroupInfo();
    // Add the group user mappings for a given group to x_group_user table
    /*XXGroup xGroup = daoManager.getXXGroup().findByGroupName(vXGroup.getName());
		if (xGroup == null) {
			return vxGUInfo;
		}*/
    List<VXUser> vxu = new ArrayList<VXUser>();
    for (VXUser vXUser : vXGroupUserInfo.getXuserInfo()) {
        XXUser xUser = daoManager.getXXUser().findByUserName(vXUser.getName());
        XXPortalUser xXPortalUser = daoManager.getXXPortalUser().findByLoginId(vXUser.getName());
        if (xUser != null) {
            // Add or update group user mapping only if the user already exists in x_user table.
            logger.debug(String.format("createXGroupUserFromMap(): Create or update group %s ", vXGroup.getName()));
            vXGroup = xGroupService.createXGroupWithOutLogin(vXGroup);
            vxGUInfo.setXgroupInfo(vXGroup);
            vxu.add(vXUser);
            VXGroupUser vXGroupUser = new VXGroupUser();
            vXGroupUser.setUserId(xUser.getId());
            vXGroupUser.setName(vXGroup.getName());
            if (xXPortalUser.getUserSource() == RangerCommonEnums.USER_EXTERNAL) {
                vXGroupUser = xGroupUserService.createXGroupUserWithOutLogin(vXGroupUser);
                logger.debug(String.format("createXGroupUserFromMap(): Create or update group user mapping with groupname =  " + vXGroup.getName() + " username = %s userId = %d", xXPortalUser.getLoginId(), xUser.getId()));
            }
            Collection<String> reqRoleList = vXUser.getUserRoleList();
            XXPortalUser xxPortalUser = daoManager.getXXPortalUser().findByLoginId(vXUser.getName());
            List<String> existingRole = daoManager.getXXPortalUserRole().findXPortalUserRolebyXPortalUserId(xxPortalUser.getId());
            VXPortalUser vxPortalUser = userManager.mapXXPortalUserToVXPortalUserForDefaultAccount(xxPortalUser);
            if (xxPortalUser.getUserSource() == RangerCommonEnums.USER_EXTERNAL) {
                vxPortalUser = userManager.updateRoleForExternalUsers(reqRoleList, existingRole, vxPortalUser);
                assignPermissionToUser(vxPortalUser, true);
            }
        }
    }
    vxGUInfo.setXuserInfo(vxu);
    return vxGUInfo;
}
Also used : XXUser(org.apache.ranger.entity.XXUser) XXPortalUser(org.apache.ranger.entity.XXPortalUser) ArrayList(java.util.ArrayList) Transactional(org.springframework.transaction.annotation.Transactional)

Example 10 with XXPortalUser

use of org.apache.ranger.entity.XXPortalUser in project ranger by apache.

the class TestRangerServiceService method test5GetAllServices.

@Test
public void test5GetAllServices() {
    XXServiceDao xServiceDao = Mockito.mock(XXServiceDao.class);
    XXPortalUserDao xPortalUserDao = Mockito.mock(XXPortalUserDao.class);
    XXServiceConfigMapDao xServiceConfigMapDao = Mockito.mock(XXServiceConfigMapDao.class);
    XXServiceDefDao xServiceDefDao = Mockito.mock(XXServiceDefDao.class);
    String name = "fdfdfds";
    List<XXServiceConfigMap> svcConfigMapList = new ArrayList<XXServiceConfigMap>();
    XXServiceConfigMap xConfMap = new XXServiceConfigMap();
    xConfMap.setAddedByUserId(null);
    xConfMap.setConfigkey(name);
    xConfMap.setConfigvalue(name);
    xConfMap.setCreateTime(new Date());
    xConfMap.setServiceId(null);
    xConfMap.setUpdatedByUserId(null);
    xConfMap.setUpdateTime(new Date());
    svcConfigMapList.add(xConfMap);
    List<XXService> xServiceList = new ArrayList<XXService>();
    XXService xService = xService();
    xServiceList.add(xService);
    XXPortalUser tUser = new XXPortalUser();
    tUser.setAddedByUserId(userId);
    tUser.setCreateTime(new Date());
    tUser.setEmailAddress("test@gmail.com");
    tUser.setFirstName(name);
    tUser.setId(userId);
    tUser.setLastName(name);
    XXServiceDef xServiceDef = new XXServiceDef();
    xServiceDef.setAddedByUserId(userId);
    xServiceDef.setCreateTime(new Date());
    xServiceDef.setDescription("test");
    xServiceDef.setGuid("1427365526516_835_0");
    xServiceDef.setId(userId);
    XXServiceVersionInfoDao xServiceVersionInfoDao = Mockito.mock(XXServiceVersionInfoDao.class);
    XXServiceVersionInfo serviceVersionInfo = new XXServiceVersionInfo();
    serviceVersionInfo.setServiceId(xService.getId());
    serviceVersionInfo.setPolicyVersion(xService.getPolicyVersion());
    serviceVersionInfo.setPolicyUpdateTime(xService.getPolicyUpdateTime());
    serviceVersionInfo.setTagVersion(xService.getTagVersion());
    serviceVersionInfo.setTagUpdateTime(xService.getTagUpdateTime());
    Mockito.when(daoManager.getXXServiceVersionInfo()).thenReturn(xServiceVersionInfoDao);
    Mockito.when(xServiceVersionInfoDao.findByServiceId(xService.getId())).thenReturn(serviceVersionInfo);
    Mockito.when(daoManager.getXXService()).thenReturn(xServiceDao);
    Mockito.when(xServiceDao.getAll()).thenReturn(xServiceList);
    Mockito.when(daoManager.getXXPortalUser()).thenReturn(xPortalUserDao);
    Mockito.when(xPortalUserDao.getById(userId)).thenReturn(tUser);
    Mockito.when(daoManager.getXXServiceDef()).thenReturn(xServiceDefDao);
    Mockito.when(xServiceDefDao.getById(xService.getType())).thenReturn(xServiceDef);
    Mockito.when(daoManager.getXXServiceConfigMap()).thenReturn(xServiceConfigMapDao);
    Mockito.when(xServiceConfigMapDao.findByServiceId(xService.getId())).thenReturn(svcConfigMapList);
    List<RangerService> dbServiceList = serviceService.getAllServices();
    Assert.assertNotNull(dbServiceList);
    Mockito.verify(daoManager).getXXServiceDef();
    Mockito.verify(daoManager).getXXServiceConfigMap();
}
Also used : XXServiceDef(org.apache.ranger.entity.XXServiceDef) ArrayList(java.util.ArrayList) XXServiceDao(org.apache.ranger.db.XXServiceDao) XXServiceConfigMapDao(org.apache.ranger.db.XXServiceConfigMapDao) Date(java.util.Date) XXServiceConfigMap(org.apache.ranger.entity.XXServiceConfigMap) XXPortalUser(org.apache.ranger.entity.XXPortalUser) XXServiceDefDao(org.apache.ranger.db.XXServiceDefDao) XXPortalUserDao(org.apache.ranger.db.XXPortalUserDao) RangerService(org.apache.ranger.plugin.model.RangerService) XXService(org.apache.ranger.entity.XXService) XXServiceVersionInfo(org.apache.ranger.entity.XXServiceVersionInfo) XXServiceVersionInfoDao(org.apache.ranger.db.XXServiceVersionInfoDao) Test(org.junit.Test)

Aggregations

XXPortalUser (org.apache.ranger.entity.XXPortalUser)98 ArrayList (java.util.ArrayList)40 Test (org.junit.Test)39 XXPortalUserDao (org.apache.ranger.db.XXPortalUserDao)32 VXPortalUser (org.apache.ranger.view.VXPortalUser)30 VXString (org.apache.ranger.view.VXString)26 XXPortalUserRole (org.apache.ranger.entity.XXPortalUserRole)21 XXPortalUserRoleDao (org.apache.ranger.db.XXPortalUserRoleDao)19 Date (java.util.Date)15 XXUserPermission (org.apache.ranger.entity.XXUserPermission)14 XXModuleDef (org.apache.ranger.entity.XXModuleDef)12 XXUser (org.apache.ranger.entity.XXUser)12 UserSessionBase (org.apache.ranger.common.UserSessionBase)11 XXGroupPermission (org.apache.ranger.entity.XXGroupPermission)11 VXUserPermission (org.apache.ranger.view.VXUserPermission)10 XXUserPermissionDao (org.apache.ranger.db.XXUserPermissionDao)9 VXGroupPermission (org.apache.ranger.view.VXGroupPermission)9 RangerSecurityContext (org.apache.ranger.security.context.RangerSecurityContext)8 XXGroupPermissionDao (org.apache.ranger.db.XXGroupPermissionDao)7 XXTrxLog (org.apache.ranger.entity.XXTrxLog)7