Search in sources :

Example 16 with ScriptPermissions

use of com.infiniteautomation.mango.util.script.ScriptPermissions in project ma-core-public by infiniteautomation.

the class ScriptPermissionConverter method jsonWrite.

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

Example 17 with ScriptPermissions

use of com.infiniteautomation.mango.util.script.ScriptPermissions in project ma-core-public by infiniteautomation.

the class SetPointEventHandlerVO method readObject.

@SuppressWarnings({ "unchecked", "deprecation" })
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
    int ver = in.readInt();
    // Switch on the version of the class so that version changes can be elegantly handled.
    if (ver == 1) {
        targetPointId = in.readInt();
        activeAction = in.readInt();
        activeValueToSet = SerializationHelper.readSafeUTF(in);
        activePointId = in.readInt();
        inactiveAction = in.readInt();
        inactiveValueToSet = SerializationHelper.readSafeUTF(in);
        inactivePointId = in.readInt();
        activeScript = inactiveScript = null;
        additionalContext = new ArrayList<IntStringPair>();
        scriptRoles = new ScriptPermissions();
    } else if (ver == 2) {
        targetPointId = in.readInt();
        activeAction = in.readInt();
        activeValueToSet = SerializationHelper.readSafeUTF(in);
        activePointId = in.readInt();
        inactiveAction = in.readInt();
        inactiveValueToSet = SerializationHelper.readSafeUTF(in);
        inactivePointId = in.readInt();
        activeScript = SerializationHelper.readSafeUTF(in);
        inactiveScript = SerializationHelper.readSafeUTF(in);
        additionalContext = new ArrayList<IntStringPair>();
        scriptRoles = new ScriptPermissions();
    } else if (ver == 3) {
        targetPointId = in.readInt();
        activeAction = in.readInt();
        activeValueToSet = SerializationHelper.readSafeUTF(in);
        activePointId = in.readInt();
        inactiveAction = in.readInt();
        inactiveValueToSet = SerializationHelper.readSafeUTF(in);
        inactivePointId = in.readInt();
        activeScript = SerializationHelper.readSafeUTF(in);
        inactiveScript = SerializationHelper.readSafeUTF(in);
        additionalContext = (List<IntStringPair>) in.readObject();
        com.serotonin.m2m2.rt.script.ScriptPermissions oldPermissions = (com.serotonin.m2m2.rt.script.ScriptPermissions) in.readObject();
        if (oldPermissions != null) {
            // We will be using this in the upgrade so this is temporary and will be used to set
            // the scriptRoles
            legacyScriptRoles = oldPermissions.getAllLegacyPermissions();
            legacyPermissionHolderName = oldPermissions.getPermissionHolderName();
        } else {
            scriptRoles = new ScriptPermissions();
        }
    } else if (ver == 4) {
        targetPointId = in.readInt();
        activeAction = in.readInt();
        activeValueToSet = SerializationHelper.readSafeUTF(in);
        activePointId = in.readInt();
        inactiveAction = in.readInt();
        inactiveValueToSet = SerializationHelper.readSafeUTF(in);
        inactivePointId = in.readInt();
        activeScript = SerializationHelper.readSafeUTF(in);
        inactiveScript = SerializationHelper.readSafeUTF(in);
        additionalContext = (List<IntStringPair>) in.readObject();
        scriptRoles = (ScriptPermissions) in.readObject();
    }
}
Also used : IntStringPair(com.serotonin.db.pair.IntStringPair) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ScriptPermissions(com.infiniteautomation.mango.util.script.ScriptPermissions)

Example 18 with ScriptPermissions

use of com.infiniteautomation.mango.util.script.ScriptPermissions in project ma-core-public by infiniteautomation.

the class EmailEventHandlerDaoTest method newVO.

