use of org.entando.entando.web.common.model.RestResponse in project entando-core by entando.
the class RoleController method getRoles.
@RestAccessControl(permission = Permission.SUPERUSER)
@RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<RestResponse> getRoles(RestListRequest requestList) throws JsonProcessingException {
this.getRoleValidator().validateRestListRequest(requestList);
PagedMetadata<RoleDto> result = this.getRoleService().getRoles(requestList);
this.getRoleValidator().validateRestListResult(requestList, result);
logger.debug("loading role list -> {}", result);
return new ResponseEntity<>(new RestResponse(result.getBody(), null, result), HttpStatus.OK);
}
use of org.entando.entando.web.common.model.RestResponse in project entando-core by entando.
the class UserController method deleteUser.
@RestAccessControl(permission = Permission.MANAGE_USERS)
@RequestMapping(value = "/{username}", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> deleteUser(@PathVariable String username) throws ApsSystemException {
logger.debug("deleting {}", username);
this.getUserService().removeUser(username);
Map<String, String> result = new HashMap<>();
result.put("code", username);
return new ResponseEntity<>(new RestResponse(result), HttpStatus.OK);
}
use of org.entando.entando.web.common.model.RestResponse in project entando-core by entando.
the class UserController method getUsers.
@RestAccessControl(permission = Permission.MANAGE_USERS)
@RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> getUsers(RestListRequest requestList) {
logger.debug("getting users details with request {}", requestList);
PagedMetadata<UserDto> result = this.getUserService().getUsers(requestList);
return new ResponseEntity<>(new RestResponse(result.getBody(), null, result), HttpStatus.OK);
}
use of org.entando.entando.web.common.model.RestResponse in project entando-core by entando.
the class UserController method addUserAuthorities.
@RestAccessControl(permission = Permission.MANAGE_USERS)
@RequestMapping(value = "/{target}/authorities", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<RestResponse> addUserAuthorities(@ModelAttribute("user") UserDetails user, @PathVariable String target, @Valid @RequestBody UserAuthoritiesRequest authRequest, BindingResult bindingResult) throws ApsSystemException {
logger.debug("user {} requesting add authorities for username {} with req {}", user.getUsername(), target, authRequest);
// field validations
if (bindingResult.hasErrors()) {
throw new ValidationGenericException(bindingResult);
}
// business validations
getUserValidator().validate(authRequest, bindingResult);
if (bindingResult.hasErrors()) {
throw new ValidationGenericException(bindingResult);
}
getUserValidator().validateUpdateSelf(target, user.getUsername(), bindingResult);
if (bindingResult.hasErrors()) {
throw new ValidationGenericException(bindingResult);
}
List<UserAuthorityDto> authorities = this.getUserService().addUserAuthorities(target, authRequest);
return new ResponseEntity<>(new RestResponse(authorities), HttpStatus.OK);
}
use of org.entando.entando.web.common.model.RestResponse in project entando-core by entando.
the class UserController method updateUserAuthorities.
@RestAccessControl(permission = Permission.MANAGE_USERS)
@RequestMapping(value = "/{target}/authorities", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<RestResponse> updateUserAuthorities(@ModelAttribute("user") UserDetails user, @PathVariable String target, @Valid @RequestBody UserAuthoritiesRequest authRequest, BindingResult bindingResult) {
logger.debug("user {} requesting update authorities for username {} with req {}", user.getUsername(), target, authRequest);
// field validations
if (bindingResult.hasErrors()) {
throw new ValidationGenericException(bindingResult);
}
// business validations
getUserValidator().validate(authRequest, bindingResult);
if (bindingResult.hasErrors()) {
throw new ValidationGenericException(bindingResult);
}
getUserValidator().validateUpdateSelf(target, user.getUsername(), bindingResult);
if (bindingResult.hasErrors()) {
throw new ValidationGenericException(bindingResult);
}
List<UserAuthorityDto> authorities = this.getUserService().addUserAuthorities(target, authRequest);
return new ResponseEntity<>(new RestResponse(authorities), HttpStatus.OK);
}
Aggregations