Search in sources :

Example 26 with Account

use of org.eclipse.che.account.shared.model.Account in project devspaces-images by redhat-developer.

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");
    }
}
Also used : Account(org.eclipse.che.account.shared.model.Account) ForbiddenException(org.eclipse.che.api.core.ForbiddenException) AccountPermissionsChecker(org.eclipse.che.multiuser.api.permission.server.account.AccountPermissionsChecker) Subject(org.eclipse.che.commons.subject.Subject)

Aggregations

Account (org.eclipse.che.account.shared.model.Account)26 ServerException (org.eclipse.che.api.core.ServerException)14 NotFoundException (org.eclipse.che.api.core.NotFoundException)12 Optional (java.util.Optional)10 Inject (javax.inject.Inject)10 Singleton (javax.inject.Singleton)10 AccountManager (org.eclipse.che.account.api.AccountManager)10 Resource (org.eclipse.che.multiuser.resource.model.Resource)10 List (java.util.List)8 WorkspaceManager (org.eclipse.che.api.workspace.server.WorkspaceManager)8 WorkspaceImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl)8 ResourceUsageTracker (org.eclipse.che.multiuser.resource.api.ResourceUsageTracker)8 ResourceImpl (org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl)8 Collectors (java.util.stream.Collectors)6 Provider (javax.inject.Provider)6 Pages (org.eclipse.che.api.core.Pages)6 ArrayList (java.util.ArrayList)4 ConflictException (org.eclipse.che.api.core.ConflictException)4 ForbiddenException (org.eclipse.che.api.core.ForbiddenException)4 STOPPED (org.eclipse.che.api.core.model.workspace.WorkspaceStatus.STOPPED)4