Search in sources :

Example 1 with BrokerStatusChangedEvent

use of org.eclipse.che.api.workspace.shared.dto.event.BrokerStatusChangedEvent in project devspaces-images by redhat-developer.

the class BrokerServicePermissionFilter method doAccept.

@Override
public void doAccept(String method, Object... params) throws ForbiddenException {
    String workspaceId;
    switch(method) {
        case BROKER_STATUS_CHANGED_METHOD:
        case BROKER_RESULT_METHOD:
            RuntimeIdentityDto runtimeId = ((BrokerStatusChangedEvent) params[0]).getRuntimeId();
            if (runtimeId == null || runtimeId.getWorkspaceId() == null) {
                throw new ForbiddenException("Workspace id must be specified");
            }
            workspaceId = runtimeId.getWorkspaceId();
            break;
        default:
            throw new ForbiddenException("Unknown method is configured to be filtered.");
    }
    Subject currentSubject = EnvironmentContext.getCurrent().getSubject();
    if (!currentSubject.hasPermission(WorkspaceDomain.DOMAIN_ID, workspaceId, WorkspaceDomain.RUN)) {
        throw new ForbiddenException("User doesn't have the required permissions to the specified workspace");
    }
}
Also used : ForbiddenException(org.eclipse.che.api.core.ForbiddenException) RuntimeIdentityDto(org.eclipse.che.api.workspace.shared.dto.RuntimeIdentityDto) BrokerStatusChangedEvent(org.eclipse.che.api.workspace.shared.dto.event.BrokerStatusChangedEvent) Subject(org.eclipse.che.commons.subject.Subject)

Example 2 with BrokerStatusChangedEvent

use of org.eclipse.che.api.workspace.shared.dto.event.BrokerStatusChangedEvent in project che-server by eclipse-che.

the class BrokerServicePermissionFilter method doAccept.

@Override
public void doAccept(String method, Object... params) throws ForbiddenException {
    String workspaceId;
    switch(method) {
        case BROKER_STATUS_CHANGED_METHOD:
        case BROKER_RESULT_METHOD:
            RuntimeIdentityDto runtimeId = ((BrokerStatusChangedEvent) params[0]).getRuntimeId();
            if (runtimeId == null || runtimeId.getWorkspaceId() == null) {
                throw new ForbiddenException("Workspace id must be specified");
            }
            workspaceId = runtimeId.getWorkspaceId();
            break;
        default:
            throw new ForbiddenException("Unknown method is configured to be filtered.");
    }
    Subject currentSubject = EnvironmentContext.getCurrent().getSubject();
    if (!currentSubject.hasPermission(WorkspaceDomain.DOMAIN_ID, workspaceId, WorkspaceDomain.RUN)) {
        throw new ForbiddenException("User doesn't have the required permissions to the specified workspace");
    }
}
Also used : ForbiddenException(org.eclipse.che.api.core.ForbiddenException) RuntimeIdentityDto(org.eclipse.che.api.workspace.shared.dto.RuntimeIdentityDto) BrokerStatusChangedEvent(org.eclipse.che.api.workspace.shared.dto.event.BrokerStatusChangedEvent) Subject(org.eclipse.che.commons.subject.Subject)

Aggregations

ForbiddenException (org.eclipse.che.api.core.ForbiddenException)2 RuntimeIdentityDto (org.eclipse.che.api.workspace.shared.dto.RuntimeIdentityDto)2 BrokerStatusChangedEvent (org.eclipse.che.api.workspace.shared.dto.event.BrokerStatusChangedEvent)2 Subject (org.eclipse.che.commons.subject.Subject)2