Search in sources :

Example 16 with ThingsboardException

use of org.thingsboard.server.exception.ThingsboardException in project thingsboard by thingsboard.

the class BaseController method checkComponentDescriptorByClazz.

ComponentDescriptor checkComponentDescriptorByClazz(String clazz) throws ThingsboardException {
    try {
        log.debug("[{}] Lookup component descriptor", clazz);
        ComponentDescriptor componentDescriptor = checkNotNull(componentDescriptorService.getComponent(clazz));
        return componentDescriptor;
    } catch (Exception e) {
        throw handleException(e, false);
    }
}
Also used : ComponentDescriptor(org.thingsboard.server.common.data.plugin.ComponentDescriptor) MessagingException(javax.mail.MessagingException) IncorrectParameterException(org.thingsboard.server.dao.exception.IncorrectParameterException) ThingsboardException(org.thingsboard.server.exception.ThingsboardException) DataValidationException(org.thingsboard.server.dao.exception.DataValidationException)

Example 17 with ThingsboardException

use of org.thingsboard.server.exception.ThingsboardException in project thingsboard by thingsboard.

the class BaseController method checkDashboard.

private void checkDashboard(DashboardInfo dashboard) throws ThingsboardException {
    checkNotNull(dashboard);
    checkTenantId(dashboard.getTenantId());
    SecurityUser authUser = getCurrentUser();
    if (authUser.getAuthority() == Authority.CUSTOMER_USER) {
        if (!dashboard.isAssignedToCustomer(authUser.getCustomerId())) {
            throw new ThingsboardException(YOU_DON_T_HAVE_PERMISSION_TO_PERFORM_THIS_OPERATION, ThingsboardErrorCode.PERMISSION_DENIED);
        }
    }
}
Also used : SecurityUser(org.thingsboard.server.service.security.model.SecurityUser) ThingsboardException(org.thingsboard.server.exception.ThingsboardException)

Example 18 with ThingsboardException

use of org.thingsboard.server.exception.ThingsboardException in project thingsboard by thingsboard.

the class BaseController method checkRule.

protected RuleMetaData checkRule(RuleMetaData rule) throws ThingsboardException {
    checkNotNull(rule);
    SecurityUser authUser = getCurrentUser();
    TenantId tenantId = rule.getTenantId();
    validateId(tenantId, INCORRECT_TENANT_ID + tenantId);
    if (authUser.getAuthority() != Authority.SYS_ADMIN) {
        if (authUser.getTenantId() == null || !tenantId.getId().equals(ModelConstants.NULL_UUID) && !authUser.getTenantId().equals(tenantId)) {
            throw new ThingsboardException(YOU_DON_T_HAVE_PERMISSION_TO_PERFORM_THIS_OPERATION, ThingsboardErrorCode.PERMISSION_DENIED);
        }
    }
    return rule;
}
Also used : SecurityUser(org.thingsboard.server.service.security.model.SecurityUser) ThingsboardException(org.thingsboard.server.exception.ThingsboardException)

Example 19 with ThingsboardException

use of org.thingsboard.server.exception.ThingsboardException in project thingsboard by thingsboard.

the class BaseController method checkAlarmInfoId.

AlarmInfo checkAlarmInfoId(AlarmId alarmId) throws ThingsboardException {
    try {
        validateId(alarmId, "Incorrect alarmId " + alarmId);
        AlarmInfo alarmInfo = alarmService.findAlarmInfoByIdAsync(alarmId).get();
        checkAlarm(alarmInfo);
        return alarmInfo;
    } catch (Exception e) {
        throw handleException(e, false);
    }
}
Also used : AlarmInfo(org.thingsboard.server.common.data.alarm.AlarmInfo) MessagingException(javax.mail.MessagingException) IncorrectParameterException(org.thingsboard.server.dao.exception.IncorrectParameterException) ThingsboardException(org.thingsboard.server.exception.ThingsboardException) DataValidationException(org.thingsboard.server.dao.exception.DataValidationException)

Example 20 with ThingsboardException

use of org.thingsboard.server.exception.ThingsboardException in project thingsboard by thingsboard.

the class BaseController method checkPlugin.

protected PluginMetaData checkPlugin(PluginMetaData plugin) throws ThingsboardException {
    checkNotNull(plugin);
    SecurityUser authUser = getCurrentUser();
    TenantId tenantId = plugin.getTenantId();
    validateId(tenantId, INCORRECT_TENANT_ID + tenantId);
    if (authUser.getAuthority() != Authority.SYS_ADMIN) {
        if (authUser.getTenantId() == null || !tenantId.getId().equals(ModelConstants.NULL_UUID) && !authUser.getTenantId().equals(tenantId)) {
            throw new ThingsboardException(YOU_DON_T_HAVE_PERMISSION_TO_PERFORM_THIS_OPERATION, ThingsboardErrorCode.PERMISSION_DENIED);
        } else if (tenantId.getId().equals(ModelConstants.NULL_UUID)) {
            plugin.setConfiguration(null);
        }
    }
    return plugin;
}
Also used : SecurityUser(org.thingsboard.server.service.security.model.SecurityUser) ThingsboardException(org.thingsboard.server.exception.ThingsboardException)

Aggregations

ThingsboardException (org.thingsboard.server.exception.ThingsboardException)88 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)72 IncorrectParameterException (org.thingsboard.server.dao.exception.IncorrectParameterException)39 TenantId (org.thingsboard.server.common.data.id.TenantId)23 SecurityUser (org.thingsboard.server.service.security.model.SecurityUser)18 CustomerId (org.thingsboard.server.common.data.id.CustomerId)17 TextPageLink (org.thingsboard.server.common.data.page.TextPageLink)11 Customer (org.thingsboard.server.common.data.Customer)10 MessagingException (javax.mail.MessagingException)8 DashboardId (org.thingsboard.server.common.data.id.DashboardId)8 DataValidationException (org.thingsboard.server.dao.exception.DataValidationException)8 Device (org.thingsboard.server.common.data.Device)7 EntityId (org.thingsboard.server.common.data.id.EntityId)7 TimePageLink (org.thingsboard.server.common.data.page.TimePageLink)7 User (org.thingsboard.server.common.data.User)6 Asset (org.thingsboard.server.common.data.asset.Asset)6 DeviceId (org.thingsboard.server.common.data.id.DeviceId)6 RelationTypeGroup (org.thingsboard.server.common.data.relation.RelationTypeGroup)6 UserCredentials (org.thingsboard.server.common.data.security.UserCredentials)6 List (java.util.List)5