Search in sources :

Example 36 with XXModuleDefDao

use of org.apache.ranger.db.XXModuleDefDao in project ranger by apache.

the class TestXUserMgr method test05UpdateXUser.

@Test
public void test05UpdateXUser() {
    setup();
    XXUserPermissionDao xUserPermissionDao = Mockito.mock(XXUserPermissionDao.class);
    Collection<String> existingRoleList = new ArrayList<String>();
    existingRoleList.add(RangerConstants.ROLE_USER);
    Collection<String> reqRoleList = new ArrayList<String>();
    reqRoleList.add(RangerConstants.ROLE_SYS_ADMIN);
    Collection<Long> groupIdList = new ArrayList<Long>();
    groupIdList.add(userId);
    VXUser vxUser = vxUser();
    vxUser.setUserRoleList(reqRoleList);
    vxUser.setUserSource(RangerCommonEnums.USER_EXTERNAL);
    vxUser.setGroupIdList(groupIdList);
    vxUser.setFirstName("user12");
    vxUser.setLastName("test12");
    Mockito.when(xUserService.updateResource(vxUser)).thenReturn(vxUser);
    XXModuleDefDao xModuleDefDao = Mockito.mock(XXModuleDefDao.class);
    VXPortalUser vXPortalUser = userProfile();
    vXPortalUser.setUserRoleList(existingRoleList);
    Mockito.when(userMgr.getUserProfileByLoginId(vxUser.getName())).thenReturn(vXPortalUser);
    Mockito.when(daoManager.getXXUserPermission()).thenReturn(xUserPermissionDao);
    List<XXUserPermission> xUserPermissionsList = new ArrayList<XXUserPermission>();
    XXUserPermission xUserPermissionObj = new XXUserPermission();
    xUserPermissionObj.setAddedByUserId(userId);
    xUserPermissionObj.setCreateTime(new Date());
    xUserPermissionObj.setId(userId);
    xUserPermissionObj.setIsAllowed(1);
    xUserPermissionObj.setModuleId(1L);
    xUserPermissionObj.setUpdatedByUserId(userId);
    xUserPermissionObj.setUpdateTime(new Date());
    xUserPermissionObj.setUserId(userId);
    xUserPermissionsList.add(xUserPermissionObj);
    List<XXModuleDef> xXModuleDefs = xxModuleDefs();
    Mockito.when(xUserPermissionDao.findByUserPermissionId(vXPortalUser.getId())).thenReturn(xUserPermissionsList);
    Mockito.when(daoManager.getXXModuleDef()).thenReturn(xModuleDefDao);
    Mockito.when(xModuleDefDao.getAll()).thenReturn(xXModuleDefs);
    XXUser xXUser = xxUser(vxUser);
    XXUserDao xxUserDao = Mockito.mock(XXUserDao.class);
    Mockito.when(daoManager.getXXUser()).thenReturn(xxUserDao);
    Mockito.when(xxUserDao.findByPortalUserId(vXPortalUser.getId())).thenReturn(xXUser);
    VXGroupUserList vxGroupUserList = vxGroupUserList();
    Mockito.when(xGroupUserService.searchXGroupUsers((SearchCriteria) Mockito.any())).thenReturn(vxGroupUserList);
    UserSessionBase userSession = Mockito.mock(UserSessionBase.class);
    Set<UserSessionBase> userSessions = new HashSet<UserSessionBase>();
    userSessions.add(userSession);
    VXUserPermission vXUserPermission = vxUserPermission();
    Mockito.when(xUserPermissionService.createResource((VXUserPermission) Mockito.any())).thenReturn(vXUserPermission);
    Mockito.when(sessionMgr.getActiveUserSessionsForPortalUserId(userId)).thenReturn(userSessions);
    VXUser dbvxUser = xUserMgr.updateXUser(vxUser);
    Assert.assertNotNull(dbvxUser);
    Assert.assertEquals(dbvxUser.getId(), vxUser.getId());
    Assert.assertEquals(dbvxUser.getDescription(), vxUser.getDescription());
    Assert.assertEquals(dbvxUser.getName(), vxUser.getName());
    Mockito.verify(xUserService).updateResource(vxUser);
    groupIdList.clear();
    groupIdList.add(9L);
    vxUser.setGroupIdList(groupIdList);
    List<XXTrxLog> trxLogList = new ArrayList<XXTrxLog>();
    Mockito.when(xGroupUserService.getTransactionLog((VXGroupUser) Mockito.any(), Mockito.anyString())).thenReturn(trxLogList);
    VXGroup vXGroup = vxGroup();
    Mockito.when(xGroupService.readResource(Mockito.anyLong())).thenReturn(vXGroup);
    VXGroupUser vXGroupUser = vxGroupUser();
    Mockito.when(xGroupUserService.createResource((VXGroupUser) Mockito.any())).thenReturn(vXGroupUser);
    dbvxUser = xUserMgr.updateXUser(vxUser);
    Assert.assertNotNull(dbvxUser);
}
Also used : XXUser(org.apache.ranger.entity.XXUser) VXGroupUserList(org.apache.ranger.view.VXGroupUserList) XXUserDao(org.apache.ranger.db.XXUserDao) ArrayList(java.util.ArrayList) XXModuleDefDao(org.apache.ranger.db.XXModuleDefDao) VXString(org.apache.ranger.view.VXString) VXUserPermission(org.apache.ranger.view.VXUserPermission) UserSessionBase(org.apache.ranger.common.UserSessionBase) XXModuleDef(org.apache.ranger.entity.XXModuleDef) VXPortalUser(org.apache.ranger.view.VXPortalUser) HashSet(java.util.HashSet) XXUserPermissionDao(org.apache.ranger.db.XXUserPermissionDao) VXGroupUser(org.apache.ranger.view.VXGroupUser) XXTrxLog(org.apache.ranger.entity.XXTrxLog) VXUser(org.apache.ranger.view.VXUser) XXUserPermission(org.apache.ranger.entity.XXUserPermission) Date(java.util.Date) VXLong(org.apache.ranger.view.VXLong) VXGroup(org.apache.ranger.view.VXGroup) Test(org.junit.Test)

