Search in sources :

Example 1 with IncorrectParameterException

use of org.thingsboard.server.dao.exception.IncorrectParameterException in project thingsboard by thingsboard.

the class UserServiceImpl method requestPasswordReset.

@Override
public UserCredentials requestPasswordReset(String email) {
    log.trace("Executing requestPasswordReset email [{}]", email);
    validateString(email, "Incorrect email " + email);
    User user = userDao.findByEmail(email);
    if (user == null) {
        throw new IncorrectParameterException(String.format("Unable to find user by email [%s]", email));
    }
    UserCredentials userCredentials = userCredentialsDao.findByUserId(user.getUuidId());
    if (!userCredentials.isEnabled()) {
        throw new IncorrectParameterException("Unable to reset password for inactive user");
    }
    userCredentials.setResetToken(RandomStringUtils.randomAlphanumeric(DEFAULT_TOKEN_LENGTH));
    return saveUserCredentials(userCredentials);
}
Also used : User(org.thingsboard.server.common.data.User) IncorrectParameterException(org.thingsboard.server.dao.exception.IncorrectParameterException) UserCredentials(org.thingsboard.server.common.data.security.UserCredentials)

Example 2 with IncorrectParameterException

use of org.thingsboard.server.dao.exception.IncorrectParameterException in project thingsboard by thingsboard.

the class UserServiceImpl method activateUserCredentials.

@Override
public UserCredentials activateUserCredentials(String activateToken, String password) {
    log.trace("Executing activateUserCredentials activateToken [{}], password [{}]", activateToken, password);
    validateString(activateToken, "Incorrect activateToken " + activateToken);
    validateString(password, "Incorrect password " + password);
    UserCredentials userCredentials = userCredentialsDao.findByActivateToken(activateToken);
    if (userCredentials == null) {
        throw new IncorrectParameterException(String.format("Unable to find user credentials by activateToken [%s]", activateToken));
    }
    if (userCredentials.isEnabled()) {
        throw new IncorrectParameterException("User credentials already activated");
    }
    userCredentials.setEnabled(true);
    userCredentials.setActivateToken(null);
    userCredentials.setPassword(password);
    return saveUserCredentials(userCredentials);
}
Also used : IncorrectParameterException(org.thingsboard.server.dao.exception.IncorrectParameterException) UserCredentials(org.thingsboard.server.common.data.security.UserCredentials)

Example 3 with IncorrectParameterException

use of org.thingsboard.server.dao.exception.IncorrectParameterException in project thingsboard by thingsboard.

the class BaseComponentDescriptorService method validate.

@Override
public boolean validate(ComponentDescriptor component, JsonNode configuration) {
    JsonValidator validator = JsonSchemaFactory.byDefault().getValidator();
    try {
        if (!component.getConfigurationDescriptor().has("schema")) {
            throw new DataValidationException("Configuration descriptor doesn't contain schema property!");
        }
        JsonNode configurationSchema = component.getConfigurationDescriptor().get("schema");
        ProcessingReport report = validator.validate(configurationSchema, configuration);
        return report.isSuccess();
    } catch (ProcessingException e) {
        throw new IncorrectParameterException(e.getMessage(), e);
    }
}
Also used : ProcessingReport(com.github.fge.jsonschema.core.report.ProcessingReport) DataValidationException(org.thingsboard.server.dao.exception.DataValidationException) IncorrectParameterException(org.thingsboard.server.dao.exception.IncorrectParameterException) JsonNode(com.fasterxml.jackson.databind.JsonNode) JsonValidator(com.github.fge.jsonschema.main.JsonValidator) ProcessingException(com.github.fge.jsonschema.core.exceptions.ProcessingException)

Example 4 with IncorrectParameterException

use of org.thingsboard.server.dao.exception.IncorrectParameterException in project thingsboard by thingsboard.

the class BaseRuleService method validateRuleAndPluginState.

