|
|
|
@ -26,6 +26,7 @@ import org.springframework.beans.factory.annotation.Value; |
|
|
|
import org.springframework.security.core.Authentication; |
|
|
|
import org.springframework.security.core.context.SecurityContextHolder; |
|
|
|
import org.springframework.web.bind.annotation.ExceptionHandler; |
|
|
|
import org.thingsboard.server.common.data.BaseData; |
|
|
|
import org.thingsboard.server.common.data.Customer; |
|
|
|
import org.thingsboard.server.common.data.Dashboard; |
|
|
|
import org.thingsboard.server.common.data.DashboardInfo; |
|
|
|
@ -103,7 +104,6 @@ import org.thingsboard.server.service.state.DeviceStateService; |
|
|
|
import org.thingsboard.server.service.telemetry.TelemetrySubscriptionService; |
|
|
|
|
|
|
|
import javax.mail.MessagingException; |
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Optional; |
|
|
|
@ -330,11 +330,23 @@ public abstract class BaseController { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
protected <I extends EntityId, T extends HasTenantId> void checkEntity(I entityId, T entity) throws ThingsboardException { |
|
|
|
if (entityId == null) { |
|
|
|
accessControlService |
|
|
|
.checkPermission(getCurrentUser(), Resource.ALARM, Operation.CREATE, null, entity); |
|
|
|
} else { |
|
|
|
checkEntityId(entityId, Operation.WRITE); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
protected void checkEntityId(EntityId entityId, Operation operation) throws ThingsboardException { |
|
|
|
try { |
|
|
|
checkNotNull(entityId); |
|
|
|
validateId(entityId.getId(), "Incorrect entityId " + entityId); |
|
|
|
switch (entityId.getEntityType()) { |
|
|
|
case ALARM: |
|
|
|
checkAlarmId(new AlarmId(entityId.getId()), operation); |
|
|
|
return; |
|
|
|
case DEVICE: |
|
|
|
checkDeviceId(new DeviceId(entityId.getId()), operation); |
|
|
|
return; |
|
|
|
@ -362,6 +374,12 @@ public abstract class BaseController { |
|
|
|
case ENTITY_VIEW: |
|
|
|
checkEntityViewId(new EntityViewId(entityId.getId()), operation); |
|
|
|
return; |
|
|
|
case WIDGETS_BUNDLE: |
|
|
|
checkWidgetsBundleId(new WidgetsBundleId(entityId.getId()), operation); |
|
|
|
return; |
|
|
|
case WIDGET_TYPE: |
|
|
|
checkWidgetTypeId(new WidgetTypeId(entityId.getId()), operation); |
|
|
|
return; |
|
|
|
default: |
|
|
|
throw new IllegalArgumentException("Unsupported entity type: " + entityId.getEntityType()); |
|
|
|
} |
|
|
|
|