Search in sources :

Example 16 with VXGroupPermission

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

the class XGroupPermissionServiceBase method searchXGroupPermission.

/**
 * @param searchCriteria
 * @return
 */
public VXGroupPermissionList searchXGroupPermission(SearchCriteria searchCriteria) {
    VXGroupPermissionList returnList = new VXGroupPermissionList();
    List<VXGroupPermission> vXGroupPermissions = new ArrayList<VXGroupPermission>();
    List<T> resultList = searchResources(searchCriteria, searchFields, sortFields, returnList);
    // Iterate over the result list and create the return list
    for (T gjXUser : resultList) {
        VXGroupPermission vXGroupPermission = populateViewBean(gjXUser);
        vXGroupPermissions.add(vXGroupPermission);
    }
    returnList.setvXGroupPermission(vXGroupPermissions);
    return returnList;
}
Also used : VXGroupPermission(org.apache.ranger.view.VXGroupPermission) ArrayList(java.util.ArrayList) VXGroupPermissionList(org.apache.ranger.view.VXGroupPermissionList)

Example 17 with VXGroupPermission

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

the class XModuleDefService method populateViewBean.

@Override
public VXModuleDef populateViewBean(XXModuleDef xObj) {
    VXModuleDef vModuleDef = super.populateViewBean(xObj);
    Map<Long, XXUser> xXPortalUserIdXXUserMap = xUserService.getXXPortalUserIdXXUserMap();
    Map<Long, XXGroup> xXGroupMap = xGroupService.getXXGroupIdXXGroupMap();
    List<VXUserPermission> vXUserPermissionList = new ArrayList<VXUserPermission>();
    List<VXGroupPermission> vXGroupPermissionList = new ArrayList<VXGroupPermission>();
    List<XXUserPermission> xuserPermissionList = daoManager.getXXUserPermission().findByModuleId(xObj.getId(), false);
    List<XXGroupPermission> xgroupPermissionList = daoManager.getXXGroupPermission().findByModuleId(xObj.getId(), false);
    if (CollectionUtils.isEmpty(xXPortalUserIdXXUserMap)) {
        for (XXUserPermission xUserPerm : xuserPermissionList) {
            VXUserPermission vXUserPerm = xUserPermService.populateViewBean(xUserPerm);
            vXUserPermissionList.add(vXUserPerm);
        }
    } else {
        vXUserPermissionList = xUserPermService.getPopulatedVXUserPermissionList(xuserPermissionList, xXPortalUserIdXXUserMap, vModuleDef);
    }
    if (CollectionUtils.isEmpty(xXGroupMap)) {
        for (XXGroupPermission xGrpPerm : xgroupPermissionList) {
            VXGroupPermission vXGrpPerm = xGrpPermService.populateViewBean(xGrpPerm);
            vXGroupPermissionList.add(vXGrpPerm);
        }
    } else {
        vXGroupPermissionList = xGrpPermService.getPopulatedVXGroupPermissionList(xgroupPermissionList, xXGroupMap, vModuleDef);
    }
    vModuleDef.setUserPermList(vXUserPermissionList);
    vModuleDef.setGroupPermList(vXGroupPermissionList);
    return vModuleDef;
}
Also used : XXUser(org.apache.ranger.entity.XXUser) XXGroupPermission(org.apache.ranger.entity.XXGroupPermission) ArrayList(java.util.ArrayList) XXUserPermission(org.apache.ranger.entity.XXUserPermission) VXUserPermission(org.apache.ranger.view.VXUserPermission) XXGroup(org.apache.ranger.entity.XXGroup) VXGroupPermission(org.apache.ranger.view.VXGroupPermission) VXModuleDef(org.apache.ranger.view.VXModuleDef)

Example 18 with VXGroupPermission

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

the class UserMgr method gjUserToUserProfile.

