use of com.infiniteautomation.mango.permission.MangoPermission in project ma-core-public by infiniteautomation.
the class Upgrade29 method convertMailingLists.
private void convertMailingLists(OutputStream out) {
// Add permission id columns
Map<String, String[]> scripts = new HashMap<>();
scripts.put(DatabaseType.MYSQL.name(), mailingListsPermissionMySQL);
scripts.put(DatabaseType.H2.name(), mailingListsPermissionH2);
scripts.put(DatabaseType.MSSQL.name(), mailingListsPermissionMSSQL);
scripts.put(DatabaseType.POSTGRES.name(), mailingListsPermissionMySQL);
runScript(scripts, out);
// Move current permissions to roles
ejt.query("SELECT id, readPermission, editPermission FROM mailingLists", rs -> {
int voId = rs.getInt(1);
// Add role/mapping
MangoPermission readPermissions = PermissionMigration.parseLegacyPermission(rs.getString(2));
Integer readId = getOrCreatePermission(readPermissions).getId();
MangoPermission editPermissions = PermissionMigration.parseLegacyPermission(rs.getString(3));
Integer editId = getOrCreatePermission(editPermissions).getId();
ejt.update("UPDATE mailingLists SET readPermissionId=?, editPermissionId=? WHERE id=?", readId, editId, voId);
});
// Restrict to NOT NULL
scripts = new HashMap<>();
scripts.put(DatabaseType.MYSQL.name(), mailingListsPermissionNotNullMySQL);
scripts.put(DatabaseType.H2.name(), mailingListsPermissionNotNull);
scripts.put(DatabaseType.MSSQL.name(), mailingListsPermissionNotNull);
scripts.put(DatabaseType.POSTGRES.name(), mailingListsPermissionNotNull);
runScript(scripts, out);
// Drop old columns
scripts = new HashMap<>();
scripts.put(DatabaseType.MYSQL.name(), mailingListsDropPermissionsSQL);
scripts.put(DatabaseType.H2.name(), mailingListsDropPermissionsSQL);
scripts.put(DatabaseType.MSSQL.name(), mailingListsDropPermissionsSQL);
scripts.put(DatabaseType.POSTGRES.name(), mailingListsDropPermissionsSQL);
runScript(scripts, out);
}
use of com.infiniteautomation.mango.permission.MangoPermission in project ma-core-public by infiniteautomation.
the class Upgrade29 method convertJsonData.
private void convertJsonData(OutputStream out) {
// Add permission id columns
Map<String, String[]> scripts = new HashMap<>();
scripts.put(DatabaseType.MYSQL.name(), jsonDataPermissionMySQL);
scripts.put(DatabaseType.H2.name(), jsonDataPermissionH2);
scripts.put(DatabaseType.MSSQL.name(), jsonDataPermissionMSSQL);
scripts.put(DatabaseType.POSTGRES.name(), jsonDataPermissionMySQL);
runScript(scripts, out);
// Move current permissions to roles
ejt.query("SELECT id, readPermission, editPermission, publicData FROM jsonData", rs -> {
int voId = rs.getInt(1);
// Add role/mapping
MangoPermission readPermissions = PermissionMigration.parseLegacyPermission(rs.getString(2));
if (BaseDao.charToBool(rs.getString(4))) {
// Is public so add anonymous role
Set<Set<Role>> newRoles = new HashSet<>(readPermissions.getRoles());
newRoles.add(Collections.singleton(PermissionHolder.USER_ROLE));
newRoles.add(Collections.singleton(PermissionHolder.ANONYMOUS_ROLE));
readPermissions = new MangoPermission(newRoles);
}
Integer readId = getOrCreatePermission(readPermissions).getId();
MangoPermission editPermissions = PermissionMigration.parseLegacyPermission(rs.getString(3));
Integer editId = getOrCreatePermission(editPermissions).getId();
ejt.update("UPDATE jsonData SET readPermissionId=?, editPermissionId=? WHERE id=?", readId, editId, voId);
});
// DROP publicData column
scripts = new HashMap<>();
scripts.put(DatabaseType.MYSQL.name(), jsonDataDropPublicDataSQL);
scripts.put(DatabaseType.H2.name(), jsonDataDropPublicDataSQL);
scripts.put(DatabaseType.MSSQL.name(), jsonDataDropPublicDataSQL);
scripts.put(DatabaseType.POSTGRES.name(), jsonDataDropPublicDataSQL);
runScript(scripts, out);
// Restrict to NOT NULL
scripts = new HashMap<>();
scripts.put(DatabaseType.MYSQL.name(), jsonDataPermissionNotNullMySQL);
scripts.put(DatabaseType.H2.name(), jsonDataPermissionNotNull);
scripts.put(DatabaseType.MSSQL.name(), jsonDataPermissionNotNull);
scripts.put(DatabaseType.POSTGRES.name(), jsonDataPermissionNotNull);
runScript(scripts, out);
scripts = new HashMap<>();
scripts.put(DatabaseType.MYSQL.name(), jsonDataDropPermissionsSQL);
scripts.put(DatabaseType.H2.name(), jsonDataDropPermissionsSQL);
scripts.put(DatabaseType.MSSQL.name(), jsonDataDropPermissionsSQL);
scripts.put(DatabaseType.POSTGRES.name(), jsonDataDropPermissionsSQL);
runScript(scripts, out);
}
use of com.infiniteautomation.mango.permission.MangoPermission in project ma-core-public by infiniteautomation.
the class UserDao method deletePostRelationalData.
@Override
public void deletePostRelationalData(User vo) {
super.deletePostRelationalData(vo);
MangoPermission readPermission = vo.getReadPermission();
MangoPermission editPermission = vo.getEditPermission();
permissionService.deletePermissions(readPermission, editPermission);
}
use of com.infiniteautomation.mango.permission.MangoPermission in project ma-core-public by infiniteautomation.
the class PermissionMigration method getOrCreatePermissionNoCache.
default MangoPermission getOrCreatePermissionNoCache(MangoPermission permission) {
if (permission.getId() != null) {
return permission;
}
return getTransactionTemplate().execute(tx -> {
Set<Integer> mintermIds = new HashSet<>();
Set<Set<Role>> minterms = new HashSet<>();
for (Set<Role> minterm : permission.getRoles()) {
Set<Role> savedRoles = new HashSet<>();
for (Role role : minterm) {
savedRoles.add(getOrCreateRole(role));
}
mintermIds.add(getOrCreateMinterm(savedRoles));
}
Integer id = getOrCreatePermission(mintermIds);
MangoPermission saved = new MangoPermission(minterms);
return saved.withId(id);
});
}
use of com.infiniteautomation.mango.permission.MangoPermission in project ma-core-public by infiniteautomation.
the class ScriptService method evalScript.
private EvalResult evalScript(ScriptAndEngine scriptAndEngine, EvalContext evalContext) {
MangoScript script = scriptAndEngine.script;
ScriptEngine engine = scriptAndEngine.engine;
ScriptEngineDefinition engineDefinition = scriptAndEngine.engineDefinition;
ScriptContext context = engine.getContext();
Bindings engineBindings = context.getBindings(ScriptContext.ENGINE_SCOPE);
engineBindings.putAll(evalContext.bindings);
context.setWriter(evalContext.writer);
context.setErrorWriter(evalContext.errorWriter);
context.setReader(evalContext.reader);
String scriptFilename = script.getScriptFilename();
if (scriptFilename != null) {
engineBindings.put(ScriptEngine.FILENAME, scriptFilename);
} else {
String scriptName = script.getScriptName();
String fileName = scriptName;
List<String> extensions = engine.getFactory().getExtensions();
boolean hasExtension = extensions.stream().anyMatch(e -> scriptName.endsWith("." + e));
if (!hasExtension && !extensions.isEmpty()) {
fileName += "." + extensions.get(0);
}
engineBindings.put(ScriptEngine.FILENAME, fileName);
}
for (ScriptBindingsDefinition bindingsDef : bindingsDefinitions) {
MangoPermission permission = bindingsDef.requiredPermission();
if (permissionService.hasPermission(script, permission)) {
bindingsDef.addBindings(script, engineBindings, scriptAndEngine.synchronizationObject, engineDefinition);
}
}
return this.runAs.runAs(script, () -> {
try {
Object value;
if (script instanceof CompiledMangoScript) {
value = ((CompiledMangoScript) script).compiled.eval();
} else {
try (Reader reader = script.readScript()) {
value = engine.eval(reader);
}
}
return new EvalResult(value, engineBindings);
} catch (ScriptException e) {
throw new ScriptEvalException(e, engineDefinition.extractSourceLocation(e));
} catch (IOException e) {
throw new ScriptIOException(e);
}
});
}
Aggregations