use of com.serotonin.m2m2.vo.permission.PermissionHolder in project ma-modules-public by infiniteautomation.
the class AbstractPublishedPointModelMapping method map.
@Override
public MODEL map(Object from, PermissionHolder user, RestModelMapper mapper) {
VO vo = (VO) from;
MODEL model = null;
try {
model = toClass().getDeclaredConstructor().newInstance();
setModelProperties(model, vo, user, mapper);
return model;
} catch (Exception e) {
throw new RuntimeException("Failed to create model", e);
}
}
use of com.serotonin.m2m2.vo.permission.PermissionHolder in project ma-modules-public by infiniteautomation.
the class TestingRestController method insertPersistentSession.
@ApiOperation(value = "Create a persistent session entry")
@RequestMapping(method = RequestMethod.POST, value = { "/persistent-session" })
public ResponseEntity<MangoSessionDataModel> insertPersistentSession(@RequestBody MangoSessionDataModel model, @AuthenticationPrincipal PermissionHolder user, HttpServletRequest request) {
// Fill in some helpful pieces if they are missing
if (model.getContextPath() == null) {
model.setContextPath(sessionDataStore.getSessionContext().getCanonicalContextPath());
}
if (model.getVirtualHost() == null) {
model.setVirtualHost(sessionDataStore.getSessionContext().getVhost());
}
HttpSession session = request.getSession(false);
if (model.getLastAccessTime() == null) {
model.setLastAccessTime(new Date(session.getLastAccessedTime()));
}
if (model.getCreateTime() == null) {
model.setCreateTime(new Date(session.getCreationTime()));
}
sessionDataStore.add(modelMapper.unMap(model, MangoSessionDataVO.class, user));
return new ResponseEntity<>(model, HttpStatus.CREATED);
}
use of com.serotonin.m2m2.vo.permission.PermissionHolder in project ma-modules-public by infiniteautomation.
the class TranslationsController method publicNamespacedTranslations.
@ApiOperation(value = "Get translations for public namespaces", notes = "Namespace must be base , ie public not public.messages. Returns sub-namespaces too. For > 1 use comma common,public")
@RequestMapping(method = RequestMethod.GET, value = "/public/{namespaces}")
@AnonymousAccess
public TranslationsModel publicNamespacedTranslations(@ApiParam(value = "Message Namespaces, simmilar to java package structure", allowMultiple = true) @PathVariable String[] namespaces, @ApiParam(value = "Language for translation (must have language pack installed)", allowMultiple = false) @RequestParam(value = "language", required = false) String language, @ApiParam(value = "Use server language for translation", allowMultiple = false) @RequestParam(value = "server", required = false, defaultValue = "false") boolean server, @RequestParam(value = "browser", required = false, defaultValue = "false") boolean browser, @AuthenticationPrincipal PermissionHolder user, HttpServletRequest request) {
// Confirm the requested namespace is indeed public
for (String namespace : namespaces) {
if (!this.publicNamespaces.contains(namespace)) {
throw new BadRequestException();
}
}
TranslationsModel resultMap = new TranslationsModel();
Locale locale = this.getLocale(language, server, browser, request, user);
resultMap.setLocale(locale.toLanguageTag());
resultMap.setTranslations(getTranslationMap(namespaces, locale));
resultMap.setNamespaces(namespaces);
return resultMap;
}
use of com.serotonin.m2m2.vo.permission.PermissionHolder in project ma-modules-public by infiniteautomation.
the class UserRestController method updateUser.
@ApiOperation(value = "Update User", notes = "Admin or Update Self only", response = UserModel.class)
@RequestMapping(method = RequestMethod.PUT, value = "/{username}")
public ResponseEntity<UserModel> updateUser(@PathVariable String username, @ApiParam(value = "User", required = true) @RequestBody UserModel model, @AuthenticationPrincipal PermissionHolder user, HttpServletRequest request, UriComponentsBuilder builder, Authentication authentication) {
User existing = service.get(username);
User currentUser = user.getUser();
if (currentUser != null && existing.getId() == currentUser.getId() && !(authentication instanceof UsernamePasswordAuthenticationToken))
throw new PermissionException(new TranslatableMessage("rest.error.usernamePasswordOnly"), user);
User update = service.update(existing.getId(), model.toVO());
sessionRegistry.userUpdated(request, update);
URI location = builder.path("/users/{username}").buildAndExpand(update.getUsername()).toUri();
HttpHeaders headers = new HttpHeaders();
headers.setLocation(location);
return new ResponseEntity<>(new UserModel(update), headers, HttpStatus.OK);
}
use of com.serotonin.m2m2.vo.permission.PermissionHolder in project ma-modules-public by infiniteautomation.
the class UserRestController method exportQuery.
@ApiOperation(value = "Export formatted for Configuration Import by supplying an RQL query", notes = "User must have read permission")
@RequestMapping(method = RequestMethod.GET, value = "/export", produces = MediaTypes.SEROTONIN_JSON_VALUE)
public Map<String, JsonStreamedArray> exportQuery(HttpServletRequest request, @AuthenticationPrincipal PermissionHolder user) {
ASTNode rql = RQLUtils.parseRQLtoAST(request.getQueryString());
Map<String, JsonStreamedArray> export = new HashMap<>();
if (!permissionService.hasAdminRole(user)) {
User currentUser = user.getUser();
rql = RQLUtils.addAndRestriction(rql, new ASTNode("eq", "id", currentUser == null ? Common.NEW_ID : currentUser.getId()));
}
export.put("users", new StreamedSeroJsonVORqlQuery<>(service, rql, null, null, null));
return export;
}
Aggregations