Example 37 with XXModuleDefDao

use of org.apache.ranger.db.XXModuleDefDao in project ranger by apache.

the class TestRoleBasedUserSearchUtil method TestValidateUserAndFetchUserList.

@Test
public void TestValidateUserAndFetchUserList() {
    List<String> permissionList = new ArrayList<String>();
    permissionList.add(RangerConstants.MODULE_USER_GROUPS);
    String currentEncryptedPassword = "testpassword";
    XXPortalUser xxPortalUser = new XXPortalUser();
    xxPortalUser.setId(1L);
    xxPortalUser.setLoginId("testUser");
    xxPortalUser.setPassword("testpassword");
    xxPortalUser.setFirstName("testUser");
    VXUser vxUser = new VXUser();
    vxUser.setId(1L);
    VXUserList vXUserList = new VXUserList();
    List<VXUser> vXUsers = new ArrayList<VXUser>();
    vXUsers.add(vxUser);
    vXUserList.setVXUsers(vXUsers);
    List<String> userRoleList = new ArrayList<String>();
    userRoleList.add("ROLE_SYS_ADMIN");
    List<XXPortalUser> listXXPortalUser = new ArrayList<XXPortalUser>();
    listXXPortalUser.add(xxPortalUser);
    vxUser.setUserRoleList(userRoleList);
    XXModuleDefDao xXModuleDefDao = Mockito.mock(XXModuleDefDao.class);
    Mockito.when(daoMgr.getXXPortalUser()).thenReturn(xXPortalUserDao);
    Mockito.when(xXPortalUserDao.findByLoginId(Mockito.anyString())).thenReturn(xxPortalUser);
    Mockito.when(xUserService.getXUserByUserName(xxPortalUser.getLoginId())).thenReturn(vxUser);
    Mockito.when(daoMgr.getXXModuleDef()).thenReturn(xXModuleDefDao);
    Mockito.when(xXModuleDefDao.findAccessibleModulesByUserId(Mockito.anyLong(), Mockito.anyLong())).thenReturn(permissionList);
    Mockito.when(userMgr.encrypt(Mockito.anyString(), Mockito.anyString())).thenReturn(currentEncryptedPassword);
    Mockito.when(xXPortalUserDao.findByRole(Mockito.anyString())).thenReturn(listXXPortalUser);
    roleBasedUserSearchUtil.validateUserAndFetchUserList();
    Mockito.verify(xXPortalUserDao).findByLoginId(Mockito.anyString());
    Mockito.verify(xUserService).getXUserByUserName(xxPortalUser.getLoginId());
    Mockito.verify(xXModuleDefDao).findAccessibleModulesByUserId(Mockito.anyLong(), Mockito.anyLong());
    Mockito.verify(userMgr).encrypt(Mockito.anyString(), Mockito.anyString());
    Mockito.verify(xXPortalUserDao, Mockito.atLeast(2)).findByRole(Mockito.anyString());
}
Also used : XXPortalUser(org.apache.ranger.entity.XXPortalUser) ArrayList(java.util.ArrayList) XXModuleDefDao(org.apache.ranger.db.XXModuleDefDao) VXUser(org.apache.ranger.view.VXUser) VXUserList(org.apache.ranger.view.VXUserList) Test(org.junit.Test)

