use of com.infiniteautomation.mango.util.script.ScriptPermissions in project ma-core-public by infiniteautomation.
the class EmailEventHandlerServiceTest method testCannotUpdateUnauthorizedScriptRole.
@Test
@ExpectValidationException("scriptRoles")
public void testCannotUpdateUnauthorizedScriptRole() {
addRoleToCreatePermission(editRole);
EmailEventHandlerVO vo = newVO(editUser);
vo.setReadPermission(MangoPermission.requireAnyRole(editRole));
vo.setEditPermission(MangoPermission.requireAnyRole(editRole));
ScriptPermissions permissions = new ScriptPermissions(Sets.newHashSet(editRole));
vo.setScriptRoles(permissions);
runAs.runAs(editUser, () -> {
EmailEventHandlerVO fromDb = (EmailEventHandlerVO) service.insert(vo);
ScriptPermissions newPermissions = new ScriptPermissions(Sets.newHashSet(readRole, editRole));
fromDb.setScriptRoles(newPermissions);
service.update(fromDb.getId(), fromDb);
});
}
use of com.infiniteautomation.mango.util.script.ScriptPermissions in project ma-core-public by infiniteautomation.
the class EmailEventHandlerServiceTest method testDeleteRoleUpdateVO.
@Test
public void testDeleteRoleUpdateVO() {
EmailEventHandlerVO vo = newVO(readUser);
ScriptPermissions permissions = new ScriptPermissions(Sets.newHashSet(readRole, editRole));
vo.setScriptRoles(permissions);
service.insert(vo);
EmailEventHandlerVO fromDb = (EmailEventHandlerVO) service.get(vo.getId());
assertVoEqual(vo, fromDb);
roleService.delete(editRole.getId());
roleService.delete(readRole.getId());
EmailEventHandlerVO updated = (EmailEventHandlerVO) service.get(fromDb.getId());
fromDb.setScriptRoles(new ScriptPermissions(Collections.emptySet()));
assertVoEqual(fromDb, updated);
}
use of com.infiniteautomation.mango.util.script.ScriptPermissions in project ma-core-public by infiniteautomation.
the class EmailEventHandlerServiceTest method testCreatePrivilegeSuccess.
@Test
public void testCreatePrivilegeSuccess() {
EmailEventHandlerVO 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);
});
}
use of com.infiniteautomation.mango.util.script.ScriptPermissions in project ma-core-public by infiniteautomation.
the class ScriptPermissionConverter method jsonRead.
// TODO Mango 4.2 improve performance with lazy field as PermissionService is not available at construct time
@Override
public Object jsonRead(JsonReader reader, JsonValue jsonValue, Type type) throws JsonException {
Set<Role> roles = new HashSet<>();
PermissionService service = Common.getBean(PermissionService.class);
if (jsonValue instanceof JsonArray) {
for (JsonValue val : (JsonArray) jsonValue) {
// Just a single string
Role r = service.getRole(val.toString());
if (r != null) {
roles.add(r);
} else {
// Let the validation pick this up as a missing role, the response to the user is cleaner
roles.add(new Role(Common.NEW_ID, val.toString()));
}
}
} else if (jsonValue instanceof JsonObject) {
// Could be the super-legacy version with 3 separate sets of roles
JsonObject o = (JsonObject) jsonValue;
Set<String> permissions = new HashSet<>();
permissions.addAll(PermissionService.explodeLegacyPermissionGroups(o.getString(DATA_SOURCE)));
permissions.addAll(PermissionService.explodeLegacyPermissionGroups(o.getString(DATA_POINT_SET)));
permissions.addAll(PermissionService.explodeLegacyPermissionGroups(o.getString(DATA_POINT_READ)));
permissions.addAll(PermissionService.explodeLegacyPermissionGroups(o.getString(CUSTOM)));
for (String role : permissions) {
Role r = service.getRole(role);
if (r != null) {
roles.add(r);
} else {
// Let the validation pick this up as a missing role, the response to the user is cleaner
roles.add(new Role(Common.NEW_ID, role));
}
}
}
return new ScriptPermissions(roles);
}
use of com.infiniteautomation.mango.util.script.ScriptPermissions in project ma-core-public by infiniteautomation.
the class EmailEventHandlerVO method readObject.
@SuppressWarnings({ "unchecked", "deprecation" })
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
// NOTE: after deserialization the recipient lists need to be cleaned of deleted references,
// See MailingListDao.cleanRecipientsList. This happens in the DAO
int ver = in.readInt();
subject = SUBJECT_INCLUDE_EVENT_MESSAGE;
if (ver == 1) {
List<RecipientListEntryBean> legacy = (List<RecipientListEntryBean>) in.readObject();
if (legacy != null) {
activeRecipients = new ArrayList<>();
for (RecipientListEntryBean b : legacy) {
activeRecipients.add(b.createEmailRecipient());
}
}
sendEscalation = in.readBoolean();
repeatEscalations = false;
escalationDelayType = in.readInt();
escalationDelay = in.readInt();
legacy = (List<RecipientListEntryBean>) in.readObject();
if (legacy != null) {
escalationRecipients = new ArrayList<>();
for (RecipientListEntryBean b : legacy) {
escalationRecipients.add(b.createEmailRecipient());
}
}
sendInactive = in.readBoolean();
inactiveOverride = in.readBoolean();
legacy = (List<RecipientListEntryBean>) in.readObject();
if (legacy != null) {
inactiveRecipients = new ArrayList<>();
for (RecipientListEntryBean b : legacy) {
inactiveRecipients.add(b.createEmailRecipient());
}
}
includeSystemInfo = in.readBoolean();
includePointValueCount = in.readInt();
includeLogfile = in.readBoolean();
customTemplate = null;
additionalContext = new ArrayList<IntStringPair>();
scriptRoles = new ScriptPermissions();
script = null;
} else if (ver == 2) {
List<RecipientListEntryBean> legacy = (List<RecipientListEntryBean>) in.readObject();
if (legacy != null) {
activeRecipients = new ArrayList<>();
for (RecipientListEntryBean b : legacy) {
activeRecipients.add(b.createEmailRecipient());
}
}
sendEscalation = in.readBoolean();
repeatEscalations = false;
escalationDelayType = in.readInt();
escalationDelay = in.readInt();
legacy = (List<RecipientListEntryBean>) in.readObject();
if (legacy != null) {
escalationRecipients = new ArrayList<>();
for (RecipientListEntryBean b : legacy) {
escalationRecipients.add(b.createEmailRecipient());
}
}
sendInactive = in.readBoolean();
inactiveOverride = in.readBoolean();
legacy = (List<RecipientListEntryBean>) in.readObject();
if (legacy != null) {
inactiveRecipients = new ArrayList<>();
for (RecipientListEntryBean b : legacy) {
inactiveRecipients.add(b.createEmailRecipient());
}
}
includeSystemInfo = in.readBoolean();
includePointValueCount = in.readInt();
includeLogfile = in.readBoolean();
customTemplate = SerializationHelper.readSafeUTF(in);
additionalContext = new ArrayList<IntStringPair>();
scriptRoles = new ScriptPermissions();
script = null;
} else if (ver == 3) {
List<RecipientListEntryBean> legacy = (List<RecipientListEntryBean>) in.readObject();
if (legacy != null) {
activeRecipients = new ArrayList<>();
for (RecipientListEntryBean b : legacy) {
activeRecipients.add(b.createEmailRecipient());
}
}
sendEscalation = in.readBoolean();
repeatEscalations = false;
escalationDelayType = in.readInt();
escalationDelay = in.readInt();
legacy = (List<RecipientListEntryBean>) in.readObject();
if (legacy != null) {
escalationRecipients = new ArrayList<>();
for (RecipientListEntryBean b : legacy) {
escalationRecipients.add(b.createEmailRecipient());
}
}
sendInactive = in.readBoolean();
inactiveOverride = in.readBoolean();
legacy = (List<RecipientListEntryBean>) in.readObject();
if (legacy != null) {
inactiveRecipients = new ArrayList<>();
for (RecipientListEntryBean b : legacy) {
inactiveRecipients.add(b.createEmailRecipient());
}
}
includeSystemInfo = in.readBoolean();
includePointValueCount = in.readInt();
includeLogfile = in.readBoolean();
customTemplate = SerializationHelper.readSafeUTF(in);
additionalContext = (List<IntStringPair>) in.readObject();
scriptRoles = new ScriptPermissions();
script = null;
} else if (ver == 4) {
List<RecipientListEntryBean> legacy = (List<RecipientListEntryBean>) in.readObject();
if (legacy != null) {
activeRecipients = new ArrayList<>();
for (RecipientListEntryBean b : legacy) {
activeRecipients.add(b.createEmailRecipient());
}
}
sendEscalation = in.readBoolean();
repeatEscalations = false;
escalationDelayType = in.readInt();
escalationDelay = in.readInt();
legacy = (List<RecipientListEntryBean>) in.readObject();
if (legacy != null) {
escalationRecipients = new ArrayList<>();
for (RecipientListEntryBean b : legacy) {
escalationRecipients.add(b.createEmailRecipient());
}
}
sendInactive = in.readBoolean();
legacy = (List<RecipientListEntryBean>) in.readObject();
if (legacy != null) {
inactiveRecipients = new ArrayList<>();
for (RecipientListEntryBean b : legacy) {
inactiveRecipients.add(b.createEmailRecipient());
}
}
includeSystemInfo = in.readBoolean();
includePointValueCount = in.readInt();
includeLogfile = in.readBoolean();
customTemplate = 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();
}
script = SerializationHelper.readSafeUTF(in);
} else if (ver == 5) {
List<RecipientListEntryBean> legacy = (List<RecipientListEntryBean>) in.readObject();
if (legacy != null) {
activeRecipients = new ArrayList<>();
for (RecipientListEntryBean b : legacy) {
activeRecipients.add(b.createEmailRecipient());
}
}
sendEscalation = in.readBoolean();
repeatEscalations = in.readBoolean();
escalationDelayType = in.readInt();
escalationDelay = in.readInt();
legacy = (List<RecipientListEntryBean>) in.readObject();
if (legacy != null) {
escalationRecipients = new ArrayList<>();
for (RecipientListEntryBean b : legacy) {
escalationRecipients.add(b.createEmailRecipient());
}
}
sendInactive = in.readBoolean();
inactiveOverride = in.readBoolean();
legacy = (List<RecipientListEntryBean>) in.readObject();
if (legacy != null) {
inactiveRecipients = new ArrayList<>();
for (RecipientListEntryBean b : legacy) {
inactiveRecipients.add(b.createEmailRecipient());
}
}
includeSystemInfo = in.readBoolean();
includePointValueCount = in.readInt();
includeLogfile = in.readBoolean();
customTemplate = 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();
}
script = SerializationHelper.readSafeUTF(in);
} else if (ver == 6) {
List<RecipientListEntryBean> legacy = (List<RecipientListEntryBean>) in.readObject();
if (legacy != null) {
activeRecipients = new ArrayList<>();
for (RecipientListEntryBean b : legacy) {
activeRecipients.add(b.createEmailRecipient());
}
}
sendEscalation = in.readBoolean();
repeatEscalations = in.readBoolean();
escalationDelayType = in.readInt();
escalationDelay = in.readInt();
legacy = (List<RecipientListEntryBean>) in.readObject();
if (legacy != null) {
escalationRecipients = new ArrayList<>();
for (RecipientListEntryBean b : legacy) {
escalationRecipients.add(b.createEmailRecipient());
}
}
sendInactive = in.readBoolean();
inactiveOverride = in.readBoolean();
legacy = (List<RecipientListEntryBean>) in.readObject();
if (legacy != null) {
inactiveRecipients = new ArrayList<>();
for (RecipientListEntryBean b : legacy) {
inactiveRecipients.add(b.createEmailRecipient());
}
}
includeSystemInfo = in.readBoolean();
includePointValueCount = in.readInt();
includeLogfile = in.readBoolean();
customTemplate = SerializationHelper.readSafeUTF(in);
additionalContext = (List<IntStringPair>) in.readObject();
scriptRoles = (ScriptPermissions) in.readObject();
script = SerializationHelper.readSafeUTF(in);
} else if (ver == 7) {
List<RecipientListEntryBean> legacy = (List<RecipientListEntryBean>) in.readObject();
if (legacy != null) {
activeRecipients = new ArrayList<>();
for (RecipientListEntryBean b : legacy) {
activeRecipients.add(b.createEmailRecipient());
}
}
sendEscalation = in.readBoolean();
repeatEscalations = in.readBoolean();
escalationDelayType = in.readInt();
escalationDelay = in.readInt();
legacy = (List<RecipientListEntryBean>) in.readObject();
if (legacy != null) {
escalationRecipients = new ArrayList<>();
for (RecipientListEntryBean b : legacy) {
escalationRecipients.add(b.createEmailRecipient());
}
}
sendInactive = in.readBoolean();
inactiveOverride = in.readBoolean();
legacy = (List<RecipientListEntryBean>) in.readObject();
if (legacy != null) {
inactiveRecipients = new ArrayList<>();
for (RecipientListEntryBean b : legacy) {
inactiveRecipients.add(b.createEmailRecipient());
}
}
includeSystemInfo = in.readBoolean();
includePointValueCount = in.readInt();
includeLogfile = in.readBoolean();
customTemplate = SerializationHelper.readSafeUTF(in);
additionalContext = (List<IntStringPair>) in.readObject();
scriptRoles = (ScriptPermissions) in.readObject();
script = SerializationHelper.readSafeUTF(in);
subject = in.readInt();
} else if (ver == 8) {
activeRecipients = (List<MailingListRecipient>) in.readObject();
sendEscalation = in.readBoolean();
repeatEscalations = in.readBoolean();
escalationDelayType = in.readInt();
escalationDelay = in.readInt();
escalationRecipients = (List<MailingListRecipient>) in.readObject();
sendInactive = in.readBoolean();
inactiveOverride = in.readBoolean();
inactiveRecipients = (List<MailingListRecipient>) in.readObject();
includeSystemInfo = in.readBoolean();
includePointValueCount = in.readInt();
includeLogfile = in.readBoolean();
customTemplate = SerializationHelper.readSafeUTF(in);
additionalContext = (List<IntStringPair>) in.readObject();
scriptRoles = (ScriptPermissions) in.readObject();
script = SerializationHelper.readSafeUTF(in);
subject = in.readInt();
}
}
Aggregations