Search in sources :

Example 1 with XXDBBase

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

the class TestRangerBizUtil method testGetMObject_NOVXDataObject.

@Test
public void testGetMObject_NOVXDataObject() {
    XXDBBase xXDBaseChk = rangerBizUtil.getMObject(null);
    Assert.assertNull(xXDBaseChk);
}
Also used : XXDBBase(org.apache.ranger.entity.XXDBBase) Test(org.junit.Test)

Example 2 with XXDBBase

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

the class TestRangerBizUtil method testGetMObject.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testGetMObject() {
    BaseDao baseDao = Mockito.mock(BaseDao.class);
    Mockito.when(daoManager.getDaoForClassType(RangerCommonEnums.CLASS_TYPE_USER_PROFILE)).thenReturn(baseDao);
    Mockito.when(baseDao.getById(id)).thenReturn(new XXAsset());
    XXDBBase mObjChk = rangerBizUtil.getMObject(RangerCommonEnums.CLASS_TYPE_USER_PROFILE, id);
    Assert.assertNotNull(mObjChk);
}
Also used : BaseDao(org.apache.ranger.common.db.BaseDao) XXAsset(org.apache.ranger.entity.XXAsset) XXDBBase(org.apache.ranger.entity.XXDBBase) Test(org.junit.Test)

Example 3 with XXDBBase

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

the class RangerBizUtil method getClassType.

public int getClassType(Class<?> klass) {
    String className = klass.getName();
    // See if this mapping is already in the database
    Integer classType = classTypeMappings.get(className);
    if (classType == null) {
        // Instantiate the class and call the getClassType method
        if (XXDBBase.class.isAssignableFrom(klass)) {
            try {
                XXDBBase gjObj = (XXDBBase) klass.newInstance();
                classType = gjObj.getMyClassType();
                classTypeMappings.put(className, classType);
            } catch (Throwable ex) {
                logger.error("Error instantiating object for class " + className, ex);
            }
        }
    }
    if (classType == null) {
        return RangerCommonEnums.CLASS_TYPE_NONE;
    } else {
        return classType;
    }
}
Also used : XXDBBase(org.apache.ranger.entity.XXDBBase) VXString(org.apache.ranger.view.VXString)

Example 4 with XXDBBase

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

the class RangerDomainObjectSecurityHandler method hasAccess.

public boolean hasAccess(Class<? extends XXDBBase> targetClass, Serializable targetId, Permission.permissionType permission) {
    try {
        Class<? extends XXDBBase> gjClazz = targetClass.asSubclass(XXDBBase.class);
        XXDBBase base = getDaoManager().getEntityManager().find(gjClazz, targetId);
        return hasAccess(base, permission);
    } catch (Exception e) {
        logger.error("Excepion targetType:" + targetClass + " targetId:" + targetId, e);
    }
    return false;
}
Also used : XXDBBase(org.apache.ranger.entity.XXDBBase)

Example 5 with XXDBBase

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

the class TestRangerBizUtil method testGetMObject_VXDataObject.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testGetMObject_VXDataObject() {
    VXAsset vXDataObject = new VXAsset();
    vXDataObject.setId(id);
    BaseDao baseDao = Mockito.mock(BaseDao.class);
    Mockito.when(daoManager.getDaoForClassType(vXDataObject.getMyClassType())).thenReturn(baseDao);
    Mockito.when(baseDao.getById(vXDataObject.getId())).thenReturn(new XXAsset());
    XXDBBase xXDBaseChk = rangerBizUtil.getMObject(vXDataObject);
    Assert.assertNotNull(xXDBaseChk);
}
Also used : VXAsset(org.apache.ranger.view.VXAsset) BaseDao(org.apache.ranger.common.db.BaseDao) XXAsset(org.apache.ranger.entity.XXAsset) XXDBBase(org.apache.ranger.entity.XXDBBase) Test(org.junit.Test)

Aggregations

XXDBBase (org.apache.ranger.entity.XXDBBase)8 Test (org.junit.Test)4 BaseDao (org.apache.ranger.common.db.BaseDao)2 XXAsset (org.apache.ranger.entity.XXAsset)2 PrePersist (javax.persistence.PrePersist)1 PreUpdate (javax.persistence.PreUpdate)1 UserSessionBase (org.apache.ranger.common.UserSessionBase)1 RangerSecurityContext (org.apache.ranger.security.context.RangerSecurityContext)1 VXAsset (org.apache.ranger.view.VXAsset)1 VXString (org.apache.ranger.view.VXString)1