use of com.infiniteautomation.mango.spring.service.PermissionService in project ma-core-public by MangoAutomation.
the class RoleDao method joinPermissions.
@Override
public <R extends Record> SelectJoinStep<R> joinPermissions(SelectJoinStep<R> select, PermissionHolder user) {
PermissionService permissionService = permissionServiceSupplier.get();
Set<Role> heldRoles = permissionService.getAllInheritedRoles(user);
if (heldRoles.contains(PermissionHolder.SUPERADMIN_ROLE)) {
return select;
}
List<String> xids = heldRoles.stream().map(Role::getXid).collect(Collectors.toList());
return select.innerJoin(DSL.selectOne()).on(table.xid.in(xids));
}
use of com.infiniteautomation.mango.spring.service.PermissionService in project ma-core-public by MangoAutomation.
the class MangoPermissionConverter method jsonRead.
@Override
public Object jsonRead(JsonReader reader, JsonValue jsonValue, Type type) throws JsonException {
Set<Set<Role>> roles = new HashSet<>();
PermissionService permissionService = Common.getBean(PermissionService.class);
if (jsonValue instanceof JsonArray) {
for (JsonValue val : (JsonArray) jsonValue) {
if (val instanceof JsonArray) {
Set<Role> inner = new HashSet<>();
roles.add(inner);
for (JsonValue v : (JsonArray) val) {
Role r = permissionService.getRole(v.toString());
if (r != null) {
inner.add(r);
} else {
inner.add(new Role(Common.NEW_ID, v.toString()));
}
}
} else {
// Just a single string
Role r = permissionService.getRole(val.toString());
if (r != null) {
roles.add(Collections.singleton(r));
} else {
roles.add(Collections.singleton(new Role(Common.NEW_ID, val.toString())));
}
}
}
} else {
for (String role : PermissionService.explodeLegacyPermissionGroups(jsonValue.toString())) {
Role r = permissionService.getRole(role);
if (r != null) {
roles.add(Collections.singleton(r));
} else {
roles.add(Collections.singleton(new Role(Common.NEW_ID, role)));
}
}
}
return new MangoPermission(roles);
}
use of com.infiniteautomation.mango.spring.service.PermissionService in project ma-core-public by MangoAutomation.
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.spring.service.PermissionService in project ma-core-public by MangoAutomation.
the class DataSourceDaoDeadlockDetection method detectDeadlockFromDataSourceDeleteDataPointInsertAndDelete.
/**
* See the deadlock when you insert data source, then point,
* then delete point (outside of transaction) then delete source
*/
@Test
public void detectDeadlockFromDataSourceDeleteDataPointInsertAndDelete() {
// Create data source
// Add data point
// Delete data source
// Create data source
// 25;
int numThreads = 5;
// 100;
int numDataSources = 10;
PermissionService permissionService = Common.getBean(PermissionService.class);
DataSourceService dataSourceService = Common.getBean(DataSourceService.class);
DataPointService dataPointService = Common.getBean(DataPointService.class);
AtomicInteger successes = new AtomicInteger();
AtomicInteger failures = new AtomicInteger();
AtomicInteger running = new AtomicInteger(numThreads);
MutableObject<Exception> failure = new MutableObject<>(null);
for (int i = 0; i < numThreads; i++) {
new Thread() {
@Override
public void run() {
try {
for (int i = 0; i < numDataSources; i++) {
// Create data source
MockDataSourceVO ds = new MockDataSourceVO();
ds.setName(Common.generateXid("Mock "));
dataSourceService.insert(ds);
// Create and save point
DataPointVO dp = createMockDataPoint(ds, new MockPointLocatorVO());
// Delete point
dataPointService.delete(dp.getId());
// Delete data source
dataSourceService.delete(ds.getId());
successes.getAndIncrement();
}
} catch (Exception e) {
e.printStackTrace();
failure.setValue(e);
failures.getAndIncrement();
} finally {
running.decrementAndGet();
}
}
}.start();
}
while (running.get() > 0) {
try {
Thread.sleep(100);
} catch (Exception e) {
}
}
if (failures.get() > 0) {
fail("Ran " + successes.get() + " queries: " + failure.getValue().getMessage());
}
}
use of com.infiniteautomation.mango.spring.service.PermissionService in project ma-core-public by MangoAutomation.
the class DataSourceDaoDeadlockDetection method detectDeadlockFromDataSourceDeleteDataPointInsert.
/**
* See the deadlock when you insert data source, then point,
* then then delete source (which deletes the point inside a transaction)
*/
@Test
public void detectDeadlockFromDataSourceDeleteDataPointInsert() {
// 25;
int numThreads = 5;
// 100;
int numDataSources = 10;
PermissionService permissionService = Common.getBean(PermissionService.class);
DataSourceService dataSourceService = Common.getBean(DataSourceService.class);
AtomicInteger failures = new AtomicInteger();
AtomicInteger successes = new AtomicInteger();
AtomicInteger running = new AtomicInteger(numThreads);
MutableObject<Exception> failure = new MutableObject<>(null);
for (int i = 0; i < numThreads; i++) {
new Thread() {
@Override
public void run() {
try {
for (int i = 0; i < numDataSources; i++) {
// Create data source
MockDataSourceVO ds = new MockDataSourceVO();
ds.setName(Common.generateXid("Mock "));
dataSourceService.insert(ds);
// Create and save point
createMockDataPoint(ds, new MockPointLocatorVO());
// Delete data source
dataSourceService.delete(ds.getId());
successes.getAndIncrement();
}
} catch (Exception e) {
e.printStackTrace();
failure.setValue(e);
failures.getAndIncrement();
} finally {
running.decrementAndGet();
}
}
}.start();
}
while (running.get() > 0) {
try {
Thread.sleep(100);
} catch (Exception e) {
}
}
if (failures.get() > 0) {
fail("Ran " + successes.get() + " queries: " + failure.getValue().getMessage());
}
}
Aggregations