use of org.apache.ranger.entity.XXPortalUser 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.entity.XXPortalUser in project ranger by apache.
the class TestUserMgr method test21CreateUser.
@Test
public void test21CreateUser() {
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);
XXPortalUser user = new XXPortalUser();
VXPortalUser userProfile = userProfile();
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);
Mockito.when(daoManager.getXXPortalUser()).thenReturn(userDao);
Mockito.when(userDao.create((XXPortalUser) Mockito.any())).thenReturn(user);
Mockito.when(daoManager.getXXPortalUserRole()).thenReturn(roleDao);
Mockito.when(daoManager.getXXUserPermission()).thenReturn(xUserPermissionDao);
Mockito.when(daoManager.getXXGroupPermission()).thenReturn(xGroupPermissionDao);
Mockito.doNothing().when(rangerBizUtil).blockAuditorRoleUser();
VXPortalUser dbVXPortalUser = userMgr.createUser(userProfile);
Assert.assertNotNull(dbVXPortalUser);
Assert.assertEquals(user.getId(), dbVXPortalUser.getId());
Assert.assertEquals(user.getFirstName(), dbVXPortalUser.getFirstName());
Assert.assertEquals(user.getFirstName(), dbVXPortalUser.getFirstName());
Assert.assertEquals(user.getLastName(), dbVXPortalUser.getLastName());
Assert.assertEquals(user.getLoginId(), dbVXPortalUser.getLoginId());
Assert.assertEquals(user.getEmailAddress(), dbVXPortalUser.getEmailAddress());
Assert.assertEquals(user.getPassword(), dbVXPortalUser.getPassword());
Mockito.verify(daoManager).getXXPortalUser();
Mockito.verify(daoManager).getXXUserPermission();
Mockito.verify(daoManager).getXXGroupPermission();
}
use of org.apache.ranger.entity.XXPortalUser in project ranger by apache.
the class TestUserMgr method test22CreateDefaultAccountUser.
@Test
public void test22CreateDefaultAccountUser() {
setup();
XXPortalUserDao userDao = Mockito.mock(XXPortalUserDao.class);
XXPortalUserRoleDao roleDao = Mockito.mock(XXPortalUserRoleDao.class);
VXPortalUser userProfile = userProfile();
XXPortalUser user = new XXPortalUser();
XXPortalUserRole XXPortalUserRole = new XXPortalUserRole();
XXPortalUserRole.setId(userId);
XXPortalUserRole.setUserRole("ROLE_USER");
List<XXPortalUserRole> list = new ArrayList<XXPortalUserRole>();
list.add(XXPortalUserRole);
Mockito.when(daoManager.getXXPortalUser()).thenReturn(userDao);
Mockito.when(userDao.findByLoginId(Mockito.anyString())).thenReturn(user);
Mockito.when(daoManager.getXXPortalUserRole()).thenReturn(roleDao);
Mockito.doNothing().when(rangerBizUtil).blockAuditorRoleUser();
VXPortalUser dbVXPortalUser = userMgr.createDefaultAccountUser(userProfile);
Assert.assertNotNull(dbVXPortalUser);
Assert.assertEquals(user.getId(), dbVXPortalUser.getId());
Assert.assertEquals(user.getFirstName(), dbVXPortalUser.getFirstName());
Assert.assertEquals(user.getFirstName(), dbVXPortalUser.getFirstName());
Assert.assertEquals(user.getLastName(), dbVXPortalUser.getLastName());
Assert.assertEquals(user.getLoginId(), dbVXPortalUser.getLoginId());
Assert.assertEquals(user.getEmailAddress(), dbVXPortalUser.getEmailAddress());
Assert.assertEquals(user.getPassword(), dbVXPortalUser.getPassword());
Mockito.verify(daoManager, Mockito.atLeast(1)).getXXPortalUser();
Mockito.verify(daoManager, Mockito.atLeast(1)).getXXPortalUserRole();
}
use of org.apache.ranger.entity.XXPortalUser in project ranger by apache.
the class TestUserMgr method test28DeleteUserRole.
@Test
public void test28DeleteUserRole() {
setup();
XXPortalUserRoleDao roleDao = Mockito.mock(XXPortalUserRoleDao.class);
XXPortalUserRole XXPortalUserRole = new XXPortalUserRole();
String userRole = "ROLE_USER";
XXPortalUser user = new XXPortalUser();
XXPortalUserRole.setId(user.getId());
XXPortalUserRole.setUserRole("ROLE_USER");
List<XXPortalUserRole> list = new ArrayList<XXPortalUserRole>();
list.add(XXPortalUserRole);
Mockito.when(daoManager.getXXPortalUserRole()).thenReturn(roleDao);
Mockito.when(roleDao.findByUserId(userId)).thenReturn(list);
Mockito.doNothing().when(rangerBizUtil).blockAuditorRoleUser();
boolean deleteValue = userMgr.deleteUserRole(userId, userRole);
Assert.assertTrue(deleteValue);
}
use of org.apache.ranger.entity.XXPortalUser in project ranger by apache.
the class XAuditMapService method mapViewToEntityBean.
@Override
protected XXAuditMap mapViewToEntityBean(VXAuditMap vObj, XXAuditMap mObj, int OPERATION_CONTEXT) {
if (vObj != null && mObj != null) {
super.mapViewToEntityBean(vObj, mObj, OPERATION_CONTEXT);
XXPortalUser xXPortalUser = null;
if (mObj.getAddedByUserId() == null || mObj.getAddedByUserId() == 0) {
if (!stringUtil.isEmpty(vObj.getOwner())) {
xXPortalUser = daoManager.getXXPortalUser().findByLoginId(vObj.getOwner());
if (xXPortalUser != null) {
mObj.setAddedByUserId(xXPortalUser.getId());
}
}
}
if (mObj.getUpdatedByUserId() == null || mObj.getUpdatedByUserId() == 0) {
if (!stringUtil.isEmpty(vObj.getUpdatedBy())) {
xXPortalUser = daoManager.getXXPortalUser().findByLoginId(vObj.getUpdatedBy());
if (xXPortalUser != null) {
mObj.setUpdatedByUserId(xXPortalUser.getId());
}
}
}
}
return mObj;
}
Aggregations