use of co.cask.cdap.proto.security.Principal in project cdap by caskdata.
the class ProgramLifecycleService method hasAccess.
private boolean hasAccess(ProgramId programId) throws Exception {
Principal principal = authenticationContext.getPrincipal();
Predicate<EntityId> filter = authorizationEnforcer.createFilter(principal);
return filter.apply(programId);
}
use of co.cask.cdap.proto.security.Principal in project cdap by caskdata.
the class DatasetInstanceService method list.
/**
* Lists all dataset instances in a namespace. If perimeter security and authorization are enabled, only returns the
* dataset instances that the current user has access to.
*
* @param namespace the namespace to list datasets for
* @return the dataset instances in the provided namespace
* @throws NotFoundException if the namespace was not found
* @throws IOException if there is a problem in making an HTTP request to check if the namespace exists
*/
Collection<DatasetSpecification> list(final NamespaceId namespace) throws Exception {
Principal principal = authenticationContext.getPrincipal();
ensureNamespaceExists(namespace);
Collection<DatasetSpecification> datasets = instanceManager.getAll(namespace);
final Predicate<EntityId> filter = authorizationEnforcer.createFilter(principal);
return Lists.newArrayList(Iterables.filter(datasets, new com.google.common.base.Predicate<DatasetSpecification>() {
@Override
public boolean apply(DatasetSpecification spec) {
return filter.apply(namespace.dataset(spec.getName()));
}
}));
}
use of co.cask.cdap.proto.security.Principal in project cdap by caskdata.
the class DatasetTypeService method getModule.
/**
* Returns the {@link DatasetModuleMeta metadata} of the specified {@link DatasetModuleId}.
*/
DatasetModuleMeta getModule(DatasetModuleId datasetModuleId) throws Exception {
ensureNamespaceExists(datasetModuleId.getParent());
DatasetModuleMeta moduleMeta = typeManager.getModule(datasetModuleId);
if (moduleMeta == null) {
throw new DatasetModuleNotFoundException(datasetModuleId);
}
Principal principal = authenticationContext.getPrincipal();
final Predicate<EntityId> filter = authorizationEnforcer.createFilter(principal);
if (!filter.apply(datasetModuleId)) {
throw new UnauthorizedException(principal, datasetModuleId);
}
return moduleMeta;
}
use of co.cask.cdap.proto.security.Principal in project cdap by caskdata.
the class DatasetTypeService method listTypes.
/**
* Lists all {@link DatasetType dataset types} in the specified {@link NamespaceId}.
*/
List<DatasetTypeMeta> listTypes(final NamespaceId namespaceId) throws Exception {
ensureNamespaceExists(namespaceId);
// Sorting by name for convenience
List<DatasetTypeMeta> allTypes = Lists.newArrayList(typeManager.getTypes(namespaceId));
Collections.sort(allTypes, new Comparator<DatasetTypeMeta>() {
@Override
public int compare(DatasetTypeMeta o1, DatasetTypeMeta o2) {
return o1.getName().compareTo(o2.getName());
}
});
Principal principal = authenticationContext.getPrincipal();
final Predicate<EntityId> authFilter = authorizationEnforcer.createFilter(principal);
Iterable<DatasetTypeMeta> authorizedDatasetTypes = Iterables.filter(allTypes, new com.google.common.base.Predicate<DatasetTypeMeta>() {
@Override
public boolean apply(DatasetTypeMeta datasetTypeMeta) {
DatasetTypeId datasetTypeId = namespaceId.datasetType(datasetTypeMeta.getName());
return authFilter.apply(datasetTypeId);
}
});
return Lists.newArrayList(authorizedDatasetTypes);
}
use of co.cask.cdap.proto.security.Principal in project cdap by caskdata.
the class DatasetTypeService method getType.
/**
* Returns details of the specified {@link DatasetTypeId dataset type}.
*/
DatasetTypeMeta getType(DatasetTypeId datasetTypeId) throws Exception {
ensureNamespaceExists(datasetTypeId.getParent());
DatasetTypeMeta typeMeta = typeManager.getTypeInfo(datasetTypeId);
if (typeMeta == null) {
throw new DatasetTypeNotFoundException(datasetTypeId);
}
// TODO: Test if this can be removed
if (NamespaceId.SYSTEM.equals(datasetTypeId.getParent())) {
return typeMeta;
}
// only return the type if the user has some privileges on it
Principal principal = authenticationContext.getPrincipal();
Predicate<EntityId> authFilter = authorizationEnforcer.createFilter(principal);
if (!authFilter.apply(datasetTypeId)) {
throw new UnauthorizedException(principal, datasetTypeId);
}
return typeMeta;
}
Aggregations