use of org.apache.ranger.view.VXPasswordChange in project ranger by apache.
the class TestUserMgr method test15ChangePasswordAsUser.
@Test
public void test15ChangePasswordAsUser() {
setupUser();
XXPortalUserDao userDao = Mockito.mock(XXPortalUserDao.class);
VXPortalUser userProfile = userProfile();
VXPasswordChange pwdChange = new VXPasswordChange();
pwdChange.setId(userProfile.getId());
pwdChange.setLoginId(userProfile.getLoginId());
pwdChange.setOldPassword(userProfile.getPassword());
pwdChange.setEmailAddress(userProfile.getEmailAddress());
pwdChange.setUpdPassword(userProfile.getPassword());
XXPortalUser user = new XXPortalUser();
user.setId(userProfile.getId());
user.setLoginId(userProfile.getLoginId());
Mockito.when(daoManager.getXXPortalUser()).thenReturn(userDao);
Mockito.when(userDao.findByLoginId(Mockito.anyString())).thenReturn(user);
Mockito.when(stringUtil.equals(Mockito.anyString(), Mockito.nullable(String.class))).thenReturn(true);
Mockito.when(daoManager.getXXPortalUser()).thenReturn(userDao);
Mockito.when(stringUtil.validatePassword(Mockito.anyString(), Mockito.any(String[].class))).thenReturn(true);
VXResponse dbVXResponse = userMgr.changePassword(pwdChange);
Assert.assertNotNull(dbVXResponse);
Assert.assertEquals(userProfile.getStatus(), dbVXResponse.getStatusCode());
Mockito.verify(stringUtil).equals(Mockito.anyString(), Mockito.nullable(String.class));
Mockito.verify(stringUtil).validatePassword(Mockito.anyString(), Mockito.any(String[].class));
}
use of org.apache.ranger.view.VXPasswordChange in project ranger by apache.
the class TestUserMgr method test14ChangePasswordAsKeyAdmin.
@Test
public void test14ChangePasswordAsKeyAdmin() {
setupKeyAdmin();
XXPortalUserDao userDao = Mockito.mock(XXPortalUserDao.class);
VXPortalUser userProfile = userProfile();
VXPasswordChange pwdChange = new VXPasswordChange();
pwdChange.setId(userProfile.getId());
pwdChange.setLoginId(userProfile.getLoginId());
pwdChange.setOldPassword(userProfile.getPassword());
pwdChange.setEmailAddress(userProfile.getEmailAddress());
pwdChange.setUpdPassword(userProfile.getPassword());
XXPortalUser userKeyAdmin = new XXPortalUser();
userKeyAdmin.setId(userProfile.getId());
userKeyAdmin.setLoginId(userProfile.getLoginId());
Mockito.when(daoManager.getXXPortalUser()).thenReturn(userDao);
Mockito.when(userDao.findByLoginId(Mockito.anyString())).thenReturn(userKeyAdmin);
Mockito.when(stringUtil.equals(Mockito.anyString(), Mockito.nullable(String.class))).thenReturn(true);
Mockito.when(daoManager.getXXPortalUser()).thenReturn(userDao);
Mockito.when(stringUtil.validatePassword(Mockito.anyString(), Mockito.any(String[].class))).thenReturn(true);
VXResponse dbVXResponse = userMgr.changePassword(pwdChange);
Assert.assertNotNull(dbVXResponse);
Assert.assertEquals(userProfile.getStatus(), dbVXResponse.getStatusCode());
Mockito.verify(stringUtil).equals(Mockito.anyString(), Mockito.nullable(String.class));
Mockito.verify(stringUtil).validatePassword(Mockito.anyString(), Mockito.any(String[].class));
}
use of org.apache.ranger.view.VXPasswordChange in project ranger by apache.
the class TestUserMgr method test18ChangeEmailAddressAsUser.
@Test
public void test18ChangeEmailAddressAsUser() {
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());
}
use of org.apache.ranger.view.VXPasswordChange in project ranger by apache.
the class TestUserMgr method test17ChangeEmailAddressAsKeyAdmin.
@Test
public void test17ChangeEmailAddressAsKeyAdmin() {
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());
}
use of org.apache.ranger.view.VXPasswordChange in project ranger by apache.
the class TestUserMgr method test16ChangeEmailAddressAsAdmin.
@Test
public void test16ChangeEmailAddressAsAdmin() {
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());
}
Aggregations