Search in sources :

Example 31 with VXPortalUser

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

Example 32 with VXPortalUser

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

Example 33 with VXPortalUser

use of org.apache.ranger.view.VXPortalUser in project ranger by apache.

the class TestUserMgr method test47ChangePasswordAsUser.

@Test
public void test47ChangePasswordAsUser() {
    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(true);
    Mockito.when(restErrorUtil.createRESTException("serverMsg.userMgrOldPassword", MessageEnums.INVALID_INPUT_DATA, user.getId(), "password", user.toString())).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 34 with VXPortalUser

use of org.apache.ranger.view.VXPortalUser in project ranger by apache.

the class TestUserMgr method test37createUserSearchQuery.

@Test
public void test37createUserSearchQuery() {
    EntityManager entityManager = Mockito.mock(EntityManager.class);
    String queryString = "Select id,loginId,emailAddress,firstName,lastName,statusList,publicScreenName,status from XXPortalUser";
    Query query = Mockito.mock(Query.class);
    SearchCriteria searchCriteria = new SearchCriteria();
    searchCriteria.setDistinct(true);
    searchCriteria.setGetChildren(true);
    searchCriteria.setGetCount(true);
    searchCriteria.setMaxRows(12);
    searchCriteria.setOwnerId(userId);
    searchCriteria.setStartIndex(1);
    searchCriteria.setSortBy("asc");
    VXPortalUser vXPortalUser = userProfile();
    List<String> userRoleList = new ArrayList<String>();
    userRoleList.add("ROLE_USER");
    List<Integer> statusList = new ArrayList<Integer>();
    statusList.add(1);
    searchCriteria.addParam("roleList", userRoleList);
    searchCriteria.addParam("userId", vXPortalUser.getId());
    searchCriteria.addParam("loginId", vXPortalUser.getLoginId());
    searchCriteria.addParam("emailAddress", vXPortalUser.getEmailAddress());
    searchCriteria.addParam("firstName", vXPortalUser.getFirstName());
    searchCriteria.addParam("lastName", vXPortalUser.getLastName());
    searchCriteria.addParam("statusList", statusList);
    searchCriteria.addParam("publicScreenName", vXPortalUser.getPublicScreenName());
    searchCriteria.addParam("status", vXPortalUser.getStatus());
    searchCriteria.addParam("familyScreenName", vXPortalUser.getPublicScreenName());
    Mockito.when(daoManager.getEntityManager()).thenReturn(entityManager);
    Mockito.when(entityManager.createQuery(Mockito.anyString())).thenReturn(query);
    Query newQuery = userMgr.createUserSearchQuery(query.toString(), queryString, searchCriteria);
    Assert.assertNotNull(newQuery);
    userRoleList.add("ROLE_SYS_ADMIN");
    statusList.add(0);
    searchCriteria.addParam("statusList", statusList);
    searchCriteria.addParam("roleList", userRoleList);
    newQuery = userMgr.createUserSearchQuery(query.toString(), queryString, searchCriteria);
}
Also used : EntityManager(javax.persistence.EntityManager) Query(javax.persistence.Query) ArrayList(java.util.ArrayList) VXPortalUser(org.apache.ranger.view.VXPortalUser) VXString(org.apache.ranger.view.VXString) SearchCriteria(org.apache.ranger.common.SearchCriteria) Test(org.junit.Test)

Example 35 with VXPortalUser

use of org.apache.ranger.view.VXPortalUser in project ranger by apache.

the class TestUserMgr method test23setUserRoles.

@Test
public void test23setUserRoles() {
    setup();
    XXPortalUserRoleDao xPortalUserRoleDao = Mockito.mock(XXPortalUserRoleDao.class);
    XXPortalUserDao userDao = Mockito.mock(XXPortalUserDao.class);
    XXUserPermissionDao xUserPermissionDao = Mockito.mock(XXUserPermissionDao.class);
    XXGroupPermissionDao xGroupPermissionDao = Mockito.mock(XXGroupPermissionDao.class);
    XXModuleDefDao xModuleDefDao = Mockito.mock(XXModuleDefDao.class);
    VXPortalUser userProfile = userProfile();
    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());
    List<VXString> vStringRolesList = new ArrayList<VXString>();
    VXString vXStringObj = new VXString();
    vXStringObj.setValue("ROLE_USER");
    vStringRolesList.add(vXStringObj);
    List<XXPortalUserRole> xPortalUserRoleList = new ArrayList<XXPortalUserRole>();
    XXPortalUserRole XXPortalUserRole = new XXPortalUserRole();
    XXPortalUserRole.setId(userId);
    XXPortalUserRole.setUserId(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);
    List<VXGroupPermission> groupPermList = new ArrayList<VXGroupPermission>();
    VXGroupPermission groupPermission = new VXGroupPermission();
    groupPermission.setId(1L);
    groupPermission.setIsAllowed(1);
    groupPermission.setModuleId(1L);
    groupPermission.setGroupId(userId);
    groupPermission.setGroupName("xyz");
    groupPermission.setOwner("admin");
    groupPermList.add(groupPermission);
    XXModuleDef xModuleDef = new XXModuleDef();
    xModuleDef.setUpdatedByUserId(userId);
    xModuleDef.setAddedByUserId(userId);
    xModuleDef.setCreateTime(new Date());
    xModuleDef.setId(userId);
    xModuleDef.setModule("Policy manager");
    xModuleDef.setUpdateTime(new Date());
    xModuleDef.setUrl("/policy manager");
    VXUserPermission userPermission = new VXUserPermission();
    userPermission.setId(1L);
    userPermission.setIsAllowed(1);
    userPermission.setModuleId(1L);
    userPermission.setUserId(userId);
    userPermission.setUserName("xyz");
    userPermission.setOwner("admin");
    Mockito.when(daoManager.getXXPortalUserRole()).thenReturn(xPortalUserRoleDao);
    Mockito.when(daoManager.getXXPortalUser()).thenReturn(userDao);
    Mockito.when(userDao.getById(userId)).thenReturn(user);
    Mockito.when(daoManager.getXXUserPermission()).thenReturn(xUserPermissionDao);
    Mockito.when(xUserPermissionDao.findByUserPermissionIdAndIsAllowed(userProfile.getId())).thenReturn(xUserPermissionsList);
    Mockito.when(daoManager.getXXGroupPermission()).thenReturn(xGroupPermissionDao);
    Mockito.when(xGroupPermissionDao.findbyVXPortalUserId(userProfile.getId())).thenReturn(xGroupPermissionList);
    Mockito.when(xGroupPermissionService.populateViewBean(xGroupPermissionObj)).thenReturn(groupPermission);
    Mockito.when(daoManager.getXXModuleDef()).thenReturn(xModuleDefDao);
    Mockito.when(xModuleDefDao.findByModuleId(Mockito.anyLong())).thenReturn(xModuleDef);
    Mockito.when(xUserPermissionService.populateViewBean(xUserPermissionObj)).thenReturn(userPermission);
    Mockito.when(daoManager.getXXModuleDef()).thenReturn(xModuleDefDao);
    Mockito.when(xModuleDefDao.findByModuleId(Mockito.anyLong())).thenReturn(xModuleDef);
    Mockito.doNothing().when(rangerBizUtil).blockAuditorRoleUser();
    userMgr.checkAccess(userId);
    userMgr.setUserRoles(userId, vStringRolesList);
    Mockito.verify(daoManager).getXXUserPermission();
    Mockito.verify(daoManager).getXXGroupPermission();
    Mockito.verify(xGroupPermissionService).populateViewBean(xGroupPermissionObj);
    Mockito.verify(xUserPermissionService).populateViewBean(xUserPermissionObj);
}
Also used : XXGroupPermission(org.apache.ranger.entity.XXGroupPermission) XXUserPermissionDao(org.apache.ranger.db.XXUserPermissionDao) XXGroupPermissionDao(org.apache.ranger.db.XXGroupPermissionDao) ArrayList(java.util.ArrayList) XXModuleDefDao(org.apache.ranger.db.XXModuleDefDao) XXUserPermission(org.apache.ranger.entity.XXUserPermission) Date(java.util.Date) VXUserPermission(org.apache.ranger.view.VXUserPermission) VXString(org.apache.ranger.view.VXString) XXPortalUserRoleDao(org.apache.ranger.db.XXPortalUserRoleDao) XXPortalUser(org.apache.ranger.entity.XXPortalUser) XXModuleDef(org.apache.ranger.entity.XXModuleDef) VXGroupPermission(org.apache.ranger.view.VXGroupPermission) XXPortalUserDao(org.apache.ranger.db.XXPortalUserDao) VXPortalUser(org.apache.ranger.view.VXPortalUser) XXPortalUserRole(org.apache.ranger.entity.XXPortalUserRole) Test(org.junit.Test)

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