Search in sources :

Example 96 with XXPortalUser

use of org.apache.ranger.entity.XXPortalUser in project ranger by apache.

the class XUserPermissionServiceBase method mapViewToEntityBean.

@Override
protected T mapViewToEntityBean(V vObj, T mObj, int OPERATION_CONTEXT) {
    // Assuming that vObj.userId coming from UI/Client would be of XXUser, but in DB it should be of XXPortalUser so
    // have to map XXUser.ID to XXPortalUser.ID and if portalUser does not exist then not allowing to create/update
    XXPortalUser portalUser = daoManager.getXXPortalUser().findByXUserId(vObj.getUserId());
    if (portalUser == null) {
        throw restErrorUtil.createRESTException("Invalid UserId: [" + vObj.getUserId() + "], Please make sure while create/update given userId should be of x_user", MessageEnums.INVALID_INPUT_DATA);
    }
    mObj.setUserId(portalUser.getId());
    mObj.setModuleId(vObj.getModuleId());
    mObj.setIsAllowed(vObj.getIsAllowed());
    if (OPERATION_CONTEXT == OPERATION_CREATE_CONTEXT) {
        validateXUserPermForCreate(mObj);
    } else if (OPERATION_CONTEXT == OPERATION_UPDATE_CONTEXT) {
        validateXUserPermForUpdate(mObj);
    }
    return mObj;
}
Also used : XXPortalUser(org.apache.ranger.entity.XXPortalUser)

Example 97 with XXPortalUser

use of org.apache.ranger.entity.XXPortalUser in project ranger by apache.

the class XResourceService method mapViewToEntityBean.

@Override
protected XXResource mapViewToEntityBean(VXResource vObj, XXResource mObj, int OPERATION_CONTEXT) {
    XXResource ret = null;
    if (vObj != null && mObj != null) {
        ret = super.mapViewToEntityBean(vObj, mObj, OPERATION_CONTEXT);
        ret.setUdfs(vObj.getUdfs());
        XXPortalUser xXPortalUser = null;
        if (ret.getAddedByUserId() == null || ret.getAddedByUserId() == 0) {
            if (!stringUtil.isEmpty(vObj.getOwner())) {
                xXPortalUser = daoManager.getXXPortalUser().findByLoginId(vObj.getOwner());
                if (xXPortalUser != null) {
                    ret.setAddedByUserId(xXPortalUser.getId());
                }
            }
        }
        if (ret.getUpdatedByUserId() == null || ret.getUpdatedByUserId() == 0) {
            if (!stringUtil.isEmpty(vObj.getUpdatedBy())) {
                xXPortalUser = daoManager.getXXPortalUser().findByLoginId(vObj.getUpdatedBy());
                if (xXPortalUser != null) {
                    ret.setUpdatedByUserId(xXPortalUser.getId());
                }
            }
        }
    }
    return ret;
}
Also used : XXPortalUser(org.apache.ranger.entity.XXPortalUser) XXResource(org.apache.ranger.entity.XXResource)

Example 98 with XXPortalUser

use of org.apache.ranger.entity.XXPortalUser in project ranger by apache.

the class XTrxLogService method mapEntityToViewBean.

@Override
protected VXTrxLog mapEntityToViewBean(VXTrxLog vObj, XXTrxLog mObj) {
    VXTrxLog ret = null;
    if (mObj != null && vObj != null) {
        ret = super.mapEntityToViewBean(vObj, mObj);
        XXPortalUser xXPortalUser = null;
        if (stringUtil.isEmpty(ret.getOwner())) {
            xXPortalUser = daoManager.getXXPortalUser().getById(mObj.getAddedByUserId());
            if (xXPortalUser != null) {
                ret.setOwner(xXPortalUser.getLoginId());
            }
        }
        if (stringUtil.isEmpty(ret.getUpdatedBy())) {
            xXPortalUser = daoManager.getXXPortalUser().getById(mObj.getUpdatedByUserId());
            if (xXPortalUser != null) {
                ret.setUpdatedBy(xXPortalUser.getLoginId());
            }
        }
    }
    return ret;
}
Also used : XXPortalUser(org.apache.ranger.entity.XXPortalUser) VXTrxLog(org.apache.ranger.view.VXTrxLog)