private void gjUserToUserProfile(XXPortalUser user, VXPortalUser userProfile) {
    UserSessionBase sess = ContextUtil.getCurrentUserSession();
    if (sess == null) {
        return;
    }
    // Admin
    if (sess.isUserAdmin() || sess.isKeyAdmin() || sess.getXXPortalUser().getId().equals(user.getId())) {
        userProfile.setLoginId(user.getLoginId());
        userProfile.setStatus(user.getStatus());
        userProfile.setUserRoleList(new ArrayList<String>());
        String emailAddress = user.getEmailAddress();
        if (emailAddress != null && stringUtil.validateEmail(emailAddress)) {
            userProfile.setEmailAddress(user.getEmailAddress());
        }
        userProfile.setUserSource(sess.getAuthProvider());
        List<XXPortalUserRole> gjUserRoleList = daoManager.getXXPortalUserRole().findByParentId(user.getId());
        for (XXPortalUserRole gjUserRole : gjUserRoleList) {
            userProfile.getUserRoleList().add(gjUserRole.getUserRole());
        }
        userProfile.setId(user.getId());
        List<XXUserPermission> xUserPermissions = daoManager.getXXUserPermission().findByUserPermissionIdAndIsAllowed(userProfile.getId());
        List<XXGroupPermission> xxGroupPermissions = daoManager.getXXGroupPermission().findbyVXPortalUserId(userProfile.getId());
        List<VXGroupPermission> groupPermissions = new ArrayList<VXGroupPermission>();
        List<VXUserPermission> vxUserPermissions = new ArrayList<VXUserPermission>();
        for (XXGroupPermission xxGroupPermission : xxGroupPermissions) {
            VXGroupPermission groupPermission = xGroupPermissionService.populateViewBean(xxGroupPermission);
            groupPermission.setModuleName(daoManager.getXXModuleDef().findByModuleId(groupPermission.getModuleId()).getModule());
            groupPermissions.add(groupPermission);
        }
        for (XXUserPermission xUserPermission : xUserPermissions) {
            VXUserPermission vXUserPermission = xUserPermissionService.populateViewBean(xUserPermission);
            vXUserPermission.setModuleName(daoManager.getXXModuleDef().findByModuleId(vXUserPermission.getModuleId()).getModule());
            vxUserPermissions.add(vXUserPermission);
        }
        userProfile.setGroupPermissions(groupPermissions);
        userProfile.setUserPermList(vxUserPermissions);
        userProfile.setFirstName(user.getFirstName());
        userProfile.setLastName(user.getLastName());
        userProfile.setPublicScreenName(user.getPublicScreenName());
    }
}
Also used : XXGroupPermission(org.apache.ranger.entity.XXGroupPermission) ArrayList(java.util.ArrayList) VXString(org.apache.ranger.view.VXString) XXUserPermission(org.apache.ranger.entity.XXUserPermission) VXUserPermission(org.apache.ranger.view.VXUserPermission) UserSessionBase(org.apache.ranger.common.UserSessionBase) VXGroupPermission(org.apache.ranger.view.VXGroupPermission) XXPortalUserRole(org.apache.ranger.entity.XXPortalUserRole)

Example 19 with VXGroupPermission

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

the class XGroupPermissionService method populateViewBean.

@Override
public VXGroupPermission populateViewBean(XXGroupPermission xObj) {
    VXGroupPermission vObj = super.populateViewBean(xObj);
    XXGroup xGroup = daoManager.getXXGroup().getById(xObj.getGroupId());
    if (xGroup == null) {
        throw restErrorUtil.createRESTException(xGroup + " is Not Found", MessageEnums.DATA_NOT_FOUND);
    }
    vObj.setGroupName(xGroup.getName());
    return vObj;
}
Also used : XXGroup(org.apache.ranger.entity.XXGroup) VXGroupPermission(org.apache.ranger.view.VXGroupPermission)

Example 20 with VXGroupPermission

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

the class TestXUserREST method test92searchXGroupPermission.

