use of org.apache.ranger.entity.XXPortalUser in project ranger by apache.
the class TestUserMgr method test11CreateUser.
@Test
public void test11CreateUser() {
setup();
XXPortalUserDao userDao = Mockito.mock(XXPortalUserDao.class);
XXPortalUserRoleDao roleDao = Mockito.mock(XXPortalUserRoleDao.class);
VXPortalUser userProfile = userProfile();
Collection<String> userRoleList = new ArrayList<String>();
userRoleList.add("ROLE_USER");
XXPortalUser user = new XXPortalUser();
user.setEmailAddress(userProfile.getEmailAddress());
user.setFirstName(userProfile.getFirstName());
user.setLastName(userProfile.getLastName());
user.setLoginId(userProfile.getLoginId());
user.setPassword(userProfile.getPassword());
user.setUserSource(userProfile.getUserSource());
user.setPublicScreenName(userProfile.getPublicScreenName());
user.setId(userProfile.getId());
XXPortalUserRole XXPortalUserRole = new XXPortalUserRole();
XXPortalUserRole.setId(user.getId());
XXPortalUserRole.setUserRole("ROLE_USER");
List<XXPortalUserRole> list = new ArrayList<XXPortalUserRole>();
list.add(XXPortalUserRole);
Mockito.when(daoManager.getXXPortalUser()).thenReturn(userDao);
Mockito.when(userDao.create((XXPortalUser) Mockito.any())).thenReturn(user);
Mockito.when(daoManager.getXXPortalUserRole()).thenReturn(roleDao);
Mockito.when(roleDao.findByUserId(userId)).thenReturn(list);
Mockito.doNothing().when(rangerBizUtil).blockAuditorRoleUser();
XXPortalUser dbxxPortalUser = userMgr.createUser(userProfile, 1, userRoleList);
Assert.assertNotNull(dbxxPortalUser);
userId = dbxxPortalUser.getId();
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(userProfile.getPassword(), dbxxPortalUser.getPassword());
Mockito.verify(daoManager).getXXPortalUser();
Mockito.verify(daoManager).getXXPortalUserRole();
}
use of org.apache.ranger.entity.XXPortalUser 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.entity.XXPortalUser in project ranger by apache.
the class TestUserMgr method test24UpdateUserWithPass.
@Test
public void test24UpdateUserWithPass() {
setup();
XXPortalUserDao userDao = Mockito.mock(XXPortalUserDao.class);
VXPortalUser userProfile = userProfile();
XXPortalUser user = new XXPortalUser();
Mockito.when(daoManager.getXXPortalUser()).thenReturn(userDao);
Mockito.when(userDao.getById(userProfile.getId())).thenReturn(user);
Mockito.when(restErrorUtil.createRESTException("Please provide valid email address.", MessageEnums.INVALID_INPUT_DATA)).thenThrow(new WebApplicationException());
thrown.expect(WebApplicationException.class);
Mockito.doNothing().when(rangerBizUtil).blockAuditorRoleUser();
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(userProfile.getPassword(), dbXXPortalUser.getPassword());
Mockito.verify(restErrorUtil).createRESTException("Please provide valid email address.", MessageEnums.INVALID_INPUT_DATA);
}
use of org.apache.ranger.entity.XXPortalUser in project ranger by apache.
the class TestUserMgr method test31getUserProfile.
@Test
public void test31getUserProfile() {
setup();
XXPortalUserDao xPortalUserDao = Mockito.mock(XXPortalUserDao.class);
XXPortalUser xPortalUser = Mockito.mock(XXPortalUser.class);
XXUserPermissionDao xUserPermissionDao = Mockito.mock(XXUserPermissionDao.class);
XXGroupPermissionDao xGroupPermissionDao = Mockito.mock(XXGroupPermissionDao.class);
XXPortalUserRoleDao xPortalUserRoleDao = Mockito.mock(XXPortalUserRoleDao.class);
List<XXPortalUserRole> xPortalUserRoleList = new ArrayList<XXPortalUserRole>();
XXPortalUserRole XXPortalUserRole = new XXPortalUserRole();
XXPortalUserRole.setId(userId);
XXPortalUserRole.setUserRole("ROLE_USER");
xPortalUserRoleList.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(xPortalUserDao);
Mockito.when(xPortalUserDao.getById(userId)).thenReturn(xPortalUser);
Mockito.when(daoManager.getXXPortalUserRole()).thenReturn(xPortalUserRoleDao);
Mockito.when(daoManager.getXXUserPermission()).thenReturn(xUserPermissionDao);
Mockito.when(daoManager.getXXGroupPermission()).thenReturn(xGroupPermissionDao);
VXPortalUser dbVXPortalUser = userMgr.getUserProfile(userId);
Assert.assertNotNull(dbVXPortalUser);
Mockito.verify(daoManager).getXXPortalUser();
Mockito.verify(daoManager).getXXUserPermission();
Mockito.verify(daoManager).getXXUserPermission();
Mockito.verify(daoManager).getXXGroupPermission();
}
use of org.apache.ranger.entity.XXPortalUser in project ranger by apache.
the class TestUserMgr method setupUser.
public void setupUser() {
RangerSecurityContext context = new RangerSecurityContext();
context.setUserSession(new UserSessionBase());
RangerContextHolder.setSecurityContext(context);
UserSessionBase currentUserSession = ContextUtil.getCurrentUserSession();
XXPortalUser user = new XXPortalUser();
user.setId(userProfile().getId());
user.setLoginId(userProfile().getLoginId());
currentUserSession.setXXPortalUser(user);
}
Aggregations