Search in sources :

Example 6 with VXGroupUser

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

the class XGroupUserService method readResourceWithOutLogin.

public VXGroupUser readResourceWithOutLogin(Long id) {
    XXGroupUser resource = getDao().getById(id);
    if (resource == null) {
        // Returns code 400 with DATA_NOT_FOUND as the error message
        throw restErrorUtil.createRESTException(getResourceName() + " not found", MessageEnums.DATA_NOT_FOUND, id, null, "preRead: " + id + " not found.");
    }
    VXGroupUser view = populateViewBean(resource);
    return view;
}
Also used : XXGroupUser(org.apache.ranger.entity.XXGroupUser) VXGroupUser(org.apache.ranger.view.VXGroupUser)

Example 7 with VXGroupUser

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

the class XGroupUserServiceBase method searchXGroupUsers.

/**
 * @param searchCriteria
 * @return
 */
public VXGroupUserList searchXGroupUsers(SearchCriteria searchCriteria) {
    VXGroupUserList returnList = new VXGroupUserList();
    List<VXGroupUser> xGroupUserList = new ArrayList<VXGroupUser>();
    List<T> resultList = searchResources(searchCriteria, searchFields, sortFields, returnList);
    // Iterate over the result list and create the return list
    for (T gjXGroupUser : resultList) {
        VXGroupUser vXGroupUser = populateViewBean(gjXGroupUser);
        xGroupUserList.add(vXGroupUser);
    }
    returnList.setVXGroupUsers(xGroupUserList);
    return returnList;
}
Also used : VXGroupUserList(org.apache.ranger.view.VXGroupUserList) ArrayList(java.util.ArrayList) VXGroupUser(org.apache.ranger.view.VXGroupUser)

Example 8 with VXGroupUser

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

the class TestXUserREST method test30searchXGroupUsers.

@SuppressWarnings("unchecked")
@Test
public void test30searchXGroupUsers() {
    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
    SearchCriteria testSearchCriteria = createsearchCriteria();
    Mockito.when(searchUtil.extractCommonCriterias((HttpServletRequest) Mockito.any(), (List<SortField>) Mockito.any())).thenReturn(testSearchCriteria);
    VXGroupUserList testVXGroupUserList = new VXGroupUserList();
    VXGroupUser vXGroupUser = createVXGroupUser();
    List<VXGroupUser> vXGroupUsers = new ArrayList<VXGroupUser>();
    vXGroupUsers.add(vXGroupUser);
    testVXGroupUserList.setVXGroupUsers(vXGroupUsers);
    Mockito.when(xUserMgr.searchXGroupUsers(testSearchCriteria)).thenReturn(testVXGroupUserList);
    VXGroupUserList outputvXGroupList = xUserRest.searchXGroupUsers(request);
    Mockito.verify(xUserMgr).searchXGroupUsers(testSearchCriteria);
    Mockito.verify(searchUtil).extractCommonCriterias((HttpServletRequest) Mockito.any(), (List<SortField>) Mockito.any());
    assertNotNull(outputvXGroupList);
    assertEquals(outputvXGroupList.getClass(), testVXGroupUserList.getClass());
    assertEquals(outputvXGroupList.getResultSize(), testVXGroupUserList.getResultSize());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) VXGroupUserList(org.apache.ranger.view.VXGroupUserList) ArrayList(java.util.ArrayList) VXGroupUser(org.apache.ranger.view.VXGroupUser) SortField(org.apache.ranger.common.SortField) SearchCriteria(org.apache.ranger.common.SearchCriteria) Test(org.junit.Test)

Example 9 with VXGroupUser

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

the class TestXUserREST method test28updateXGroupUser.

@Test
public void test28updateXGroupUser() {
    VXGroupUser testVXGroupUser = createVXGroupUser();
    Mockito.when(xUserMgr.updateXGroupUser(testVXGroupUser)).thenReturn(testVXGroupUser);
    VXGroupUser retVxGroupUser = xUserRest.updateXGroupUser(testVXGroupUser);
    assertNotNull(retVxGroupUser);
    assertEquals(testVXGroupUser.getClass(), retVxGroupUser.getClass());
    assertEquals(testVXGroupUser.getId(), retVxGroupUser.getId());
    Mockito.verify(xUserMgr).updateXGroupUser(testVXGroupUser);
}
Also used : VXGroupUser(org.apache.ranger.view.VXGroupUser) Test(org.junit.Test)

Example 10 with VXGroupUser

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

the class TestXUserMgr method test30CreateVXUserGroupInfo.

