Search in sources :

Example 46 with VXPortalUser

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);
}
Also used : XXPortalUser(org.apache.ranger.entity.XXPortalUser) WebApplicationException(javax.ws.rs.WebApplicationException) VXPasswordChange(org.apache.ranger.view.VXPasswordChange) XXPortalUserDao(org.apache.ranger.db.XXPortalUserDao) VXPortalUser(org.apache.ranger.view.VXPortalUser) VXString(org.apache.ranger.view.VXString) Test(org.junit.Test)

Example 47 with VXPortalUser

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);
}
Also used : XXPortalUser(org.apache.ranger.entity.XXPortalUser) XXPortalUserDao(org.apache.ranger.db.XXPortalUserDao) VXPortalUser(org.apache.ranger.view.VXPortalUser) VXString(org.apache.ranger.view.VXString) Test(org.junit.Test)

Example 48 with VXPortalUser

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);
}
Also used : XXPortalUser(org.apache.ranger.entity.XXPortalUser) WebApplicationException(javax.ws.rs.WebApplicationException) VXPasswordChange(org.apache.ranger.view.VXPasswordChange) VXPortalUser(org.apache.ranger.view.VXPortalUser) XXPortalUserDao(org.apache.ranger.db.XXPortalUserDao) Test(org.junit.Test)

Example 49 with VXPortalUser

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);
}
Also used : XXRoleRefUser(org.apache.ranger.entity.XXRoleRefUser) XXUser(org.apache.ranger.entity.XXUser) VXGroupUserList(org.apache.ranger.view.VXGroupUserList) VXPermMap(org.apache.ranger.view.VXPermMap) XXUserDao(org.apache.ranger.db.XXUserDao) ArrayList(java.util.ArrayList) XXSecurityZoneRefUser(org.apache.ranger.entity.XXSecurityZoneRefUser) XXPolicy(org.apache.ranger.entity.XXPolicy) XXAuthSessionDao(org.apache.ranger.db.XXAuthSessionDao) XXPortalUserRoleDao(org.apache.ranger.db.XXPortalUserRoleDao) VXPortalUser(org.apache.ranger.view.VXPortalUser) VXAuditMap(org.apache.ranger.view.VXAuditMap) XXPortalUserRole(org.apache.ranger.entity.XXPortalUserRole) VXPermMapList(org.apache.ranger.view.VXPermMapList) XXRoleRefUserDao(org.apache.ranger.db.XXRoleRefUserDao) XXUserPermissionDao(org.apache.ranger.db.XXUserPermissionDao) VXAuditMapList(org.apache.ranger.view.VXAuditMapList) VXUser(org.apache.ranger.view.VXUser) XXAuthSession(org.apache.ranger.entity.XXAuthSession) XXUserPermission(org.apache.ranger.entity.XXUserPermission) XXPortalUser(org.apache.ranger.entity.XXPortalUser) XXSecurityZoneRefUserDao(org.apache.ranger.db.XXSecurityZoneRefUserDao) XXPortalUserDao(org.apache.ranger.db.XXPortalUserDao) XXPolicyDao(org.apache.ranger.db.XXPolicyDao) Test(org.junit.Test)

Example 50 with VXPortalUser

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;
}
Also used : VXPortalUser(org.apache.ranger.view.VXPortalUser)

Aggregations

VXPortalUser (org.apache.ranger.view.VXPortalUser)129 Test (org.junit.Test)110 XXPortalUser (org.apache.ranger.entity.XXPortalUser)86 VXString (org.apache.ranger.view.VXString)80 ArrayList (java.util.ArrayList)74 XXPortalUserDao (org.apache.ranger.db.XXPortalUserDao)61 XXPortalUserRole (org.apache.ranger.entity.XXPortalUserRole)49 XXPortalUserRoleDao (org.apache.ranger.db.XXPortalUserRoleDao)47 XXUserPermission (org.apache.ranger.entity.XXUserPermission)47 VXUser (org.apache.ranger.view.VXUser)33 Date (java.util.Date)29 WebApplicationException (javax.ws.rs.WebApplicationException)29 XXUserPermissionDao (org.apache.ranger.db.XXUserPermissionDao)29 XXModuleDef (org.apache.ranger.entity.XXModuleDef)28 XXModuleDefDao (org.apache.ranger.db.XXModuleDefDao)26 XXGroupPermission (org.apache.ranger.entity.XXGroupPermission)26 VXUserPermission (org.apache.ranger.view.VXUserPermission)24 VXGroupPermission (org.apache.ranger.view.VXGroupPermission)21 XXUserDao (org.apache.ranger.db.XXUserDao)20 XXUser (org.apache.ranger.entity.XXUser)19