Search in sources :

Example 96 with MangoPermission

use of com.infiniteautomation.mango.permission.MangoPermission in project ma-core-public by infiniteautomation.

the class AbstractVOServiceWithPermissionsTest method removeRoleFromCreatePermission.

void removeRoleFromCreatePermission(Role vo) {
    String permissionType = getCreatePermissionType();
    if (permissionType != null) {
        PermissionDefinition def = ModuleRegistry.getPermissionDefinition(getCreatePermissionType());
        MangoPermission permission = def.getPermission();
        Common.getBean(SystemPermissionService.class).update(new MangoPermission(permission.withoutRole(vo).getRoles()), def);
    }
}
Also used : PermissionDefinition(com.serotonin.m2m2.module.PermissionDefinition) MangoPermission(com.infiniteautomation.mango.permission.MangoPermission)

Example 97 with MangoPermission

use of com.infiniteautomation.mango.permission.MangoPermission in project ma-core-public by infiniteautomation.

the class DataPointDao method mapRecord.

@Override
public DataPointVO mapRecord(Record record) {
    int id = record.get(table.id);
    String xid = record.get(table.xid);
    String name = record.get(table.name);
    DataPointVO dp = (DataPointVO) SerializationHelper.readObjectInContextFromArray(record.get(table.data));
    dp.setId(id);
    dp.setXid(xid);
    dp.setName(name);
    dp.setDataSourceId(record.get(table.dataSourceId));
    dp.setDeviceName(record.get(table.deviceName));
    dp.setEnabled(charToBool(record.get(table.enabled)));
    dp.setLoggingType(record.get(table.loggingType));
    dp.setIntervalLoggingPeriodType(record.get(table.intervalLoggingPeriodType));
    dp.setIntervalLoggingPeriod(record.get(table.intervalLoggingPeriod));
    dp.setIntervalLoggingType(record.get(table.intervalLoggingType));
    dp.setTolerance(record.get(table.tolerance));
    dp.setPurgeOverride(charToBool(record.get(table.purgeOverride)));
    dp.setPurgeType(record.get(table.purgeType));
    dp.setPurgePeriod(record.get(table.purgePeriod));
    dp.setDefaultCacheSize(record.get(table.defaultCacheSize));
    dp.setDiscardExtremeValues(charToBool(record.get(table.discardExtremeValues)));
    dp.setEngineeringUnits(record.get(table.engineeringUnits));
    dp.setRollup(record.get(table.rollup));
    // // read and discard dataTypeId
    // record.get(table.xyz);
    // // read and discard settable boolean
    // record.get(table.xyz);
    dp.setData(extractDataFromObject(record.get(table.jsonData)));
    dp.setSeriesId(record.get(table.seriesId));
    MangoPermission read = new MangoPermission(record.get(table.readPermissionId));
    dp.supplyReadPermission(() -> read);
    MangoPermission edit = new MangoPermission(record.get(table.editPermissionId));
    dp.supplyEditPermission(() -> edit);
    MangoPermission set = new MangoPermission(record.get(table.setPermissionId));
    dp.supplySetPermission(() -> set);
    // Data source information from join
    dp.setDataSourceName(record.get(dataSources.name));
    dp.setDataSourceXid(record.get(dataSources.xid));
    dp.setDataSourceTypeName(record.get(dataSources.dataSourceType));
    dp.ensureUnitsCorrect();
    return dp;
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) MangoPermission(com.infiniteautomation.mango.permission.MangoPermission)

Example 98 with MangoPermission

use of com.infiniteautomation.mango.permission.MangoPermission in project ma-core-public by infiniteautomation.

the class MangoPermissionConverter method jsonWrite.

@Override
public JsonValue jsonWrite(JsonTypeWriter writer, Object value) throws JsonException {
    MangoPermission permission = (MangoPermission) value;
    JsonArray outerRolesArray = new JsonArray();
    for (Set<Role> roleSet : permission.getRoles()) {
        JsonArray roles = new JsonArray();
        for (Role role : roleSet) {
            roles.add(role.getXid());
        }
        outerRolesArray.add(roles);
    }
    return outerRolesArray;
}
Also used : JsonArray(com.serotonin.json.type.JsonArray) Role(com.serotonin.m2m2.vo.role.Role) MangoPermission(com.infiniteautomation.mango.permission.MangoPermission)

Example 99 with MangoPermission

use of com.infiniteautomation.mango.permission.MangoPermission in project ma-core-public by infiniteautomation.

the class PermissionService method get.

/**
 * Get a permission from the cache, load from db if necessary
 * @param id
 * @return
 * @throws NotFoundException if permission with this ID not found
 */
public MangoPermission get(Integer id) throws NotFoundException {
    Objects.requireNonNull(id);
    MangoPermission permission = permissionCache.computeIfAbsent(id, this::loadPermission);
    if (permission == null) {
        throw new NotFoundException();
    } else {
        return permission.withId(id);
    }
}
Also used : NotFoundException(com.infiniteautomation.mango.util.exception.NotFoundException) MangoPermission(com.infiniteautomation.mango.permission.MangoPermission)

Example 100 with MangoPermission

use of com.infiniteautomation.mango.permission.MangoPermission in project ma-core-public by infiniteautomation.

the class DataPointService method getReadPermission.

/**
 * Get the read permission for this data point
 */
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

MangoPermission (com.infiniteautomation.mango.permission.MangoPermission)164 Role (com.serotonin.m2m2.vo.role.Role)38 HashSet (java.util.HashSet)35 Set (java.util.Set)32 HashMap (java.util.HashMap)24 PermissionDefinition (com.serotonin.m2m2.module.PermissionDefinition)21 NotFoundException (com.infiniteautomation.mango.util.exception.NotFoundException)19 JsonException (com.serotonin.json.JsonException)18 ValidationException (com.infiniteautomation.mango.util.exception.ValidationException)15 JsonValue (com.serotonin.json.type.JsonValue)13 TranslatableJsonException (com.serotonin.m2m2.i18n.TranslatableJsonException)13 JsonArray (com.serotonin.json.type.JsonArray)11 IOException (java.io.IOException)11 Test (org.junit.Test)11 ArrayList (java.util.ArrayList)10 User (com.serotonin.m2m2.vo.User)9 JsonObject (com.serotonin.json.type.JsonObject)8 DataSourceVO (com.serotonin.m2m2.vo.dataSource.DataSourceVO)7 ResultSet (java.sql.ResultSet)7 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)6