@Test
public void test30CreateVXUserGroupInfo() {
    setup();
    VXUserGroupInfo vXUserGroupInfo = new VXUserGroupInfo();
    VXUser vXUser = new VXUser();
    vXUser.setName("user1");
    vXUser.setDescription("testuser1 -added for unit testing");
    vXUser.setPassword("usertest123");
    List<VXGroupUser> vXGroupUserList = new ArrayList<VXGroupUser>();
    List<VXGroup> vXGroupList = new ArrayList<VXGroup>();
    final VXGroup vXGroup1 = new VXGroup();
    vXGroup1.setName("users");
    vXGroup1.setDescription("users -added for unit testing");
    vXGroupList.add(vXGroup1);
    VXGroupUser vXGroupUser1 = new VXGroupUser();
    vXGroupUser1.setName("users");
    vXGroupUserList.add(vXGroupUser1);
    final VXGroup vXGroup2 = new VXGroup();
    vXGroup2.setName("user1");
    vXGroup2.setDescription("user1 -added for unit testing");
    vXGroupList.add(vXGroup2);
    VXGroupUser vXGroupUser2 = new VXGroupUser();
    vXGroupUser2.setName("user1");
    vXGroupUserList.add(vXGroupUser2);
    vXUserGroupInfo.setXuserInfo(vXUser);
    vXUserGroupInfo.setXgroupInfo(vXGroupList);
    Mockito.when(xUserService.createXUserWithOutLogin(vXUser)).thenReturn(vXUser);
    Mockito.when(xGroupService.createXGroupWithOutLogin(vXGroup1)).thenReturn(vXGroup1);
    Mockito.when(xGroupService.createXGroupWithOutLogin(vXGroup2)).thenReturn(vXGroup2);
    XXPortalUserDao portalUser = Mockito.mock(XXPortalUserDao.class);
    Mockito.when(daoManager.getXXPortalUser()).thenReturn(portalUser);
    XXPortalUser user = new XXPortalUser();
    user.setId(1L);
    user.setUserSource(RangerCommonEnums.USER_APP);
    Mockito.when(portalUser.findByLoginId(vXUser.getName())).thenReturn(user);
    XXPortalUserRoleDao userDao = Mockito.mock(XXPortalUserRoleDao.class);
    Mockito.when(daoManager.getXXPortalUserRole()).thenReturn(userDao);
    List<String> lstRole = new ArrayList<String>();
    lstRole.add(RangerConstants.ROLE_SYS_ADMIN);
    Mockito.when(userDao.findXPortalUserRolebyXPortalUserId(Mockito.anyLong())).thenReturn(lstRole);
    VXUserGroupInfo vxUserGroupTest = xUserMgr.createXUserGroupFromMap(vXUserGroupInfo);
    Assert.assertEquals("user1", vxUserGroupTest.getXuserInfo().getName());
    List<VXGroup> result = vxUserGroupTest.getXgroupInfo();
    List<VXGroup> expected = new ArrayList<VXGroup>();
    expected.add(vXGroup1);
    expected.add(vXGroup2);
    Assert.assertTrue(result.containsAll(expected));
    // Mockito.verify(daoManager).getXXPortalUser();
    Mockito.verify(portalUser).findByLoginId(vXUser.getName());
    // Mockito.verify(daoManager).getXXPortalUserRole();
    Mockito.verify(userDao).findXPortalUserRolebyXPortalUserId(Mockito.anyLong());
}
Also used : XXPortalUser(org.apache.ranger.entity.XXPortalUser) XXPortalUserRoleDao(org.apache.ranger.db.XXPortalUserRoleDao) VXUserGroupInfo(org.apache.ranger.view.VXUserGroupInfo) ArrayList(java.util.ArrayList) VXGroupUser(org.apache.ranger.view.VXGroupUser) XXPortalUserDao(org.apache.ranger.db.XXPortalUserDao) VXString(org.apache.ranger.view.VXString) VXUser(org.apache.ranger.view.VXUser) VXGroup(org.apache.ranger.view.VXGroup) Test(org.junit.Test)

Aggregations

VXGroupUser (org.apache.ranger.view.VXGroupUser)11 Test (org.junit.Test)8 ArrayList (java.util.ArrayList)5 VXGroupUserList (org.apache.ranger.view.VXGroupUserList)4 VXGroup (org.apache.ranger.view.VXGroup)3 XXAuditMapDao (org.apache.ranger.db.XXAuditMapDao)2 XXGroupUserDao (org.apache.ranger.db.XXGroupUserDao)2 XXPermMapDao (org.apache.ranger.db.XXPermMapDao)2 XXPolicyDao (org.apache.ranger.db.XXPolicyDao)2 XXPortalUserDao (org.apache.ranger.db.XXPortalUserDao)2 XXPortalUserRoleDao (org.apache.ranger.db.XXPortalUserRoleDao)2 XXPolicy (org.apache.ranger.entity.XXPolicy)2 XXPortalUser (org.apache.ranger.entity.XXPortalUser)2 VXAuditMapList (org.apache.ranger.view.VXAuditMapList)2 VXPermMapList (org.apache.ranger.view.VXPermMapList)2 VXUser (org.apache.ranger.view.VXUser)2 Date (java.util.Date)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 SearchCriteria (org.apache.ranger.common.SearchCriteria)1 SortField (org.apache.ranger.common.SortField)1