use of org.apache.kylin.common.KylinConfig in project ranger by apache.
the class RangerKylinAccessRequest method checkPermission.
@Override
public boolean checkPermission(String user, List<String> groups, String entityType, String entityUuid, Permission permission) {
if (LOG.isDebugEnabled()) {
LOG.debug("==> RangerKylinAuthorizer.checkPermission( user=" + user + ", groups=" + groups + ", entityType=" + entityType + ", entityUuid=" + entityUuid + ", permission=" + permission + ")");
}
boolean ret = false;
if (kylinPlugin != null) {
String projectName = null;
KylinConfig kylinConfig = KylinConfig.getInstanceFromEnv();
if (AclEntityType.PROJECT_INSTANCE.equals(entityType)) {
ProjectInstance projectInstance = ProjectManager.getInstance(kylinConfig).getPrjByUuid(entityUuid);
if (projectInstance != null) {
projectName = projectInstance.getName();
} else {
if (LOG.isWarnEnabled()) {
LOG.warn("Could not find kylin project for given uuid=" + entityUuid);
}
}
}
String accessType = ExternalAclProvider.transformPermission(permission);
String clusterName = kylinPlugin.getClusterName();
RangerKylinAccessRequest request = new RangerKylinAccessRequest(projectName, user, groups, accessType, clusterName, clientIPAddress);
RangerAccessResult result = kylinPlugin.isAccessAllowed(request);
if (result != null && result.getIsAllowed()) {
ret = true;
}
}
if (LOG.isDebugEnabled()) {
LOG.debug("<== RangerKylinAuthorizer.checkPermission(): result=" + ret);
}
return ret;
}
use of org.apache.kylin.common.KylinConfig in project ranger by apache.
the class RangerKylinAuthorizerTest method mockKylinProjects.
/**
* Help function: mock kylin projects, to match projectUuid and projectName
*/
private static void mockKylinProjects() {
KylinConfig kylinConfig = KylinConfig.getInstanceFromEnv();
ProjectManager projectManager = mock(ProjectManager.class);
@SuppressWarnings({ "rawtypes", "unchecked" }) Map<Class, Object> managersCache = (Map<Class, Object>) ReflectionTestUtils.getField(kylinConfig, "managersCache");
managersCache.put(ProjectManager.class, projectManager);
Answer<ProjectInstance> answer = new Answer<ProjectInstance>() {
@Override
public ProjectInstance answer(InvocationOnMock invocation) throws Throwable {
Object[] args = invocation.getArguments();
if (args == null || args.length == 0) {
return null;
}
String uuid = (String) args[0];
return uuid2Projects.get(uuid);
}
};
when(projectManager.getPrjByUuid(anyString())).thenAnswer(answer);
}
Aggregations