use of org.apache.ranger.entity.XXPortalUser in project ranger by apache.
the class TestUserMgr method setupKeyAdmin.
public void setupKeyAdmin() {
RangerSecurityContext context = new RangerSecurityContext();
context.setUserSession(new UserSessionBase());
RangerContextHolder.setSecurityContext(context);
UserSessionBase currentUserSession = ContextUtil.getCurrentUserSession();
XXPortalUser userKeyAdmin = new XXPortalUser();
userKeyAdmin.setId(userProfile().getId());
userKeyAdmin.setLoginId(userProfile().getLoginId());
currentUserSession.setXXPortalUser(userKeyAdmin);
currentUserSession.setKeyAdmin(true);
}
use of org.apache.ranger.entity.XXPortalUser in project ranger by apache.
the class TestUserMgr method test36UpdateUser.
@Test
public void test36UpdateUser() {
setup();
XXPortalUserDao userDao = Mockito.mock(XXPortalUserDao.class);
VXPortalUser userProfile = userProfile();
XXPortalUser user = new XXPortalUser();
user.setId(userProfile.getId());
user.setLoginId(userProfile.getLoginId());
userProfile.setFirstName("User");
userProfile.setLastName("User");
Mockito.when(stringUtil.validateEmail(Mockito.anyString())).thenReturn(true);
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.doNothing().when(rangerBizUtil).blockAuditorRoleUser();
Mockito.when(stringUtil.toCamelCaseAllWords(Mockito.anyString())).thenReturn(userProfile.getFirstName());
XXPortalUser dbXXPortalUser = userMgr.updateUser(userProfile);
Assert.assertNotNull(dbXXPortalUser);
Mockito.when(stringUtil.isEmpty(Mockito.anyString())).thenReturn(true);
userProfile.setFirstName("null");
userProfile.setLastName("null");
userProfile.setEmailAddress("");
dbXXPortalUser = userMgr.updateUser(userProfile);
}
use of org.apache.ranger.entity.XXPortalUser in project ranger by apache.
the class TestUserMgr method test25updatePasswordInSHA256.
@Test
public void test25updatePasswordInSHA256() {
XXPortalUserDao userDao = Mockito.mock(XXPortalUserDao.class);
VXPortalUser userProfile = userProfile();
String userName = userProfile.getFirstName();
String userPassword = userProfile.getPassword();
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(RangerCommonEnums.USER_APP);
user.setPublicScreenName(userProfile.getPublicScreenName());
user.setId(userProfile.getId());
Mockito.when(daoManager.getXXPortalUser()).thenReturn(userDao);
Mockito.when(daoManager.getXXPortalUser()).thenReturn(userDao);
Mockito.when(userDao.update(user)).thenReturn(user);
XXPortalUser dbXXPortalUser = userMgr.updatePasswordInSHA256(null, userPassword, false);
Assert.assertNull(dbXXPortalUser);
Mockito.when(userDao.findByLoginId(Mockito.anyString())).thenReturn(null);
dbXXPortalUser = userMgr.updatePasswordInSHA256(userName, userPassword, false);
Assert.assertNull(dbXXPortalUser);
Mockito.when(userDao.findByLoginId(Mockito.anyString())).thenReturn(user);
dbXXPortalUser = userMgr.updatePasswordInSHA256(userName, userPassword, true);
Assert.assertNotNull(dbXXPortalUser);
dbXXPortalUser = userMgr.updatePasswordInSHA256(userName, "Secret", true);
Assert.assertNotNull(dbXXPortalUser);
}
use of org.apache.ranger.entity.XXPortalUser in project ranger by apache.
the class TestUserMgr method test49CreateDefaultAccountUser.
@Test
public void test49CreateDefaultAccountUser() {
destroySession();
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 user = new XXPortalUser();
user.setEmailAddress(userProfile.getEmailAddress());
user.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(null, user);
Mockito.when(userDao.findByEmailAddress(Mockito.anyString())).thenReturn(null);
Mockito.when(daoManager.getXXPortalUserRole()).thenReturn(roleDao);
Mockito.when(userDao.create((XXPortalUser) Mockito.any())).thenReturn(user);
Mockito.doNothing().when(rangerBizUtil).blockAuditorRoleUser();
userProfile.setEmailAddress(null);
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();
Mockito.when(userDao.findByLoginId(Mockito.anyString())).thenReturn(null);
Mockito.when(userDao.findByEmailAddress(Mockito.anyString())).thenReturn(user);
Mockito.when(restErrorUtil.createRESTException("The email address " + user.getEmailAddress() + " you've provided already exists. Please try again with different email address.", MessageEnums.OPER_NOT_ALLOWED_FOR_STATE)).thenThrow(new WebApplicationException());
thrown.expect(WebApplicationException.class);
userProfile.setEmailAddress(user.getEmailAddress());
userMgr.createDefaultAccountUser(userProfile);
}
use of org.apache.ranger.entity.XXPortalUser in project ranger by apache.
the class TestUserMgr method test20checkAccess.
@Test
public void test20checkAccess() {
setup();
XXPortalUserDao xPortalUserDao = Mockito.mock(XXPortalUserDao.class);
XXPortalUser xPortalUser = Mockito.mock(XXPortalUser.class);
Mockito.when(daoManager.getXXPortalUser()).thenReturn(xPortalUserDao);
Mockito.when(xPortalUserDao.getById(userId)).thenReturn(xPortalUser);
userMgr.checkAccess(userId);
Mockito.when(xPortalUserDao.getById(userId)).thenReturn(null);
Mockito.when(restErrorUtil.create403RESTException("serverMsg.userMgrWrongUser: " + userId)).thenThrow(new WebApplicationException());
thrown.expect(WebApplicationException.class);
userMgr.checkAccess(userId);
}
Aggregations