Search in sources :

Example 61 with VXPortalUser

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

the class TestXUserMgr method test45getUserRolesByName.

@Test
public void test45getUserRolesByName() {
    destroySession();
    setup();
    XXPortalUserRoleDao xPortalUserRoleDao = Mockito.mock(XXPortalUserRoleDao.class);
    VXPortalUser userProfile = userProfile();
    Collection<String> userRoleList = new ArrayList<String>();
    userRoleList.add("ROLE_USER");
    userProfile.setUserRoleList(userRoleList);
    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 = xxUserPermission();
    xUserPermissionsList.add(xUserPermissionObj);
    List<XXGroupPermission> xGroupPermissionList = new ArrayList<XXGroupPermission>();
    XXGroupPermission xGroupPermissionObj = xxGroupPermission();
    xGroupPermissionList.add(xGroupPermissionObj);
    List<VXGroupPermission> groupPermList = new ArrayList<VXGroupPermission>();
    VXGroupPermission groupPermission = vxGroupPermission();
    groupPermList.add(groupPermission);
    Mockito.when(daoManager.getXXPortalUserRole()).thenReturn(xPortalUserRoleDao);
    Mockito.when(xPortalUserRoleDao.findByUserId(userId)).thenReturn(xPortalUserRoleList);
    Mockito.when(userMgr.getUserProfileByLoginId(userProfile.getLoginId())).thenReturn(userProfile);
    VXStringList vXStringList = xUserMgr.getUserRolesByName(userProfile.getLoginId());
    Assert.assertNotNull(vXStringList);
    Mockito.when(restErrorUtil.createRESTException("Please provide a valid userName", MessageEnums.INVALID_INPUT_DATA)).thenThrow(new WebApplicationException());
    thrown.expect(WebApplicationException.class);
    xUserMgr.getUserRolesByName("");
}
Also used : XXGroupPermission(org.apache.ranger.entity.XXGroupPermission) VXStringList(org.apache.ranger.view.VXStringList) WebApplicationException(javax.ws.rs.WebApplicationException) ArrayList(java.util.ArrayList) VXString(org.apache.ranger.view.VXString) XXUserPermission(org.apache.ranger.entity.XXUserPermission) VXString(org.apache.ranger.view.VXString) XXPortalUserRoleDao(org.apache.ranger.db.XXPortalUserRoleDao) VXGroupPermission(org.apache.ranger.view.VXGroupPermission) VXPortalUser(org.apache.ranger.view.VXPortalUser) XXPortalUserRole(org.apache.ranger.entity.XXPortalUserRole) Test(org.junit.Test)

Example 62 with VXPortalUser

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

the class TestXUserMgr method test37setUserRolesByExternalID.