Example 99 with XXPortalUser

use of org.apache.ranger.entity.XXPortalUser in project ranger by apache.

the class XGroupService method createXGroupWithOutLogin.

public VXGroup createXGroupWithOutLogin(VXGroup vxGroup) {
    XXGroup xxGroup = daoManager.getXXGroup().findByGroupName(vxGroup.getName());
    boolean groupExists = true;
    if (xxGroup == null) {
        xxGroup = new XXGroup();
        groupExists = false;
    }
    xxGroup = mapViewToEntityBean(vxGroup, xxGroup, 0);
    XXPortalUser xXPortalUser = daoManager.getXXPortalUser().getById(createdByUserId);
    if (xXPortalUser != null) {
        xxGroup.setAddedByUserId(createdByUserId);
        xxGroup.setUpdatedByUserId(createdByUserId);
    }
    if (groupExists) {
        getDao().update(xxGroup);
    } else {
        getDao().create(xxGroup);
    }
    xxGroup = daoManager.getXXGroup().findByGroupName(vxGroup.getName());
    vxGroup = postCreate(xxGroup);
    return vxGroup;
}
Also used : XXPortalUser(org.apache.ranger.entity.XXPortalUser) XXGroup(org.apache.ranger.entity.XXGroup)

Example 100 with XXPortalUser

use of org.apache.ranger.entity.XXPortalUser in project ranger by apache.

the class TestRangerServiceService method test3PopulateViewBean.

