use of com.serotonin.m2m2.vo.permission.PermissionException in project ma-modules-public by infiniteautomation.
the class DataSourceRestController method enableDisable.
@ApiOperation(value = "Enable/disable/restart a data source")
@RequestMapping(method = RequestMethod.PUT, value = "/enable-disable/{xid}")
public ResponseEntity<DataPointModel> enableDisable(@AuthenticationPrincipal User user, @PathVariable String xid, @ApiParam(value = "Enable or disable the data source", required = true, allowMultiple = false) @RequestParam(required = true) boolean enabled, @ApiParam(value = "Restart the data source, enabled must equal true", required = false, defaultValue = "false", allowMultiple = false) @RequestParam(required = false, defaultValue = "false") boolean restart) {
DataSourceVO<?> dsvo = DataSourceDao.instance.getByXid(xid);
if (dsvo == null)
throw new NotFoundRestException();
try {
Permissions.ensureDataSourcePermission(user, dsvo);
} catch (PermissionException e) {
throw new AccessDeniedException("User does not have permission to edit the data source", e);
}
if (enabled && restart) {
dsvo.setEnabled(true);
// saving will restart it
Common.runtimeManager.saveDataSource(dsvo);
} else if (dsvo.isEnabled() != enabled) {
dsvo.setEnabled(enabled);
Common.runtimeManager.saveDataSource(dsvo);
}
return new ResponseEntity<>(HttpStatus.OK);
}
use of com.serotonin.m2m2.vo.permission.PermissionException in project ma-modules-public by infiniteautomation.
the class DataSourceRestController method getDataSource.
@ApiOperation(value = "Get data source by xid", notes = "Only returns data sources available to logged in user")
@RequestMapping(method = RequestMethod.GET, value = "/{xid}", produces = { "application/json" })
public ResponseEntity<AbstractDataSourceModel<?>> getDataSource(HttpServletRequest request, @PathVariable String xid) {
RestProcessResult<AbstractDataSourceModel<?>> result = new RestProcessResult<AbstractDataSourceModel<?>>(HttpStatus.OK);
User user = this.checkUser(request, result);
if (result.isOk()) {
DataSourceVO<?> vo = DataSourceDao.instance.getByXid(xid);
if (vo == null) {
return new ResponseEntity<AbstractDataSourceModel<?>>(HttpStatus.NOT_FOUND);
} else {
try {
if (Permissions.hasDataSourcePermission(user, vo))
return result.createResponseEntity(vo.asModel());
else {
result.addRestMessage(getUnauthorizedMessage());
return result.createResponseEntity();
}
} catch (PermissionException e) {
LOG.warn(e.getMessage(), e);
result.addRestMessage(getUnauthorizedMessage());
return result.createResponseEntity();
}
}
}
return result.createResponseEntity();
}
use of com.serotonin.m2m2.vo.permission.PermissionException in project ma-modules-public by infiniteautomation.
the class PointHierarchyRestController method getPath.
/**
* Get a path to a folder
* @param xid
* @param request
* @return
*/
@ApiOperation(value = "Get path to a point using point's XID", notes = "Points returned based on user priviledges")
@RequestMapping(method = RequestMethod.GET, value = "/path/{xid}", produces = { "application/json" })
public ResponseEntity<List<String>> getPath(@PathVariable String xid, HttpServletRequest request) {
RestProcessResult<List<String>> result = new RestProcessResult<List<String>>(HttpStatus.OK);
PointHierarchy ph = DataPointDao.instance.getPointHierarchy(true);
User user = this.checkUser(request, result);
if (result.isOk()) {
DataPointVO vo = DataPointDao.instance.getByXid(xid);
if (vo == null) {
result.addRestMessage(getDoesNotExistMessage());
return result.createResponseEntity();
}
// Check permissions
try {
if (!Permissions.hasDataPointReadPermission(user, vo)) {
result.addRestMessage(getUnauthorizedMessage());
return result.createResponseEntity();
} else {
return result.createResponseEntity(ph.getPath(vo.getId()));
}
} catch (PermissionException e) {
result.addRestMessage(getUnauthorizedMessage());
return result.createResponseEntity();
}
} else {
return result.createResponseEntity();
}
}
use of com.serotonin.m2m2.vo.permission.PermissionException in project ma-modules-public by infiniteautomation.
the class DataPointSummaryStreamCallback method writeCsv.
@Override
protected void writeCsv(DataPointVO vo) throws IOException {
try {
if (Permissions.hasDataPointReadPermission(user, vo)) {
DataPointSummary model = this.controller.createModel(vo);
this.csvWriter.writeNext(model);
}
} catch (PermissionException e) {
// Munched
}
}
use of com.serotonin.m2m2.vo.permission.PermissionException in project ma-core-public by infiniteautomation.
the class DataSourceEditDwr method exportDataPoint.
@DwrPermission(user = true)
public String exportDataPoint(int dataPointId) {
DataSourceVO<?> ds = Common.getUser().getEditDataSource();
DataPointVO dp = DataPointDao.instance.getDataPoint(dataPointId);
if (dp == null)
return null;
if (dp.getDataSourceId() != ds.getId())
throw new PermissionException(new TranslatableMessage("common.default", "Wrong data source"), Common.getUser());
Map<String, Object> data = new LinkedHashMap<>();
List<DataPointVO> dss = new ArrayList<>();
dss.add(dp);
data.put(ConfigurationExportData.DATA_POINTS, dss);
return EmportDwr.export(data);
}
Aggregations