Search in sources :

Example 11 with MangoPermission

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

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 12 with MangoPermission

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

the class MangoPermissionConverter method jsonWrite.

@Override
public void jsonWrite(JsonWriter writer, Object value) throws IOException, 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);
    }
    writer.writeObject(outerRolesArray);
}
Also used : JsonArray(com.serotonin.json.type.JsonArray) Role(com.serotonin.m2m2.vo.role.Role) MangoPermission(com.infiniteautomation.mango.permission.MangoPermission)

Example 13 with MangoPermission

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

the class EmailEventHandlerServiceTest method addRoleToCreatePermission.

void addRoleToCreatePermission(Role vo) {
    PermissionDefinition def = ModuleRegistry.getPermissionDefinition(EventHandlerCreatePermission.PERMISSION);
    Set<Set<Role>> roleSet = def.getPermission().getRoles();
    Set<Set<Role>> newRoles = new HashSet<>();
    newRoles.add(Collections.singleton(vo));
    for (Set<Role> roles : roleSet) {
        newRoles.add(new HashSet<>(roles));
    }
    Common.getBean(SystemPermissionService.class).update(new MangoPermission(newRoles), def);
}
Also used : Role(com.serotonin.m2m2.vo.role.Role) PermissionDefinition(com.serotonin.m2m2.module.PermissionDefinition) HashSet(java.util.HashSet) Set(java.util.Set) MangoPermission(com.infiniteautomation.mango.permission.MangoPermission) HashSet(java.util.HashSet)

Example 14 with MangoPermission

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

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 15 with MangoPermission

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

the class SetPointEventHandlerServiceTest method addRoleToCreatePermission.

void addRoleToCreatePermission(Role vo) {
    PermissionDefinition def = ModuleRegistry.getPermissionDefinition(EventHandlerCreatePermission.PERMISSION);
    Set<Set<Role>> roleSet = def.getPermission().getRoles();
    Set<Set<Role>> newRoles = new HashSet<>();
    newRoles.add(Collections.singleton(vo));
    for (Set<Role> roles : roleSet) {
        newRoles.add(new HashSet<>(roles));
    }
    Common.getBean(SystemPermissionService.class).update(new MangoPermission(newRoles), def);
}
Also used : Role(com.serotonin.m2m2.vo.role.Role) PermissionDefinition(com.serotonin.m2m2.module.PermissionDefinition) HashSet(java.util.HashSet) Set(java.util.Set) MangoPermission(com.infiniteautomation.mango.permission.MangoPermission) HashSet(java.util.HashSet)

Aggregations

MangoPermission (com.infiniteautomation.mango.permission.MangoPermission)163 Role (com.serotonin.m2m2.vo.role.Role)38 HashSet (java.util.HashSet)35 Set (java.util.Set)32 HashMap (java.util.HashMap)23 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)10 ArrayList (java.util.ArrayList)10 Test (org.junit.Test)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