Search in sources :

Example 71 with NotFoundException

use of com.infiniteautomation.mango.util.exception.NotFoundException in project ma-core-public by MangoAutomation.

the class UsersService method get.

/*
     * Nice little hack since Users don't have an XID.
     */
@Override
public User get(String username) throws NotFoundException, PermissionException {
    Assert.notNull(username, "Username required");
    if (this.userByUsername != null) {
        String usernameLower = username.toLowerCase(Locale.ROOT);
        User vo = userByUsername.get(usernameLower, dao::getByXid);
        if (vo == null) {
            throw new NotFoundException();
        }
        PermissionHolder currentUser = Common.getUser();
        ensureReadPermission(currentUser, vo);
        return vo;
    } else {
        return super.get(username);
    }
}
Also used : User(com.serotonin.m2m2.vo.User) NotFoundException(com.infiniteautomation.mango.util.exception.NotFoundException) PermissionHolder(com.serotonin.m2m2.vo.permission.PermissionHolder)

Example 72 with NotFoundException

use of com.infiniteautomation.mango.util.exception.NotFoundException in project ma-core-public by MangoAutomation.

the class UsersService method getUserByEmail.

/**
 * Get a user by their email address
 *
 * @param emailAddress the email address of the user to find
 * @return the user corresponding to the email address
 * @throws NotFoundException if the email address was not found in the database
 * @throws PermissionException if the current user does not have permission to read this user
 */
public User getUserByEmail(String emailAddress) throws NotFoundException, PermissionException {
    User vo = dao.getUserByEmail(emailAddress);
    if (vo == null)
        throw new NotFoundException();
    PermissionHolder currentUser = Common.getUser();
    ensureReadPermission(currentUser, vo);
    return vo;
}
Also used : User(com.serotonin.m2m2.vo.User) NotFoundException(com.infiniteautomation.mango.util.exception.NotFoundException) PermissionHolder(com.serotonin.m2m2.vo.permission.PermissionHolder)

Example 73 with NotFoundException

use of com.infiniteautomation.mango.util.exception.NotFoundException in project ma-core-public by MangoAutomation.

the class SystemPermissionService method update.

/**
 */
public void update(MangoPermission permission, PermissionDefinition def) throws ValidationException {
    Objects.requireNonNull(def, "Permission definition cannot be null");
    permissionService.ensureAdminRole(Common.getUser());
    ProcessResult validation = new ProcessResult();
    if (permission == null) {
        validation.addContextualMessage("permission", "validate.required");
        throw new ValidationException(validation);
    }
    permission.getRoles().stream().flatMap(Collection::stream).forEach(role -> {
        try {
            roleService.get(role.getXid());
        } catch (NotFoundException e) {
            validation.addGenericMessage("validate.role.notFound", role.getXid());
        }
    });
    if (validation.getHasMessages()) {
        throw new ValidationException(validation);
    }
    // Execute in transaction as def.setPermission may make database calls
    dao.doInTransaction(tx -> {
        dao.update(def.getPermissionTypeName(), def.getPermission(), permission);
        def.setPermission(permission);
    });
    this.eventPublisher.publishEvent(new SystemPermissionUpdated(def));
}
Also used : ValidationException(com.infiniteautomation.mango.util.exception.ValidationException) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) NotFoundException(com.infiniteautomation.mango.util.exception.NotFoundException)

Example 74 with NotFoundException

use of com.infiniteautomation.mango.util.exception.NotFoundException in project ma-core-public by MangoAutomation.

the class DataSourceService method getReadPermission.

/**
 * Get the read permission for this data source
 */
public MangoPermission getReadPermission(int dataPointId) throws NotFoundException, PermissionException {
    PermissionHolder user = Common.getUser();
    Integer permissionId = dao.getReadPermissionId(dataPointId);
    if (permissionId == null) {
        throw new NotFoundException();
    }
    MangoPermission read = permissionService.get(permissionId);
    permissionService.ensurePermission(user, read);
    return read;
}
Also used : NotFoundException(com.infiniteautomation.mango.util.exception.NotFoundException) PermissionHolder(com.serotonin.m2m2.vo.permission.PermissionHolder) MangoPermission(com.infiniteautomation.mango.permission.MangoPermission)

Aggregations

NotFoundException (com.infiniteautomation.mango.util.exception.NotFoundException)74 ValidationException (com.infiniteautomation.mango.util.exception.ValidationException)26 JsonException (com.serotonin.json.JsonException)20 MangoPermission (com.infiniteautomation.mango.permission.MangoPermission)18 TranslatableJsonException (com.serotonin.m2m2.i18n.TranslatableJsonException)18 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)15 User (com.serotonin.m2m2.vo.User)15 PermissionHolder (com.serotonin.m2m2.vo.permission.PermissionHolder)15 PermissionException (com.serotonin.m2m2.vo.permission.PermissionException)12 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)10 DataSourceVO (com.serotonin.m2m2.vo.dataSource.DataSourceVO)9 JsonArray (com.serotonin.json.type.JsonArray)8 TranslatableIllegalArgumentException (com.infiniteautomation.mango.util.exception.TranslatableIllegalArgumentException)6 TranslatableRuntimeException (com.infiniteautomation.mango.util.exception.TranslatableRuntimeException)6 FileStore (com.serotonin.m2m2.vo.FileStore)6 AbstractEventHandlerVO (com.serotonin.m2m2.vo.event.AbstractEventHandlerVO)6 AbstractPointEventDetectorVO (com.serotonin.m2m2.vo.event.detector.AbstractPointEventDetectorVO)6 PublisherVO (com.serotonin.m2m2.vo.publish.PublisherVO)6 ApiOperation (io.swagger.annotations.ApiOperation)6 IOException (java.io.IOException)6