Example 38 with XXModuleDefDao

use of org.apache.ranger.db.XXModuleDefDao in project ranger by apache.

the class TestUserMgr method test06ChangeEmailAddressAsAdmin.

@Test
public void test06ChangeEmailAddressAsAdmin() {
    setup();
    XXPortalUserDao userDao = Mockito.mock(XXPortalUserDao.class);
    XXPortalUserRoleDao roleDao = Mockito.mock(XXPortalUserRoleDao.class);
    XXUserPermissionDao xUserPermissionDao = Mockito.mock(XXUserPermissionDao.class);
    XXGroupPermissionDao xGroupPermissionDao = Mockito.mock(XXGroupPermissionDao.class);
    XXModuleDefDao xModuleDefDao = Mockito.mock(XXModuleDefDao.class);
    XXModuleDef xModuleDef = Mockito.mock(XXModuleDef.class);
    VXPortalUser userProfile = userProfile();
    XXPortalUser user = new XXPortalUser();
    user.setEmailAddress(userProfile.getEmailAddress());
    user.setFirstName(userProfile.getFirstName());
    user.setLastName(userProfile.getLastName());
    user.setLoginId(userProfile.getLoginId());
    String encryptedPwd = userMgr.encrypt(userProfile.getLoginId(), userProfile.getPassword());
    user.setPassword(encryptedPwd);
    user.setUserSource(userProfile.getUserSource());
    user.setPublicScreenName(userProfile.getPublicScreenName());
    user.setId(userProfile.getId());
    VXPasswordChange changeEmail = new VXPasswordChange();
    changeEmail.setEmailAddress("testuser@test.com");
    changeEmail.setId(user.getId());
    changeEmail.setLoginId(user.getLoginId());
    changeEmail.setOldPassword(userProfile.getPassword());
    XXPortalUserRole XXPortalUserRole = new XXPortalUserRole();
    XXPortalUserRole.setId(userId);
    XXPortalUserRole.setUserRole("ROLE_USER");
    List<XXPortalUserRole> list = new ArrayList<XXPortalUserRole>();
    list.add(XXPortalUserRole);
    List<XXUserPermission> xUserPermissionsList = new ArrayList<XXUserPermission>();
    XXUserPermission xUserPermissionObj = new XXUserPermission();
    xUserPermissionObj.setAddedByUserId(userId);
    xUserPermissionObj.setCreateTime(new Date());
    xUserPermissionObj.setId(userId);
    xUserPermissionObj.setIsAllowed(1);
    xUserPermissionObj.setModuleId(1L);
    xUserPermissionObj.setUpdatedByUserId(userId);
    xUserPermissionObj.setUpdateTime(new Date());
    xUserPermissionObj.setUserId(userId);
    xUserPermissionsList.add(xUserPermissionObj);
    List<XXGroupPermission> xGroupPermissionList = new ArrayList<XXGroupPermission>();
    XXGroupPermission xGroupPermissionObj = new XXGroupPermission();
    xGroupPermissionObj.setAddedByUserId(userId);
    xGroupPermissionObj.setCreateTime(new Date());
    xGroupPermissionObj.setId(userId);
    xGroupPermissionObj.setIsAllowed(1);
    xGroupPermissionObj.setModuleId(1L);
    xGroupPermissionObj.setUpdatedByUserId(userId);
    xGroupPermissionObj.setUpdateTime(new Date());
    xGroupPermissionObj.setGroupId(userId);
    xGroupPermissionList.add(xGroupPermissionObj);
    VXUserPermission userPermission = new VXUserPermission();
    userPermission.setId(1L);
    userPermission.setIsAllowed(1);
    userPermission.setModuleId(1L);
    userPermission.setUserId(userId);
    userPermission.setUserName("xyz");
    userPermission.setOwner("admin");
    VXGroupPermission groupPermission = new VXGroupPermission();
    groupPermission.setId(1L);
    groupPermission.setIsAllowed(1);
    groupPermission.setModuleId(1L);
    groupPermission.setGroupId(userId);
    groupPermission.setGroupName("xyz");
    groupPermission.setOwner("admin");
    Mockito.when(stringUtil.validateEmail(Mockito.anyString())).thenReturn(true);
    Mockito.when(stringUtil.equals(Mockito.anyString(), Mockito.anyString())).thenReturn(true);
    Mockito.when(stringUtil.normalizeEmail(Mockito.anyString())).thenReturn(changeEmail.getEmailAddress());
    Mockito.when(daoManager.getXXPortalUser()).thenReturn(userDao);
    Mockito.when(daoManager.getXXPortalUserRole()).thenReturn(roleDao);
    Mockito.when(userDao.update(user)).thenReturn(user);
    Mockito.when(roleDao.findByParentId(Mockito.anyLong())).thenReturn(list);
    Mockito.when(daoManager.getXXUserPermission()).thenReturn(xUserPermissionDao);
    Mockito.when(daoManager.getXXGroupPermission()).thenReturn(xGroupPermissionDao);
    Mockito.when(xUserPermissionDao.findByUserPermissionIdAndIsAllowed(userProfile.getId())).thenReturn(xUserPermissionsList);
    Mockito.when(xGroupPermissionDao.findbyVXPortalUserId(userProfile.getId())).thenReturn(xGroupPermissionList);
    Mockito.when(xGroupPermissionService.populateViewBean(xGroupPermissionObj)).thenReturn(groupPermission);
    Mockito.when(xUserPermissionService.populateViewBean(xUserPermissionObj)).thenReturn(userPermission);
    Mockito.when(daoManager.getXXModuleDef()).thenReturn(xModuleDefDao);
    Mockito.when(xModuleDefDao.findByModuleId(Mockito.anyLong())).thenReturn(xModuleDef);
    Mockito.doNothing().when(rangerBizUtil).blockAuditorRoleUser();
    VXPortalUser dbVXPortalUser = userMgr.changeEmailAddress(user, changeEmail);
    Assert.assertNotNull(dbVXPortalUser);
    Assert.assertEquals(userId, dbVXPortalUser.getId());
    Assert.assertEquals(userProfile.getLastName(), dbVXPortalUser.getLastName());
    Assert.assertEquals(changeEmail.getLoginId(), dbVXPortalUser.getLoginId());
    Assert.assertEquals(changeEmail.getEmailAddress(), dbVXPortalUser.getEmailAddress());
    user.setUserSource(RangerCommonEnums.USER_APP);
    dbVXPortalUser = userMgr.changeEmailAddress(user, changeEmail);
    user.setUserSource(RangerCommonEnums.USER_EXTERNAL);
    changeEmail.setEmailAddress("");
    dbVXPortalUser = userMgr.changeEmailAddress(user, changeEmail);
    Mockito.when(stringUtil.validateEmail(Mockito.anyString())).thenReturn(false);
    changeEmail.setEmailAddress("test@123.com");
    Mockito.when(restErrorUtil.createRESTException("serverMsg.userMgrInvalidEmail", MessageEnums.INVALID_INPUT_DATA, changeEmail.getId(), "emailAddress", changeEmail.toString())).thenThrow(new WebApplicationException());
    thrown.expect(WebApplicationException.class);
    userMgr.changeEmailAddress(user, changeEmail);
}
Also used : XXGroupPermission(org.apache.ranger.entity.XXGroupPermission) WebApplicationException(javax.ws.rs.WebApplicationException) VXPasswordChange(org.apache.ranger.view.VXPasswordChange) XXUserPermissionDao(org.apache.ranger.db.XXUserPermissionDao) XXGroupPermissionDao(org.apache.ranger.db.XXGroupPermissionDao) ArrayList(java.util.ArrayList) XXModuleDefDao(org.apache.ranger.db.XXModuleDefDao) VXString(org.apache.ranger.view.VXString) XXUserPermission(org.apache.ranger.entity.XXUserPermission) Date(java.util.Date) VXUserPermission(org.apache.ranger.view.VXUserPermission) XXPortalUserRoleDao(org.apache.ranger.db.XXPortalUserRoleDao) XXPortalUser(org.apache.ranger.entity.XXPortalUser) XXModuleDef(org.apache.ranger.entity.XXModuleDef) VXGroupPermission(org.apache.ranger.view.VXGroupPermission) XXPortalUserDao(org.apache.ranger.db.XXPortalUserDao) VXPortalUser(org.apache.ranger.view.VXPortalUser) XXPortalUserRole(org.apache.ranger.entity.XXPortalUserRole) Test(org.junit.Test)

