use of org.apache.ranger.view.VXPortalUser in project ranger by apache.
the class TestUserMgr method test48ChangePasswordAsUser.
@Test
public void test48ChangePasswordAsUser() {
destroySession();
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());
String encryptCred = userMgr.encrypt(userProfile.getLoginId(), userProfile.getPassword());
user.setPassword(encryptCred);
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(false);
Mockito.when(restErrorUtil.createRESTException("serverMsg.userMgrNewPassword", MessageEnums.INVALID_PASSWORD, null, null, pwdChange.getLoginId())).thenThrow(new WebApplicationException());
thrown.expect(WebApplicationException.class);
userMgr.changePassword(pwdChange);
}
use of org.apache.ranger.view.VXPortalUser in project ranger by apache.
the class TestUserMgr method test14UpdateUserWithPass.
@Test
public void test14UpdateUserWithPass() {
setup();
XXPortalUserDao userDao = Mockito.mock(XXPortalUserDao.class);
VXPortalUser userProfile = userProfile();
userProfile.setPassword("password1234");
XXPortalUser user = new XXPortalUser();
user.setId(userProfile.getId());
user.setLoginId(userProfile.getLoginId());
user.setEmailAddress(userProfile.getEmailAddress());
user.setLoginId(userProfile.getLoginId());
String encryptedPwd = userMgr.encrypt(userProfile.getLoginId(), userProfile.getPassword());
user.setPassword(encryptedPwd);
Mockito.when(daoManager.getXXPortalUser()).thenReturn(userDao);
Mockito.when(userDao.getById(userProfile.getId())).thenReturn(user);
Mockito.when(stringUtil.validateEmail(Mockito.anyString())).thenReturn(true);
Mockito.doNothing().when(rangerBizUtil).blockAuditorRoleUser();
Mockito.when(stringUtil.validatePassword(Mockito.anyString(), Mockito.any(String[].class))).thenReturn(true);
Mockito.when(userDao.update(user)).thenReturn(user);
XXPortalUser dbXXPortalUser = userMgr.updateUserWithPass(userProfile);
Assert.assertNotNull(dbXXPortalUser);
Assert.assertEquals(userId, dbXXPortalUser.getId());
Assert.assertEquals(userProfile.getFirstName(), dbXXPortalUser.getFirstName());
Assert.assertEquals(userProfile.getFirstName(), dbXXPortalUser.getFirstName());
Assert.assertEquals(userProfile.getLastName(), dbXXPortalUser.getLastName());
Assert.assertEquals(userProfile.getLoginId(), dbXXPortalUser.getLoginId());
Assert.assertEquals(userProfile.getEmailAddress(), dbXXPortalUser.getEmailAddress());
Assert.assertEquals(encryptedPwd, dbXXPortalUser.getPassword());
Mockito.when(userDao.getById(userProfile.getId())).thenReturn(null);
dbXXPortalUser = userMgr.updateUserWithPass(userProfile);
Assert.assertNull(dbXXPortalUser);
}
use of org.apache.ranger.view.VXPortalUser in project ranger by apache.
the class TestUserMgr method test46ChangePassword.
@Test
public void test46ChangePassword() {
destroySession();
setupUser();
VXPortalUser userProfile = userProfile();
XXPortalUser user2 = new XXPortalUser();
user2.setId(userId);
VXPasswordChange invalidpwdChange = new VXPasswordChange();
invalidpwdChange.setId(userProfile.getId());
invalidpwdChange.setLoginId(userProfile.getLoginId() + 1);
invalidpwdChange.setOldPassword("invalidOldPassword");
invalidpwdChange.setEmailAddress(userProfile.getEmailAddress());
invalidpwdChange.setUpdPassword(userProfile.getPassword());
XXPortalUserDao userDao = Mockito.mock(XXPortalUserDao.class);
Mockito.when(daoManager.getXXPortalUser()).thenReturn(userDao);
Mockito.when(userDao.findByLoginId(userProfile.getLoginId())).thenReturn(user2);
Mockito.when(userDao.findByLoginId(invalidpwdChange.getLoginId())).thenReturn(null);
Mockito.when(restErrorUtil.createRESTException("serverMsg.userMgrInvalidUser", MessageEnums.DATA_NOT_FOUND, null, null, invalidpwdChange.getLoginId())).thenThrow(new WebApplicationException());
thrown.expect(WebApplicationException.class);
userMgr.changePassword(invalidpwdChange);
}
use of org.apache.ranger.view.VXPortalUser in project ranger by apache.
the class TestXUserMgr method test94DeleteXUser.
@Test
public void test94DeleteXUser() {
setup();
boolean force = false;
VXUser vXUser = vxUser();
XXUser xXUser = new XXUser();
XXUserDao xXUserDao = Mockito.mock(XXUserDao.class);
Mockito.when(daoManager.getXXUser()).thenReturn(xXUserDao);
Mockito.when(xXUserDao.getById(vXUser.getId())).thenReturn(xXUser);
Mockito.when(xUserService.populateViewBean(xXUser)).thenReturn(vXUser);
VXGroupUserList vxGroupUserList = new VXGroupUserList();
Mockito.when(xGroupUserService.searchXGroupUsers((SearchCriteria) Mockito.any())).thenReturn(vxGroupUserList);
VXAuditMapList vXAuditMapList = new VXAuditMapList();
Mockito.when(xAuditMapService.searchXAuditMaps((SearchCriteria) Mockito.any())).thenReturn(vXAuditMapList);
VXPortalUser vXPortalUser = userProfile();
XXPortalUser xXPortalUser = xxPortalUser(vXPortalUser);
XXPortalUserDao xXPortalUserDao = Mockito.mock(XXPortalUserDao.class);
Mockito.when(daoManager.getXXPortalUser()).thenReturn(xXPortalUserDao);
Mockito.when(xXPortalUserDao.findByLoginId(vXUser.getName().trim())).thenReturn(xXPortalUser);
Mockito.when(xPortalUserService.populateViewBean(xXPortalUser)).thenReturn(vXPortalUser);
XXPortalUserRole XXPortalUserRole = new XXPortalUserRole();
XXPortalUserRole.setId(userId);
XXPortalUserRole.setUserId(userId);
XXPortalUserRole.setUserRole("ROLE_USER");
XXAuthSessionDao xXAuthSessionDao = Mockito.mock(XXAuthSessionDao.class);
XXUserPermissionDao xXUserPermissionDao = Mockito.mock(XXUserPermissionDao.class);
XXPortalUserRoleDao xXPortalUserRoleDao = Mockito.mock(XXPortalUserRoleDao.class);
Mockito.when(daoManager.getXXAuthSession()).thenReturn(xXAuthSessionDao);
Mockito.when(daoManager.getXXUserPermission()).thenReturn(xXUserPermissionDao);
Mockito.when(daoManager.getXXPortalUserRole()).thenReturn(xXPortalUserRoleDao);
List<XXAuthSession> xXAuthSessions = new ArrayList<XXAuthSession>();
XXAuthSession xXAuthSession = new XXAuthSession();
xXAuthSession.setId(userId);
xXAuthSession.setLoginId(vXPortalUser.getLoginId());
List<XXUserPermission> xXUserPermissions = new ArrayList<XXUserPermission>();
List<XXPortalUserRole> xXPortalUserRoles = new ArrayList<XXPortalUserRole>();
Mockito.when(xXAuthSessionDao.getAuthSessionByUserId(vXPortalUser.getId())).thenReturn(xXAuthSessions);
Mockito.when(xXUserPermissionDao.findByUserPermissionId(vXPortalUser.getId())).thenReturn(xXUserPermissions);
Mockito.when(xXPortalUserRoleDao.findByUserId(vXPortalUser.getId())).thenReturn(xXPortalUserRoles);
XXPolicyDao xXPolicyDao = Mockito.mock(XXPolicyDao.class);
List<XXPolicy> xXPolicyList = new ArrayList<XXPolicy>();
Mockito.when(daoManager.getXXPolicy()).thenReturn(xXPolicyDao);
Mockito.when(xXPolicyDao.findByUserId(vXUser.getId())).thenReturn(xXPolicyList);
List<XXSecurityZoneRefUser> zoneSecRefUser = new ArrayList<XXSecurityZoneRefUser>();
XXSecurityZoneRefUserDao zoneSecRefUserDao = Mockito.mock(XXSecurityZoneRefUserDao.class);
Mockito.when(daoManager.getXXSecurityZoneRefUser()).thenReturn(zoneSecRefUserDao);
Mockito.when(zoneSecRefUserDao.findByUserId(userId)).thenReturn(zoneSecRefUser);
List<XXRoleRefUser> roleRefUser = new ArrayList<XXRoleRefUser>();
XXRoleRefUserDao roleRefUserDao = Mockito.mock(XXRoleRefUserDao.class);
Mockito.when(daoManager.getXXRoleRefUser()).thenReturn(roleRefUserDao);
Mockito.when(roleRefUserDao.findByUserId(userId)).thenReturn(roleRefUser);
xUserMgr.deleteXUser(vXUser.getId(), force);
Mockito.when(xGroupUserService.searchXGroupUsers((SearchCriteria) Mockito.any())).thenReturn(new VXGroupUserList());
XXPolicy xXPolicy = getXXPolicy();
xXPolicyList.add(xXPolicy);
Mockito.when(xXPolicyDao.findByUserId(userId)).thenReturn(xXPolicyList);
xUserMgr.deleteXUser(vXUser.getId(), force);
Mockito.when(xXPolicyDao.findByUserId(userId)).thenReturn(new ArrayList<XXPolicy>());
VXPermMapList vXPermMapList = new VXPermMapList();
VXPermMap vXPermMap1 = getVXPermMap();
List<VXPermMap> vXPermMaps = new ArrayList<VXPermMap>();
vXPermMaps.add(vXPermMap1);
vXPermMapList.setVXPermMaps(vXPermMaps);
Mockito.when(xPermMapService.searchXPermMaps((SearchCriteria) Mockito.any())).thenReturn(vXPermMapList);
xUserMgr.deleteXUser(vXUser.getId(), force);
Mockito.when(xPermMapService.searchXPermMaps((SearchCriteria) Mockito.any())).thenReturn(new VXPermMapList());
List<VXAuditMap> vXAuditMaps = new ArrayList<VXAuditMap>();
VXAuditMap vXAuditMap = getVXAuditMap();
vXAuditMaps.add(vXAuditMap);
vXAuditMapList.setVXAuditMaps(vXAuditMaps);
Mockito.when(xAuditMapService.searchXAuditMaps((SearchCriteria) Mockito.any())).thenReturn(vXAuditMapList);
xUserMgr.deleteXUser(vXUser.getId(), force);
Mockito.when(xAuditMapService.searchXAuditMaps((SearchCriteria) Mockito.any())).thenReturn(new VXAuditMapList());
xXAuthSessions.add(xXAuthSession);
Mockito.when(xXAuthSessionDao.getAuthSessionByUserId(vXPortalUser.getId())).thenReturn(xXAuthSessions);
xUserMgr.deleteXUser(vXUser.getId(), force);
Mockito.when(xXAuthSessionDao.getAuthSessionByUserId(vXPortalUser.getId())).thenReturn(new ArrayList<XXAuthSession>());
XXUserPermission xUserPermissionObj = xxUserPermission();
xXUserPermissions.add(xUserPermissionObj);
Mockito.when(xXUserPermissionDao.findByUserPermissionId(vXPortalUser.getId())).thenReturn(xXUserPermissions);
xUserMgr.deleteXUser(vXUser.getId(), force);
Mockito.when(xXUserPermissionDao.findByUserPermissionId(vXPortalUser.getId())).thenReturn(new ArrayList<XXUserPermission>());
xXPortalUserRoles.add(XXPortalUserRole);
Mockito.when(xXPortalUserRoleDao.findByUserId(vXPortalUser.getId())).thenReturn(xXPortalUserRoles);
xUserMgr.deleteXUser(vXUser.getId(), force);
Mockito.when(xXPortalUserRoleDao.findByUserId(vXPortalUser.getId())).thenReturn(new ArrayList<XXPortalUserRole>());
xUserMgr.deleteXUser(vXUser.getId(), force);
vXUser.setName("");
Mockito.when(xXUserDao.getById(vXUser.getId())).thenReturn(xXUser);
Mockito.when(xUserService.populateViewBean(xXUser)).thenReturn(vXUser);
thrown.expect(NullPointerException.class);
xUserMgr.deleteXUser(vXUser.getId(), force);
}
use of org.apache.ranger.view.VXPortalUser in project ranger by apache.
the class TestXUserMgr method userProfile.
private VXPortalUser userProfile() {
VXPortalUser userProfile = new VXPortalUser();
userProfile.setEmailAddress("test@test.com");
userProfile.setFirstName("user12");
userProfile.setLastName("test12");
userProfile.setLoginId(userLoginID);
userProfile.setPassword("usertest123");
userProfile.setUserSource(1);
userProfile.setPublicScreenName("testuser");
userProfile.setId(userId);
return userProfile;
}
Aggregations