use of org.apache.ranger.entity.XXPortalUser in project ranger by apache.
the class TestUserMgr method test51UpdateUserWithPass.
@Test
public void test51UpdateUserWithPass() {
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(false);
Mockito.when(restErrorUtil.createRESTException("serverMsg.userMgrNewPassword", MessageEnums.INVALID_PASSWORD, null, null, user.getId().toString())).thenThrow(new WebApplicationException());
thrown.expect(WebApplicationException.class);
userMgr.updateUserWithPass(userProfile);
}
use of org.apache.ranger.entity.XXPortalUser in project ranger by apache.
the class TestUserMgr method test26CreateUser.
@Test
public void test26CreateUser() {
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());
String encryptedPwd = userMgr.encrypt(userProfile.getLoginId(), userProfile.getPassword());
user.setPassword(encryptedPwd);
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.when(userDao.findByLoginId(Mockito.anyString())).thenReturn(user);
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(encryptedPwd, dbxxPortalUser.getPassword());
Mockito.verify(daoManager, Mockito.atLeast(1)).getXXPortalUser();
Mockito.verify(daoManager).getXXPortalUserRole();
}
use of org.apache.ranger.entity.XXPortalUser in project ranger by apache.
the class TestUserMgr method test10CreateDefaultAccountUser.
@Test
public void test10CreateDefaultAccountUser() {
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");
userProfile.setUserRoleList(userRoleList);
XXPortalUser user = new XXPortalUser();
user.setEmailAddress(userProfile.getEmailAddress());
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();
userProfile.setOtherAttributes("other1");
VXPortalUser dbVXPortalUser = userMgr.createDefaultAccountUser(userProfile);
Assert.assertNotNull(dbVXPortalUser);
Assert.assertEquals(user.getId(), dbVXPortalUser.getId());
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 test01CreateUser.
@Test
public void test01CreateUser() {
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();
Mockito.when(userDao.findByLoginId(Mockito.anyString())).thenReturn(user);
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, Mockito.atLeast(1)).getXXPortalUser();
Mockito.verify(daoManager).getXXPortalUserRole();
}
use of org.apache.ranger.entity.XXPortalUser in project ranger by apache.
the class TestUserMgr method test12CreateDefaultAccountUser.
@Test
public void test12CreateDefaultAccountUser() {
setup();
XXPortalUserDao userDao = Mockito.mock(XXPortalUserDao.class);
XXPortalUserRoleDao roleDao = Mockito.mock(XXPortalUserRoleDao.class);
VXPortalUser userProfile = userProfile();
userProfile.setStatus(RangerCommonEnums.USER_EXTERNAL);
Collection<String> userRoleList = new ArrayList<String>();
userRoleList.add("ROLE_USER");
userProfile.setUserRoleList(userRoleList);
XXPortalUser xxPortalUser = new XXPortalUser();
xxPortalUser.setEmailAddress(userProfile.getEmailAddress());
xxPortalUser.setUserSource(RangerCommonEnums.USER_EXTERNAL);
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(xxPortalUser);
Mockito.when(daoManager.getXXPortalUserRole()).thenReturn(roleDao);
Mockito.doNothing().when(rangerBizUtil).blockAuditorRoleUser();
userProfile.setPassword("");
userProfile.setEmailAddress(null);
VXPortalUser dbVXPortalUser = userMgr.createDefaultAccountUser(userProfile);
Assert.assertNotNull(dbVXPortalUser);
Assert.assertEquals(xxPortalUser.getId(), dbVXPortalUser.getId());
Assert.assertEquals(xxPortalUser.getFirstName(), dbVXPortalUser.getFirstName());
Assert.assertEquals(xxPortalUser.getLastName(), dbVXPortalUser.getLastName());
Assert.assertEquals(xxPortalUser.getLoginId(), dbVXPortalUser.getLoginId());
Assert.assertEquals(xxPortalUser.getEmailAddress(), dbVXPortalUser.getEmailAddress());
Assert.assertEquals(xxPortalUser.getPassword(), dbVXPortalUser.getPassword());
Mockito.verify(daoManager, Mockito.atLeast(1)).getXXPortalUser();
Mockito.verify(daoManager, Mockito.atLeast(1)).getXXPortalUserRole();
}
Aggregations