@SuppressWarnings("unchecked")
@Test
public void test92searchXGroupPermission() {
    VXGroupPermissionList testVXGroupPermissionList = new VXGroupPermissionList();
    testVXGroupPermissionList.setTotalCount(1);
    VXGroupPermission testVXGroupPermission = createVXGroupPermission();
    List<VXGroupPermission> testVXGroupPermissions = new ArrayList<VXGroupPermission>();
    testVXGroupPermissions.add(testVXGroupPermission);
    testVXGroupPermissionList.setvXGroupPermission(testVXGroupPermissions);
    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
    SearchCriteria testSearchCriteria = createsearchCriteria();
    Mockito.when(searchUtil.extractCommonCriterias((HttpServletRequest) Mockito.any(), (List<SortField>) Mockito.any())).thenReturn(testSearchCriteria);
    Mockito.when(searchUtil.extractString(request, testSearchCriteria, "id", "id", StringUtil.VALIDATION_NAME)).thenReturn("");
    Mockito.when(searchUtil.extractString(request, testSearchCriteria, "groupPermissionList", "groupId", StringUtil.VALIDATION_NAME)).thenReturn("");
    Mockito.when(xUserMgr.searchXGroupPermission(testSearchCriteria)).thenReturn(testVXGroupPermissionList);
    VXGroupPermissionList outputVXGroupPermissionList = xUserRest.searchXGroupPermission(request);
    assertNotNull(outputVXGroupPermissionList);
    assertEquals(outputVXGroupPermissionList.getClass(), testVXGroupPermissionList.getClass());
    assertEquals(outputVXGroupPermissionList.getTotalCount(), testVXGroupPermissionList.getTotalCount());
    Mockito.verify(xUserMgr).searchXGroupPermission(testSearchCriteria);
    Mockito.verify(searchUtil).extractCommonCriterias((HttpServletRequest) Mockito.any(), (List<SortField>) Mockito.any());
    Mockito.verify(searchUtil).extractString(request, testSearchCriteria, "id", "id", StringUtil.VALIDATION_NAME);
    Mockito.verify(searchUtil).extractString(request, testSearchCriteria, "groupPermissionList", "groupId", StringUtil.VALIDATION_NAME);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) VXGroupPermission(org.apache.ranger.view.VXGroupPermission) ArrayList(java.util.ArrayList) SortField(org.apache.ranger.common.SortField) VXGroupPermissionList(org.apache.ranger.view.VXGroupPermissionList) SearchCriteria(org.apache.ranger.common.SearchCriteria) Test(org.junit.Test)

Aggregations

VXGroupPermission (org.apache.ranger.view.VXGroupPermission)26 Test (org.junit.Test)17 ArrayList (java.util.ArrayList)16 VXUserPermission (org.apache.ranger.view.VXUserPermission)14 Date (java.util.Date)12 XXGroupPermission (org.apache.ranger.entity.XXGroupPermission)12 XXUserPermission (org.apache.ranger.entity.XXUserPermission)11 XXModuleDef (org.apache.ranger.entity.XXModuleDef)10 XXPortalUserRole (org.apache.ranger.entity.XXPortalUserRole)10 XXPortalUserRoleDao (org.apache.ranger.db.XXPortalUserRoleDao)9 XXPortalUser (org.apache.ranger.entity.XXPortalUser)9 VXPortalUser (org.apache.ranger.view.VXPortalUser)9 VXString (org.apache.ranger.view.VXString)9 XXGroupPermissionDao (org.apache.ranger.db.XXGroupPermissionDao)6 XXModuleDefDao (org.apache.ranger.db.XXModuleDefDao)6 XXUserPermissionDao (org.apache.ranger.db.XXUserPermissionDao)6 XXPortalUserDao (org.apache.ranger.db.XXPortalUserDao)5 VXModuleDef (org.apache.ranger.view.VXModuleDef)4 VXStringList (org.apache.ranger.view.VXStringList)4 XXGroupUserDao (org.apache.ranger.db.XXGroupUserDao)3