@Override
EmailEventHandlerVO newVO() {
    EmailEventHandlerVO vo = (EmailEventHandlerVO) ModuleRegistry.getEventHandlerDefinition(EmailEventHandlerDefinition.TYPE_NAME).baseCreateEventHandlerVO();
    vo.setXid(UUID.randomUUID().toString());
    vo.setName(UUID.randomUUID().toString());
    ScriptPermissions permissions = new ScriptPermissions(Collections.singleton(readRole));
    vo.setScriptRoles(permissions);
    List<EventTypeMatcher> eventTypes = Collections.singletonList(new EventTypeMatcher(new MockEventType(readRole)));
    vo.setEventTypes(eventTypes);
    return vo;
}
Also used : EventTypeMatcher(com.serotonin.m2m2.rt.event.type.EventTypeMatcher) EmailEventHandlerVO(com.serotonin.m2m2.vo.event.EmailEventHandlerVO) ScriptPermissions(com.infiniteautomation.mango.util.script.ScriptPermissions) MockEventType(com.serotonin.m2m2.rt.event.type.MockEventType)

Example 19 with ScriptPermissions

use of com.infiniteautomation.mango.util.script.ScriptPermissions in project ma-core-public by infiniteautomation.

the class SetPointEventHandlerServiceTest method testCannotInsertUnauthorizedScriptRole.

@Test
@ExpectValidationException("scriptRoles")
public void testCannotInsertUnauthorizedScriptRole() {
    addRoleToCreatePermission(editRole);
    SetPointEventHandlerVO vo = newVO(editUser);
    vo.setReadPermission(MangoPermission.requireAnyRole(editRole));
    vo.setEditPermission(MangoPermission.requireAnyRole(editRole));
    ScriptPermissions permissions = new ScriptPermissions(Sets.newHashSet(readRole, editRole));
    vo.setScriptRoles(permissions);
    runAs.runAs(editUser, () -> {
        service.insert(vo);
    });
}
Also used : SetPointEventHandlerVO(com.serotonin.m2m2.vo.event.SetPointEventHandlerVO) ScriptPermissions(com.infiniteautomation.mango.util.script.ScriptPermissions) Test(org.junit.Test) ExpectValidationException(com.infiniteautomation.mango.rules.ExpectValidationException)

Example 20 with ScriptPermissions

use of com.infiniteautomation.mango.util.script.ScriptPermissions in project ma-core-public by infiniteautomation.

the class SetPointEventHandlerServiceTest method testCreatePrivilegeSuccess.

@Test
public void testCreatePrivilegeSuccess() {
    SetPointEventHandlerVO vo = newVO(editUser);
    vo.setReadPermission(MangoPermission.requireAnyRole(editRole));
    vo.setEditPermission(MangoPermission.requireAnyRole(editRole));
    ScriptPermissions permissions = new ScriptPermissions(Sets.newHashSet(editRole));
    vo.setScriptRoles(permissions);
    addRoleToCreatePermission(editRole);
    runAs.runAs(editUser, () -> {
        service.insert(vo);
    });
}
Also used : SetPointEventHandlerVO(com.serotonin.m2m2.vo.event.SetPointEventHandlerVO) ScriptPermissions(com.infiniteautomation.mango.util.script.ScriptPermissions) Test(org.junit.Test)

Aggregations

ScriptPermissions (com.infiniteautomation.mango.util.script.ScriptPermissions)45 Test (org.junit.Test)20 EmailEventHandlerVO (com.serotonin.m2m2.vo.event.EmailEventHandlerVO)16 SetPointEventHandlerVO (com.serotonin.m2m2.vo.event.SetPointEventHandlerVO)14 Role (com.serotonin.m2m2.vo.role.Role)12 ExpectValidationException (com.infiniteautomation.mango.rules.ExpectValidationException)8 HashSet (java.util.HashSet)8 IntStringPair (com.serotonin.db.pair.IntStringPair)6 JsonArray (com.serotonin.json.type.JsonArray)6 ArrayList (java.util.ArrayList)6 PermissionService (com.infiniteautomation.mango.spring.service.PermissionService)5 EventTypeMatcher (com.serotonin.m2m2.rt.event.type.EventTypeMatcher)4 MockEventType (com.serotonin.m2m2.rt.event.type.MockEventType)4 List (java.util.List)4 Set (java.util.Set)4 ScriptContextVariableModel (com.infiniteautomation.mango.rest.latest.model.javascript.MangoJavaScriptModel.ScriptContextVariableModel)2 JsonObject (com.serotonin.json.type.JsonObject)2 JsonValue (com.serotonin.json.type.JsonValue)2 RecipientListEntryBean (com.serotonin.m2m2.web.dwr.beans.RecipientListEntryBean)2 ResultSet (java.sql.ResultSet)2