Example 39 with XXModuleDefDao

use of org.apache.ranger.db.XXModuleDefDao in project ranger by apache.

the class TestUserMgr method test07ChangeEmailAddressAsKeyAdmin.

@Test
public void test07ChangeEmailAddressAsKeyAdmin() {
    setupKeyAdmin();
    XXPortalUserDao userDao = Mockito.mock(XXPortalUserDao.class);
    XXPortalUserRoleDao roleDao = Mockito.mock(XXPortalUserRoleDao.class);
    XXUserPermissionDao xUserPermissionDao = Mockito.mock(XXUserPermissionDao.class);
    XXGroupPermissionDao xGroupPermissionDao = Mockito.mock(XXGroupPermissionDao.class);
    XXModuleDefDao xModuleDefDao = Mockito.mock(XXModuleDefDao.class);
    XXModuleDef xModuleDef = Mockito.mock(XXModuleDef.class);
    VXPortalUser userProfile = userProfile();
    XXPortalUser userKeyAdmin = new XXPortalUser();
    userKeyAdmin.setEmailAddress(userProfile.getEmailAddress());
    userKeyAdmin.setFirstName(userProfile.getFirstName());
    userKeyAdmin.setLastName(userProfile.getLastName());
    userKeyAdmin.setLoginId(userProfile.getLoginId());
    String encryptedPwd = userMgr.encrypt(userProfile.getLoginId(), userProfile.getPassword());
    userKeyAdmin.setPassword(encryptedPwd);
    userKeyAdmin.setUserSource(userProfile.getUserSource());
    userKeyAdmin.setPublicScreenName(userProfile.getPublicScreenName());
    userKeyAdmin.setId(userProfile.getId());
    VXPasswordChange changeEmail = new VXPasswordChange();
    changeEmail.setEmailAddress("testuser@test.com");
    changeEmail.setId(userKeyAdmin.getId());
    changeEmail.setLoginId(userKeyAdmin.getLoginId());
    changeEmail.setOldPassword(userProfile.getPassword());
    XXPortalUserRole XXPortalUserRole = new XXPortalUserRole();
    XXPortalUserRole.setId(userId);
    XXPortalUserRole.setUserRole("ROLE_USER");
    List<XXPortalUserRole> list = new ArrayList<XXPortalUserRole>();
    list.add(XXPortalUserRole);
    List<XXUserPermission> xUserPermissionsList = new ArrayList<XXUserPermission>();
    XXUserPermission xUserPermissionObj = new XXUserPermission();
    xUserPermissionObj.setAddedByUserId(userId);
    xUserPermissionObj.setCreateTime(new Date());
    xUserPermissionObj.setId(userId);
    xUserPermissionObj.setIsAllowed(1);
    xUserPermissionObj.setModuleId(1L);
    xUserPermissionObj.setUpdatedByUserId(userId);
    xUserPermissionObj.setUpdateTime(new Date());
    xUserPermissionObj.setUserId(userId);
    xUserPermissionsList.add(xUserPermissionObj);
    List<XXGroupPermission> xGroupPermissionList = new ArrayList<XXGroupPermission>();
    XXGroupPermission xGroupPermissionObj = new XXGroupPermission();
    xGroupPermissionObj.setAddedByUserId(userId);
    xGroupPermissionObj.setCreateTime(new Date());
    xGroupPermissionObj.setId(userId);
    xGroupPermissionObj.setIsAllowed(1);
    xGroupPermissionObj.setModuleId(1L);
    xGroupPermissionObj.setUpdatedByUserId(userId);
    xGroupPermissionObj.setUpdateTime(new Date());
    xGroupPermissionObj.setGroupId(userId);
    xGroupPermissionList.add(xGroupPermissionObj);
    VXUserPermission userPermission = new VXUserPermission();
    userPermission.setId(1L);
    userPermission.setIsAllowed(1);
    userPermission.setModuleId(1L);
    userPermission.setUserId(userId);
    userPermission.setUserName("xyz");
    userPermission.setOwner("admin");
    VXGroupPermission groupPermission = new VXGroupPermission();
    groupPermission.setId(1L);
    groupPermission.setIsAllowed(1);
    groupPermission.setModuleId(1L);
    groupPermission.setGroupId(userId);
    groupPermission.setGroupName("xyz");
    groupPermission.setOwner("admin");
    Mockito.when(stringUtil.validateEmail(Mockito.anyString())).thenReturn(true);
    Mockito.when(stringUtil.equals(Mockito.anyString(), Mockito.anyString())).thenReturn(true);
    Mockito.when(stringUtil.normalizeEmail(Mockito.anyString())).thenReturn(changeEmail.getEmailAddress());
    Mockito.when(daoManager.getXXPortalUser()).thenReturn(userDao);
    Mockito.when(daoManager.getXXPortalUserRole()).thenReturn(roleDao);
    Mockito.when(roleDao.findByParentId(Mockito.anyLong())).thenReturn(list);
    Mockito.when(daoManager.getXXUserPermission()).thenReturn(xUserPermissionDao);
    Mockito.when(daoManager.getXXGroupPermission()).thenReturn(xGroupPermissionDao);
    Mockito.when(xUserPermissionDao.findByUserPermissionIdAndIsAllowed(userProfile.getId())).thenReturn(xUserPermissionsList);
    Mockito.when(xGroupPermissionDao.findbyVXPortalUserId(userProfile.getId())).thenReturn(xGroupPermissionList);
    Mockito.when(xGroupPermissionService.populateViewBean(xGroupPermissionObj)).thenReturn(groupPermission);
    Mockito.when(xUserPermissionService.populateViewBean(xUserPermissionObj)).thenReturn(userPermission);
    Mockito.when(daoManager.getXXModuleDef()).thenReturn(xModuleDefDao);
    Mockito.when(xModuleDefDao.findByModuleId(Mockito.anyLong())).thenReturn(xModuleDef);
    Mockito.doNothing().when(rangerBizUtil).blockAuditorRoleUser();
    VXPortalUser dbVXPortalUser = userMgr.changeEmailAddress(userKeyAdmin, changeEmail);
    Assert.assertNotNull(dbVXPortalUser);
    Assert.assertEquals(userId, dbVXPortalUser.getId());
    Assert.assertEquals(userProfile.getLastName(), dbVXPortalUser.getLastName());
    Assert.assertEquals(changeEmail.getLoginId(), dbVXPortalUser.getLoginId());
    Assert.assertEquals(changeEmail.getEmailAddress(), dbVXPortalUser.getEmailAddress());
}
Also used : XXGroupPermission(org.apache.ranger.entity.XXGroupPermission) VXPasswordChange(org.apache.ranger.view.VXPasswordChange) XXUserPermissionDao(org.apache.ranger.db.XXUserPermissionDao) XXGroupPermissionDao(org.apache.ranger.db.XXGroupPermissionDao) ArrayList(java.util.ArrayList) XXModuleDefDao(org.apache.ranger.db.XXModuleDefDao) VXString(org.apache.ranger.view.VXString) XXUserPermission(org.apache.ranger.entity.XXUserPermission) Date(java.util.Date) VXUserPermission(org.apache.ranger.view.VXUserPermission) XXPortalUserRoleDao(org.apache.ranger.db.XXPortalUserRoleDao) XXPortalUser(org.apache.ranger.entity.XXPortalUser) XXModuleDef(org.apache.ranger.entity.XXModuleDef) VXGroupPermission(org.apache.ranger.view.VXGroupPermission) XXPortalUserDao(org.apache.ranger.db.XXPortalUserDao) VXPortalUser(org.apache.ranger.view.VXPortalUser) XXPortalUserRole(org.apache.ranger.entity.XXPortalUserRole) Test(org.junit.Test)

