Search in sources :

Example 6 with VXUser

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

the class TestXUserMgr method test45setUserRolesByExternalID.

@Test
public void test45setUserRolesByExternalID() {
    setup();
    XXPortalUserRoleDao xPortalUserRoleDao = Mockito.mock(XXPortalUserRoleDao.class);
    VXUser vXUser = vxUser();
    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(xPortalUserRoleDao.findByUserId(userId)).thenReturn(xPortalUserRoleList);
    Mockito.when(xUserMgr.getXUser(userId)).thenReturn(vXUser);
    Mockito.when(userMgr.getUserProfileByLoginId(vXUser.getName())).thenReturn(userProfile);
    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) VXUser(org.apache.ranger.view.VXUser) 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) VXPortalUser(org.apache.ranger.view.VXPortalUser) XXPortalUserRole(org.apache.ranger.entity.XXPortalUserRole) Test(org.junit.Test)

Example 7 with VXUser

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

the class TestXUserMgr method test47getUserRolesByExternalID.

@Test
public void test47getUserRolesByExternalID() {
    setup();
    XXPortalUserRoleDao xPortalUserRoleDao = Mockito.mock(XXPortalUserRoleDao.class);
    VXUser vXUser = vxUser();
    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(xPortalUserRoleDao.findByUserId(userId)).thenReturn(xPortalUserRoleList);
    Mockito.when(xUserMgr.getXUser(userId)).thenReturn(vXUser);
    Mockito.when(userMgr.getUserProfileByLoginId(vXUser.getName())).thenReturn(userProfile);
    VXStringList vXStringList = xUserMgr.getUserRolesByExternalID(userId);
    Assert.assertNotNull(vXStringList);
}
Also used : XXGroupPermission(org.apache.ranger.entity.XXGroupPermission) VXStringList(org.apache.ranger.view.VXStringList) ArrayList(java.util.ArrayList) VXUser(org.apache.ranger.view.VXUser) 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) VXPortalUser(org.apache.ranger.view.VXPortalUser) XXPortalUserRole(org.apache.ranger.entity.XXPortalUserRole) Test(org.junit.Test)

Example 8 with VXUser

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

the class TestXUserMgr method test13ModifyUserVisibilitySetOne.

@Test
public void test13ModifyUserVisibilitySetOne() {
    XXUserDao xxUserDao = Mockito.mock(XXUserDao.class);
    XXUser xxUser = Mockito.mock(XXUser.class);
    VXUser vxUser = vxUser();
    Mockito.when(xUserService.updateResource(vxUser)).thenReturn(vxUser);
    HashMap<Long, Integer> visibilityMap = new HashMap<Long, Integer>();
    Integer value = 1;
    visibilityMap.put(userId, value);
    Mockito.when(daoManager.getXXUser()).thenReturn(xxUserDao);
    Mockito.when(xxUserDao.getById(userId)).thenReturn(xxUser);
    Mockito.when(xUserService.populateViewBean(xxUser)).thenReturn(vxUser);
    xUserMgr.modifyUserVisibility(visibilityMap);
    Assert.assertEquals(value, vxUser.getIsVisible());
    Assert.assertEquals(userId, vxUser.getId());
    Mockito.verify(xUserService).updateResource(vxUser);
    Mockito.verify(daoManager).getXXUser();
    Mockito.verify(xUserService).populateViewBean(xxUser);
}
Also used : XXUser(org.apache.ranger.entity.XXUser) HashMap(java.util.HashMap) XXUserDao(org.apache.ranger.db.XXUserDao) VXUser(org.apache.ranger.view.VXUser) Test(org.junit.Test)

Example 9 with VXUser

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

the class TestXUserMgr method test11CreateXUser.

