use of org.eclipse.che.account.shared.model.Account in project che-server by eclipse-che.
the class ResourceServicePermissionsFilter method filter.
@Override
protected void filter(GenericResourceMethod genericMethodResource, Object[] arguments) throws ApiException {
String accountId;
switch(genericMethodResource.getMethod().getName()) {
case GET_TOTAL_RESOURCES_METHOD:
case GET_AVAILABLE_RESOURCES_METHOD:
case GET_USED_RESOURCES_METHOD:
case GET_RESOURCES_DETAILS_METHOD:
Subject currentSubject = EnvironmentContext.getCurrent().getSubject();
if (currentSubject.hasPermission(SystemDomain.DOMAIN_ID, null, SystemDomain.MANAGE_SYSTEM_ACTION)) {
// user is admin and he is able to see resources of all accounts
return;
}
accountId = ((String) arguments[0]);
break;
default:
throw new ForbiddenException("The user does not have permission to perform this operation");
}
final Account account = accountManager.getById(accountId);
final AccountPermissionsChecker resourcesPermissionsChecker = permissionsCheckers.get(account.getType());
if (resourcesPermissionsChecker != null) {
resourcesPermissionsChecker.checkPermissions(accountId, AccountOperation.SEE_RESOURCE_INFORMATION);
} else {
throw new ForbiddenException("User is not authorized to perform given operation");
}
}
use of org.eclipse.che.account.shared.model.Account in project che-server by eclipse-che.
the class ResourceManager method getResourceDetails.
/**
* Returns detailed information about resources which given account can use.
*
* @param accountId account id
* @return detailed information about resources which can be used by given account
* @throws NotFoundException when account with specified id was not found
* @throws ServerException when some exception occurs
*/
public ResourcesDetails getResourceDetails(String accountId) throws NotFoundException, ServerException {
final List<ProvidedResources> resources = new ArrayList<>();
for (ResourcesProvider resourcesProvider : resourcesProviders) {
resources.addAll(resourcesProvider.getResources(accountId));
}
final List<Resource> allResources = resources.stream().flatMap(providedResources -> providedResources.getResources().stream()).collect(Collectors.toList());
return new ResourcesDetailsImpl(accountId, resources, new ArrayList<>(resourceAggregator.aggregateByType(allResources).values()));
}
use of org.eclipse.che.account.shared.model.Account in project che-server by eclipse-che.
the class RuntimeResourceUsageTracker method getUsedResource.
@Override
public Optional<Resource> getUsedResource(String accountId) throws NotFoundException, ServerException {
final Account account = accountManager.getById(accountId);
final long currentlyUsedRuntimes = Pages.stream((maxItems, skipCount) -> workspaceManagerProvider.get().getByNamespace(account.getName(), false, maxItems, skipCount)).filter(ws -> STOPPED != ws.getStatus()).count();
if (currentlyUsedRuntimes > 0) {
return Optional.of(new ResourceImpl(RuntimeResourceType.ID, currentlyUsedRuntimes, RuntimeResourceType.UNIT));
} else {
return Optional.empty();
}
}
use of org.eclipse.che.account.shared.model.Account in project che-server by eclipse-che.
the class FreeResourcesProvider method getDefaultResources.
private List<ResourceImpl> getDefaultResources(String accountId) throws NotFoundException, ServerException {
List<ResourceImpl> defaultResources = new ArrayList<>();
final Account account = accountManager.getById(accountId);
final DefaultResourcesProvider defaultResourcesProvider = defaultResourcesProviders.get(account.getType());
if (defaultResourcesProvider != null) {
defaultResources.addAll(defaultResourcesProvider.getResources(accountId));
}
return defaultResources;
}
use of org.eclipse.che.account.shared.model.Account in project che-server by eclipse-che.
the class JpaWorkerDaoTest method shouldThrowServerExceptionOnExistsWhenRuntimeExceptionOccursInDoGetMethod.
@Test(expectedExceptions = ServerException.class, expectedExceptionsMessageRegExp = "Database exception")
public void shouldThrowServerExceptionOnExistsWhenRuntimeExceptionOccursInDoGetMethod() throws Exception {
final Account account = new AccountImpl("accountId", "namespace", "test");
final WorkspaceImpl workspace = WorkspaceImpl.builder().setId("workspaceId").setAccount(account).build();
// Persist the account
manager.getTransaction().begin();
manager.persist(account);
manager.getTransaction().commit();
manager.clear();
// Persist the workspace
manager.getTransaction().begin();
manager.persist(workspace);
manager.getTransaction().commit();
manager.clear();
final UserImpl user = new UserImpl("user0", "user0@com.com", "usr0");
// Persist the user
manager.getTransaction().begin();
manager.persist(user);
manager.getTransaction().commit();
manager.clear();
// Persist the worker
WorkerImpl worker = new WorkerImpl("workspaceId", "user0", Collections.singletonList(SET_PERMISSIONS));
manager.getTransaction().begin();
manager.persist(worker);
manager.getTransaction().commit();
manager.clear();
workerDao.exists("user0", "workspaceId", SET_PERMISSIONS);
}
Aggregations