Example 40 with XXModuleDefDao

use of org.apache.ranger.db.XXModuleDefDao in project ranger by apache.

the class TestUserMgr method test08ChangeEmailAddressAsUser.

@Test
public void test08ChangeEmailAddressAsUser() {
    setupUser();
    XXPortalUserDao userDao = Mockito.mock(XXPortalUserDao.class);
    XXPortalUserRoleDao roleDao = Mockito.mock(XXPortalUserRoleDao.class);
    XXUserPermissionDao xUserPermissionDao = Mockito.mock(XXUserPermissionDao.class);
    XXGroupPermissionDao xGroupPermissionDao = Mockito.mock(XXGroupPermissionDao.class);
    XXModuleDefDao xModuleDefDao = Mockito.mock(XXModuleDefDao.class);
    XXModuleDef xModuleDef = Mockito.mock(XXModuleDef.class);
    VXPortalUser userProfile = userProfile();
    XXPortalUser user = new XXPortalUser();
    user.setEmailAddress(userProfile.getEmailAddress());
    user.setFirstName(userProfile.getFirstName());
    user.setLastName(userProfile.getLastName());
    user.setLoginId(userProfile.getLoginId());
    String encryptedPwd = userMgr.encrypt(userProfile.getLoginId(), userProfile.getPassword());
    user.setPassword(encryptedPwd);
    user.setUserSource(userProfile.getUserSource());
    user.setPublicScreenName(userProfile.getPublicScreenName());
    user.setId(userProfile.getId());
    VXPasswordChange changeEmail = new VXPasswordChange();
    changeEmail.setEmailAddress("testuser@test.com");
    changeEmail.setId(user.getId());
    changeEmail.setLoginId(user.getLoginId());
    changeEmail.setOldPassword(userProfile.getPassword());
    XXPortalUserRole XXPortalUserRole = new XXPortalUserRole();
    XXPortalUserRole.setId(userId);
    XXPortalUserRole.setUserRole("ROLE_USER");
    List<XXPortalUserRole> list = new ArrayList<XXPortalUserRole>();
    list.add(XXPortalUserRole);
    List<XXUserPermission> xUserPermissionsList = new ArrayList<XXUserPermission>();
    XXUserPermission xUserPermissionObj = new XXUserPermission();
    xUserPermissionObj.setAddedByUserId(userId);
    xUserPermissionObj.setCreateTime(new Date());
    xUserPermissionObj.setId(userId);
    xUserPermissionObj.setIsAllowed(1);
    xUserPermissionObj.setModuleId(1L);
    xUserPermissionObj.setUpdatedByUserId(userId);
    xUserPermissionObj.setUpdateTime(new Date());
    xUserPermissionObj.setUserId(userId);
    xUserPermissionsList.add(xUserPermissionObj);
    List<XXGroupPermission> xGroupPermissionList = new ArrayList<XXGroupPermission>();
    XXGroupPermission xGroupPermissionObj = new XXGroupPermission();
    xGroupPermissionObj.setAddedByUserId(userId);
    xGroupPermissionObj.setCreateTime(new Date());
    xGroupPermissionObj.setId(userId);
    xGroupPermissionObj.setIsAllowed(1);
    xGroupPermissionObj.setModuleId(1L);
    xGroupPermissionObj.setUpdatedByUserId(userId);
    xGroupPermissionObj.setUpdateTime(new Date());
    xGroupPermissionObj.setGroupId(userId);
    xGroupPermissionList.add(xGroupPermissionObj);
    VXUserPermission userPermission = new VXUserPermission();
    userPermission.setId(1L);
    userPermission.setIsAllowed(1);
    userPermission.setModuleId(1L);
    userPermission.setUserId(userId);
    userPermission.setUserName("xyz");
    userPermission.setOwner("admin");
    VXGroupPermission groupPermission = new VXGroupPermission();
    groupPermission.setId(1L);
    groupPermission.setIsAllowed(1);
    groupPermission.setModuleId(1L);
    groupPermission.setGroupId(userId);
    groupPermission.setGroupName("xyz");
    groupPermission.setOwner("admin");
    Mockito.when(stringUtil.validateEmail(Mockito.anyString())).thenReturn(true);
    Mockito.when(stringUtil.equals(Mockito.anyString(), Mockito.anyString())).thenReturn(true);
    Mockito.when(stringUtil.normalizeEmail(Mockito.anyString())).thenReturn(changeEmail.getEmailAddress());
    Mockito.when(daoManager.getXXPortalUser()).thenReturn(userDao);
    Mockito.when(daoManager.getXXPortalUserRole()).thenReturn(roleDao);
    Mockito.when(roleDao.findByParentId(Mockito.anyLong())).thenReturn(list);
    Mockito.when(daoManager.getXXUserPermission()).thenReturn(xUserPermissionDao);
    Mockito.when(daoManager.getXXGroupPermission()).thenReturn(xGroupPermissionDao);
    Mockito.when(xUserPermissionDao.findByUserPermissionIdAndIsAllowed(userProfile.getId())).thenReturn(xUserPermissionsList);
    Mockito.when(xGroupPermissionDao.findbyVXPortalUserId(userProfile.getId())).thenReturn(xGroupPermissionList);
    Mockito.when(xGroupPermissionService.populateViewBean(xGroupPermissionObj)).thenReturn(groupPermission);
    Mockito.when(xUserPermissionService.populateViewBean(xUserPermissionObj)).thenReturn(userPermission);
    Mockito.when(daoManager.getXXModuleDef()).thenReturn(xModuleDefDao);
    Mockito.when(xModuleDefDao.findByModuleId(Mockito.anyLong())).thenReturn(xModuleDef);
    Mockito.doNothing().when(rangerBizUtil).blockAuditorRoleUser();
    VXPortalUser dbVXPortalUser = userMgr.changeEmailAddress(user, changeEmail);
    Assert.assertNotNull(dbVXPortalUser);
    Assert.assertEquals(userId, dbVXPortalUser.getId());
    Assert.assertEquals(userProfile.getLastName(), dbVXPortalUser.getLastName());
    Assert.assertEquals(changeEmail.getLoginId(), dbVXPortalUser.getLoginId());
    Assert.assertEquals(changeEmail.getEmailAddress(), dbVXPortalUser.getEmailAddress());
    user.setId(userProfile.getId());
    user.setLoginId("usertest123");
    String encryptCred = userMgr.encrypt(user.getLoginId(), userProfile.getPassword());
    user.setPassword(encryptCred);
    Mockito.when(stringUtil.equals(Mockito.anyString(), Mockito.nullable(String.class))).thenReturn(true);
    Mockito.when(stringUtil.equals(Mockito.anyString(), Mockito.anyString())).thenReturn(false);
    Mockito.when(restErrorUtil.createRESTException("serverMsg.userMgrWrongPassword", MessageEnums.OPER_NO_PERMISSION, null, null, changeEmail.toString())).thenThrow(new WebApplicationException());
    thrown.expect(WebApplicationException.class);
    userMgr.changeEmailAddress(user, changeEmail);
}
Also used : XXGroupPermission(org.apache.ranger.entity.XXGroupPermission) WebApplicationException(javax.ws.rs.WebApplicationException) VXPasswordChange(org.apache.ranger.view.VXPasswordChange) XXUserPermissionDao(org.apache.ranger.db.XXUserPermissionDao) XXGroupPermissionDao(org.apache.ranger.db.XXGroupPermissionDao) ArrayList(java.util.ArrayList) XXModuleDefDao(org.apache.ranger.db.XXModuleDefDao) VXString(org.apache.ranger.view.VXString) XXUserPermission(org.apache.ranger.entity.XXUserPermission) Date(java.util.Date) VXUserPermission(org.apache.ranger.view.VXUserPermission) XXPortalUserRoleDao(org.apache.ranger.db.XXPortalUserRoleDao) XXPortalUser(org.apache.ranger.entity.XXPortalUser) XXModuleDef(org.apache.ranger.entity.XXModuleDef) VXGroupPermission(org.apache.ranger.view.VXGroupPermission) XXPortalUserDao(org.apache.ranger.db.XXPortalUserDao) VXPortalUser(org.apache.ranger.view.VXPortalUser) XXPortalUserRole(org.apache.ranger.entity.XXPortalUserRole) Test(org.junit.Test)