@Test
public void test11CreateXUser() {
    setup();
    VXUser vxUser = vxUser();
    Collection<String> userRoleList = new ArrayList<String>();
    userRoleList.add("test");
    vxUser.setUserRoleList(userRoleList);
    ArrayList<String> userRoleListVXPortaUser = new ArrayList<String>();
    VXPortalUser vXPortalUser = new VXPortalUser();
    vXPortalUser.setUserRoleList(userRoleListVXPortaUser);
    Mockito.when(xUserService.createResource(vxUser)).thenReturn(vxUser);
    XXModuleDefDao value = Mockito.mock(XXModuleDefDao.class);
    Mockito.when(daoManager.getXXModuleDef()).thenReturn(value);
    Mockito.when(userMgr.createDefaultAccountUser((VXPortalUser) Mockito.any())).thenReturn(vXPortalUser);
    VXUser dbUser = xUserMgr.createXUser(vxUser);
    Assert.assertNotNull(dbUser);
    userId = dbUser.getId();
    Assert.assertEquals(userId, dbUser.getId());
    Assert.assertEquals(dbUser.getDescription(), vxUser.getDescription());
    Assert.assertEquals(dbUser.getName(), vxUser.getName());
    Assert.assertEquals(dbUser.getUserRoleList(), vxUser.getUserRoleList());
    Assert.assertEquals(dbUser.getGroupNameList(), vxUser.getGroupNameList());
    Mockito.verify(xUserService).createResource(vxUser);
    Mockito.when(xUserService.readResourceWithOutLogin(userId)).thenReturn(vxUser);
    VXUser dbvxUser = xUserMgr.getXUser(userId);
    Mockito.verify(userMgr).createDefaultAccountUser((VXPortalUser) Mockito.any());
    Mockito.verify(daoManager).getXXModuleDef();
    Assert.assertNotNull(dbvxUser);
    Assert.assertEquals(userId, dbvxUser.getId());
    Assert.assertEquals(dbvxUser.getDescription(), vxUser.getDescription());
    Assert.assertEquals(dbvxUser.getName(), vxUser.getName());
    Assert.assertEquals(dbvxUser.getUserRoleList(), vxUser.getUserRoleList());
    Assert.assertEquals(dbvxUser.getGroupNameList(), vxUser.getGroupNameList());
    Mockito.verify(xUserService).readResourceWithOutLogin(userId);
}
Also used : ArrayList(java.util.ArrayList) VXPortalUser(org.apache.ranger.view.VXPortalUser) XXModuleDefDao(org.apache.ranger.db.XXModuleDefDao) VXString(org.apache.ranger.view.VXString) VXUser(org.apache.ranger.view.VXUser) Test(org.junit.Test)

Example 10 with VXUser

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

the class TestXUserREST method test14secureGetXUser.

@Test
public void test14secureGetXUser() {
    Mockito.when(xUserMgr.getXUser(id)).thenReturn(vxUser);
    VXUser gotVXUser = xUserRest.secureGetXUser(id);
    Mockito.verify(xUserMgr).getXUser(id);
    assertNotNull(gotVXUser);
    assertEquals(vxUser.getId(), gotVXUser.getId());
    assertEquals(vxUser.getName(), gotVXUser.getName());
}
Also used : VXUser(org.apache.ranger.view.VXUser) Test(org.junit.Test)

Aggregations

VXUser (org.apache.ranger.view.VXUser)42 Test (org.junit.Test)31 VXString (org.apache.ranger.view.VXString)21 ArrayList (java.util.ArrayList)13 HttpServletRequest (javax.servlet.http.HttpServletRequest)11 XXUser (org.apache.ranger.entity.XXUser)8 XXPortalUser (org.apache.ranger.entity.XXPortalUser)6 VXStringList (org.apache.ranger.view.VXStringList)6 VXPortalUser (org.apache.ranger.view.VXPortalUser)5 HashMap (java.util.HashMap)4 XXModuleDefDao (org.apache.ranger.db.XXModuleDefDao)4 XXPortalUserRoleDao (org.apache.ranger.db.XXPortalUserRoleDao)4 XXUserDao (org.apache.ranger.db.XXUserDao)4 VXUserList (org.apache.ranger.view.VXUserList)4 Date (java.util.Date)3 XXPortalUserRole (org.apache.ranger.entity.XXPortalUserRole)3 VXGroup (org.apache.ranger.view.VXGroup)3 JsonSyntaxException (com.google.gson.JsonSyntaxException)2 IOException (java.io.IOException)2 List (java.util.List)2