@Test
public void test37setUserRolesByExternalID() {
    setup();
    XXPortalUserRoleDao xPortalUserRoleDao = Mockito.mock(XXPortalUserRoleDao.class);
    VXUser vXUser = vxUser();
    VXPortalUser userProfile = userProfile();
    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 = xxUserPermission();
    xUserPermissionsList.add(xUserPermissionObj);
    List<XXGroupPermission> xGroupPermissionList = new ArrayList<XXGroupPermission>();
    XXGroupPermission xGroupPermissionObj = xxGroupPermission();
    xGroupPermissionList.add(xGroupPermissionObj);
    List<VXGroupPermission> groupPermList = new ArrayList<VXGroupPermission>();
    VXGroupPermission groupPermission = vxGroupPermission();
    groupPermList.add(groupPermission);
    Mockito.when(daoManager.getXXPortalUserRole()).thenReturn(xPortalUserRoleDao);
    Mockito.when(xPortalUserRoleDao.findByUserId(userId)).thenReturn(xPortalUserRoleList);
    Mockito.when(xUserMgr.getXUser(userId)).thenReturn(vXUser);
    Mockito.when(userMgr.getUserProfileByLoginId(vXUser.getName())).thenReturn(userProfile);
    List<String> permissionList = new ArrayList<String>();
    permissionList.add(RangerConstants.MODULE_USER_GROUPS);
    VXUser loggedInUser = vxUser();
    List<String> loggedInUserRole = new ArrayList<String>();
    loggedInUserRole.add(RangerConstants.ROLE_ADMIN);
    loggedInUser.setId(8L);
    loggedInUser.setName("testuser");
    loggedInUser.setUserRoleList(loggedInUserRole);
    Mockito.when(xUserService.getXUserByUserName("admin")).thenReturn(loggedInUser);
    XXModuleDefDao mockxxModuleDefDao = Mockito.mock(XXModuleDefDao.class);
    Mockito.when(daoManager.getXXModuleDef()).thenReturn(mockxxModuleDefDao);
    Mockito.when(mockxxModuleDefDao.findAccessibleModulesByUserId(8L, 8L)).thenReturn(permissionList);
    VXStringList vXStringList = xUserMgr.setUserRolesByExternalID(userId, vStringRolesList);
    Assert.assertNotNull(vXStringList);
}
Also used : XXGroupPermission(org.apache.ranger.entity.XXGroupPermission) VXStringList(org.apache.ranger.view.VXStringList) ArrayList(java.util.ArrayList) XXModuleDefDao(org.apache.ranger.db.XXModuleDefDao) VXString(org.apache.ranger.view.VXString) VXUser(org.apache.ranger.view.VXUser) XXUserPermission(org.apache.ranger.entity.XXUserPermission) VXString(org.apache.ranger.view.VXString) XXPortalUserRoleDao(org.apache.ranger.db.XXPortalUserRoleDao) VXGroupPermission(org.apache.ranger.view.VXGroupPermission) VXPortalUser(org.apache.ranger.view.VXPortalUser) XXPortalUserRole(org.apache.ranger.entity.XXPortalUserRole) Test(org.junit.Test)

Example 63 with VXPortalUser

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

the class TestXUserMgr method test43getUserRolesByExternalID.

@Test
public void test43getUserRolesByExternalID() {
    destroySession();
    setup();
    XXPortalUserRoleDao xPortalUserRoleDao = Mockito.mock(XXPortalUserRoleDao.class);
    VXUser vXUser = vxUser();
    VXPortalUser userProfile = userProfile();
    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 = xxUserPermission();
    xUserPermissionsList.add(xUserPermissionObj);
    List<XXGroupPermission> xGroupPermissionList = new ArrayList<XXGroupPermission>();
    XXGroupPermission xGroupPermissionObj = xxGroupPermission();
    xGroupPermissionList.add(xGroupPermissionObj);
    List<VXGroupPermission> groupPermList = new ArrayList<VXGroupPermission>();
    VXGroupPermission groupPermission = vxGroupPermission();
    groupPermList.add(groupPermission);
    Mockito.when(daoManager.getXXPortalUserRole()).thenReturn(xPortalUserRoleDao);
    Mockito.when(xPortalUserRoleDao.findByUserId(userId)).thenReturn(xPortalUserRoleList);
    Mockito.when(xUserMgr.getXUser(userId)).thenReturn(vXUser);
    Mockito.when(userMgr.getUserProfileByLoginId(vXUser.getName())).thenReturn(userProfile);
    List<String> permissionList = new ArrayList<String>();
    permissionList.add(RangerConstants.MODULE_USER_GROUPS);
    VXUser loggedInUser = vxUser();
    List<String> loggedInUserRole = new ArrayList<String>();
    loggedInUserRole.add(RangerConstants.ROLE_ADMIN);
    loggedInUser.setId(8L);
    loggedInUser.setName("testuser");
    loggedInUser.setUserRoleList(loggedInUserRole);
    Mockito.when(xUserService.getXUserByUserName("admin")).thenReturn(loggedInUser);
    XXModuleDefDao mockxxModuleDefDao = Mockito.mock(XXModuleDefDao.class);
    Mockito.when(daoManager.getXXModuleDef()).thenReturn(mockxxModuleDefDao);
    Mockito.when(mockxxModuleDefDao.findAccessibleModulesByUserId(8L, 8L)).thenReturn(permissionList);
    VXStringList vXStringList = xUserMgr.getUserRolesByExternalID(userId);
    Assert.assertNotNull(vXStringList);
    Mockito.when(restErrorUtil.createRESTException("User ID doesn't exist.", MessageEnums.INVALID_INPUT_DATA)).thenThrow(new WebApplicationException());
    thrown.expect(WebApplicationException.class);
    Mockito.when(userMgr.getUserProfileByLoginId((String) Mockito.anyString())).thenReturn(null);
    xUserMgr.getUserRolesByExternalID(userId);
}
Also used : XXGroupPermission(org.apache.ranger.entity.XXGroupPermission) VXStringList(org.apache.ranger.view.VXStringList) WebApplicationException(javax.ws.rs.WebApplicationException) ArrayList(java.util.ArrayList) XXModuleDefDao(org.apache.ranger.db.XXModuleDefDao) VXString(org.apache.ranger.view.VXString) VXUser(org.apache.ranger.view.VXUser) XXUserPermission(org.apache.ranger.entity.XXUserPermission) VXString(org.apache.ranger.view.VXString) XXPortalUserRoleDao(org.apache.ranger.db.XXPortalUserRoleDao) VXGroupPermission(org.apache.ranger.view.VXGroupPermission) VXPortalUser(org.apache.ranger.view.VXPortalUser) XXPortalUserRole(org.apache.ranger.entity.XXPortalUserRole) Test(org.junit.Test)