private void validateRuleAndPluginState(RuleMetaData rule) {
    if (org.springframework.util.StringUtils.isEmpty(rule.getPluginToken())) {
        return;
    }
    PluginMetaData pluginMd = pluginService.findPluginByApiToken(rule.getPluginToken());
    if (pluginMd == null) {
        throw new IncorrectParameterException("Rule points to non-existent plugin!");
    }
    if (!pluginMd.getTenantId().equals(systemTenantId) && !pluginMd.getTenantId().equals(rule.getTenantId())) {
        throw new IncorrectParameterException("Rule access plugin that belongs to different tenant!");
    }
    if (rule.getState() == ComponentLifecycleState.ACTIVE && pluginMd.getState() != ComponentLifecycleState.ACTIVE) {
        throw new IncorrectParameterException("Can't save active rule that points to inactive plugin!");
    }
    ComponentDescriptor pluginDescriptor = componentDescriptorService.findByClazz(pluginMd.getClazz());
    String actionClazz = getIfValid(ComponentType.ACTION.name(), rule.getAction(), "clazz", JsonNode::isTextual, JsonNode::asText);
    if (!Arrays.asList(pluginDescriptor.getActions().split(",")).contains(actionClazz)) {
        throw new IncorrectParameterException("Rule's action is not supported by plugin with token " + rule.getPluginToken() + "!");
    }
}
Also used : IncorrectParameterException(org.thingsboard.server.dao.exception.IncorrectParameterException) ComponentDescriptor(org.thingsboard.server.common.data.plugin.ComponentDescriptor) PluginMetaData(org.thingsboard.server.common.data.plugin.PluginMetaData) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 5 with IncorrectParameterException

use of org.thingsboard.server.dao.exception.IncorrectParameterException in project thingsboard by thingsboard.

the class BaseRuleService method saveRule.

@Override
public RuleMetaData saveRule(RuleMetaData rule) {
    ruleValidator.validate(rule);
    if (rule.getTenantId() == null) {
        log.trace("Save system rule metadata with predefined id {}", systemTenantId);
        rule.setTenantId(systemTenantId);
    }
    if (rule.getId() != null) {
        RuleMetaData oldVersion = ruleDao.findById(rule.getId());
        if (rule.getState() == null) {
            rule.setState(oldVersion.getState());
        } else if (rule.getState() != oldVersion.getState()) {
            throw new IncorrectParameterException("Use Activate/Suspend method to control state of the rule!");
        }
    } else {
        if (rule.getState() == null) {
            rule.setState(ComponentLifecycleState.SUSPENDED);
        } else if (rule.getState() != ComponentLifecycleState.SUSPENDED) {
            throw new IncorrectParameterException("Use Activate/Suspend method to control state of the rule!");
        }
    }
    validateFilters(rule.getFilters());
    if (rule.getProcessor() != null && !rule.getProcessor().isNull()) {
        validateComponentJson(rule.getProcessor(), ComponentType.PROCESSOR);
    }
    if (rule.getAction() != null && !rule.getAction().isNull()) {
        validateComponentJson(rule.getAction(), ComponentType.ACTION);
    }
    validateRuleAndPluginState(rule);
    return ruleDao.save(rule);
}
Also used : IncorrectParameterException(org.thingsboard.server.dao.exception.IncorrectParameterException) RuleMetaData(org.thingsboard.server.common.data.rule.RuleMetaData)

Aggregations

IncorrectParameterException (org.thingsboard.server.dao.exception.IncorrectParameterException)13 JsonNode (com.fasterxml.jackson.databind.JsonNode)5 Customer (org.thingsboard.server.common.data.Customer)4 ComponentDescriptor (org.thingsboard.server.common.data.plugin.ComponentDescriptor)3 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)2 PluginMetaData (org.thingsboard.server.common.data.plugin.PluginMetaData)2 UserCredentials (org.thingsboard.server.common.data.security.UserCredentials)2 ThingsboardException (org.thingsboard.server.exception.ThingsboardException)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ProcessingException (com.github.fge.jsonschema.core.exceptions.ProcessingException)1 ProcessingReport (com.github.fge.jsonschema.core.report.ProcessingReport)1 JsonValidator (com.github.fge.jsonschema.main.JsonValidator)1 IOException (java.io.IOException)1 AdminSettings (org.thingsboard.server.common.data.AdminSettings)1 Device (org.thingsboard.server.common.data.Device)1 User (org.thingsboard.server.common.data.User)1 Asset (org.thingsboard.server.common.data.asset.Asset)1 AssetId (org.thingsboard.server.common.data.id.AssetId)1 DeviceId (org.thingsboard.server.common.data.id.DeviceId)1 RuleMetaData (org.thingsboard.server.common.data.rule.RuleMetaData)1