Aggregations

XXModuleDefDao (org.apache.ranger.db.XXModuleDefDao)42 Test (org.junit.Test)42 ArrayList (java.util.ArrayList)37 VXString (org.apache.ranger.view.VXString)33 XXUserPermission (org.apache.ranger.entity.XXUserPermission)27 XXModuleDef (org.apache.ranger.entity.XXModuleDef)26 VXPortalUser (org.apache.ranger.view.VXPortalUser)26 VXUser (org.apache.ranger.view.VXUser)26 VXUserPermission (org.apache.ranger.view.VXUserPermission)22 XXUserPermissionDao (org.apache.ranger.db.XXUserPermissionDao)21 XXPortalUser (org.apache.ranger.entity.XXPortalUser)20 XXGroupPermission (org.apache.ranger.entity.XXGroupPermission)18 VXGroupPermission (org.apache.ranger.view.VXGroupPermission)18 XXPortalUserRoleDao (org.apache.ranger.db.XXPortalUserRoleDao)16 XXPortalUserDao (org.apache.ranger.db.XXPortalUserDao)15 XXPortalUserRole (org.apache.ranger.entity.XXPortalUserRole)15 Date (java.util.Date)14 UserSessionBase (org.apache.ranger.common.UserSessionBase)14 HashSet (java.util.HashSet)12 XXGroupPermissionDao (org.apache.ranger.db.XXGroupPermissionDao)12