Example 64 with VXPortalUser

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

the class TestXUserMgr method test54modifyUserActiveStatus.

@Test
public void test54modifyUserActiveStatus() {
    setup();
    XXUserDao xxUserDao = Mockito.mock(XXUserDao.class);
    VXPortalUser userProfile = userProfile();
    VXUser vxUser = vxUser();
    XXUser xXUser = xxUser(vxUser);
    XXPortalUser xXPortalUser = xxPortalUser(userProfile);
    xXPortalUser.setUserSource(RangerCommonEnums.USER_EXTERNAL);
    Mockito.when(daoManager.getXXUser()).thenReturn(xxUserDao);
    Mockito.when(xxUserDao.getById(xXUser.getId())).thenReturn(xXUser);
    Mockito.when(userMgr.updateUser(userProfile)).thenReturn(xXPortalUser);
    HashMap<Long, Integer> statusMap = new HashMap<Long, Integer>();
    statusMap.put(xXUser.getId(), 1);
    Mockito.when(userMgr.getUserProfileByLoginId(vxUser.getName())).thenReturn(userProfile);
    xUserMgr.modifyUserActiveStatus(statusMap);
}
Also used : XXUser(org.apache.ranger.entity.XXUser) XXPortalUser(org.apache.ranger.entity.XXPortalUser) HashMap(java.util.HashMap) XXUserDao(org.apache.ranger.db.XXUserDao) VXLong(org.apache.ranger.view.VXLong) VXPortalUser(org.apache.ranger.view.VXPortalUser) VXUser(org.apache.ranger.view.VXUser) Test(org.junit.Test)

Example 65 with VXPortalUser

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

the class TestUserREST method test13GetUserProfile.

@Test
public void test13GetUserProfile() {
    HttpSession hs = Mockito.mock(HttpSession.class);
    VXPortalUser vxPUserExp = CreateVXPortalUser();
    Mockito.when(userManager.getUserProfileByLoginId()).thenReturn(vxPUserExp);
    Mockito.when(request.getSession()).thenReturn(hs);
    Mockito.when(hs.getId()).thenReturn("id");
    VXPortalUser vxPUserAct = userREST.getUserProfile(request);
    Assert.assertNotNull(vxPUserAct);
    Assert.assertEquals(vxPUserExp, vxPUserAct);
    Assert.assertEquals(vxPUserExp.getId(), vxPUserAct.getId());
    Assert.assertEquals(vxPUserExp.getFirstName(), vxPUserAct.getFirstName());
    Mockito.verify(userManager).getUserProfileByLoginId();
}
Also used : HttpSession(javax.servlet.http.HttpSession) VXPortalUser(org.apache.ranger.view.VXPortalUser) 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