@Test
public void test3PopulateViewBean() {
    XXServiceConfigMapDao xServiceConfigMapDao = Mockito.mock(XXServiceConfigMapDao.class);
    XXPortalUserDao xPortalUserDao = Mockito.mock(XXPortalUserDao.class);
    XXServiceDefDao xServiceDefDao = Mockito.mock(XXServiceDefDao.class);
    XXService xService = xService();
    String name = "fdfdfds";
    List<XXServiceConfigMap> svcConfigMapList = new ArrayList<XXServiceConfigMap>();
    XXServiceConfigMap xConfMap = new XXServiceConfigMap();
    xConfMap.setAddedByUserId(null);
    xConfMap.setConfigkey(name);
    xConfMap.setConfigvalue(name);
    xConfMap.setCreateTime(new Date());
    xConfMap.setServiceId(null);
    xConfMap.setUpdatedByUserId(null);
    xConfMap.setUpdateTime(new Date());
    svcConfigMapList.add(xConfMap);
    XXPortalUser tUser = new XXPortalUser();
    tUser.setAddedByUserId(userId);
    tUser.setCreateTime(new Date());
    tUser.setEmailAddress("test@gmail.com");
    tUser.setFirstName(name);
    tUser.setId(userId);
    tUser.setLastName(name);
    XXServiceDef xServiceDef = new XXServiceDef();
    xServiceDef.setAddedByUserId(userId);
    xServiceDef.setCreateTime(new Date());
    xServiceDef.setDescription("test");
    xServiceDef.setGuid("1427365526516_835_0");
    xServiceDef.setId(userId);
    XXServiceVersionInfoDao xServiceVersionInfoDao = Mockito.mock(XXServiceVersionInfoDao.class);
    XXServiceVersionInfo serviceVersionInfo = new XXServiceVersionInfo();
    serviceVersionInfo.setServiceId(xService.getId());
    serviceVersionInfo.setPolicyVersion(xService.getPolicyVersion());
    serviceVersionInfo.setPolicyUpdateTime(xService.getPolicyUpdateTime());
    serviceVersionInfo.setTagVersion(xService.getTagVersion());
    serviceVersionInfo.setTagUpdateTime(xService.getTagUpdateTime());
    Mockito.when(daoManager.getXXServiceVersionInfo()).thenReturn(xServiceVersionInfoDao);
    Mockito.when(xServiceVersionInfoDao.findByServiceId(xService.getId())).thenReturn(serviceVersionInfo);
    Mockito.when(daoManager.getXXPortalUser()).thenReturn(xPortalUserDao);
    Mockito.when(xPortalUserDao.getById(userId)).thenReturn(tUser);
    Mockito.when(daoManager.getXXServiceDef()).thenReturn(xServiceDefDao);
    Mockito.when(xServiceDefDao.getById(xService.getType())).thenReturn(xServiceDef);
    Mockito.when(daoManager.getXXServiceConfigMap()).thenReturn(xServiceConfigMapDao);
    Mockito.when(xServiceConfigMapDao.findByServiceId(xService.getId())).thenReturn(svcConfigMapList);
    RangerService dbService = serviceService.populateViewBean(xService);
    Assert.assertNotNull(dbService);
    Assert.assertEquals(userId, dbService.getId());
    Assert.assertEquals(xService.getAddedByUserId(), dbService.getId());
    Assert.assertEquals(xService.getId(), dbService.getId());
    Assert.assertEquals(xService.getDescription(), dbService.getDescription());
    Assert.assertEquals(xService.getGuid(), dbService.getGuid());
    Assert.assertEquals(xService.getName(), dbService.getName());
    Assert.assertEquals(xService.getPolicyUpdateTime(), dbService.getPolicyUpdateTime());
    Assert.assertEquals(xService.getPolicyVersion(), dbService.getPolicyVersion());
    Assert.assertEquals(xService.getVersion(), dbService.getVersion());
    Mockito.verify(daoManager).getXXServiceDef();
    Mockito.verify(daoManager).getXXServiceConfigMap();
}
Also used : XXServiceDef(org.apache.ranger.entity.XXServiceDef) ArrayList(java.util.ArrayList) XXServiceConfigMapDao(org.apache.ranger.db.XXServiceConfigMapDao) Date(java.util.Date) XXServiceConfigMap(org.apache.ranger.entity.XXServiceConfigMap) XXPortalUser(org.apache.ranger.entity.XXPortalUser) XXServiceDefDao(org.apache.ranger.db.XXServiceDefDao) XXPortalUserDao(org.apache.ranger.db.XXPortalUserDao) RangerService(org.apache.ranger.plugin.model.RangerService) XXService(org.apache.ranger.entity.XXService) XXServiceVersionInfo(org.apache.ranger.entity.XXServiceVersionInfo) XXServiceVersionInfoDao(org.apache.ranger.db.XXServiceVersionInfoDao) Test(org.junit.Test)

Aggregations

XXPortalUser (org.apache.ranger.entity.XXPortalUser)192 Test (org.junit.Test)113 ArrayList (java.util.ArrayList)93 VXPortalUser (org.apache.ranger.view.VXPortalUser)86 VXString (org.apache.ranger.view.VXString)82 XXPortalUserDao (org.apache.ranger.db.XXPortalUserDao)74 XXPortalUserRole (org.apache.ranger.entity.XXPortalUserRole)46 XXPortalUserRoleDao (org.apache.ranger.db.XXPortalUserRoleDao)44 XXUserPermission (org.apache.ranger.entity.XXUserPermission)36 UserSessionBase (org.apache.ranger.common.UserSessionBase)34 VXUser (org.apache.ranger.view.VXUser)34 WebApplicationException (javax.ws.rs.WebApplicationException)33 Date (java.util.Date)30 RangerSecurityContext (org.apache.ranger.security.context.RangerSecurityContext)29 XXUser (org.apache.ranger.entity.XXUser)27 XXUserPermissionDao (org.apache.ranger.db.XXUserPermissionDao)25 XXModuleDef (org.apache.ranger.entity.XXModuleDef)25 XXModuleDefDao (org.apache.ranger.db.XXModuleDefDao)20 XXGroupPermission (org.apache.ranger.entity.XXGroupPermission)19 VXUserPermission (org.apache.ranger.view.VXUserPermission)19