use of org.entando.entando.web.common.annotation.RestAccessControl in project entando-core by entando.
the class PageModelController method getComponentUsage.
@ApiOperation("Retrieve pageModel usage count")
@ApiResponses({ @ApiResponse(code = 200, message = "OK") })
@RestAccessControl(permission = Permission.MANAGE_PAGES)
@RequestMapping(value = "/{code}/usage", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<SimpleRestResponse<ComponentUsage>> getComponentUsage(@PathVariable String code) {
logger.trace("get {} usage by code {}", COMPONENT_ID, code);
ComponentUsage usage = ComponentUsage.builder().type(COMPONENT_ID).code(code).usage(pageModelService.getComponentUsage(code)).build();
return new ResponseEntity<>(new SimpleRestResponse<>(usage), HttpStatus.OK);
}
use of org.entando.entando.web.common.annotation.RestAccessControl in project entando-core by entando.
the class GroupController method updateGroup.
@RestAccessControl(permission = Permission.SUPERUSER)
@RequestMapping(value = "/{groupCode}", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<SimpleRestResponse<GroupDto>> updateGroup(@PathVariable String groupCode, @Valid @RequestBody GroupRequest groupRequest, BindingResult bindingResult) {
// field validations
if (bindingResult.hasErrors()) {
throw new ValidationGenericException(bindingResult);
}
this.getGroupValidator().validateBodyName(groupCode, groupRequest, bindingResult);
if (bindingResult.hasErrors()) {
throw new ValidationGenericException(bindingResult);
}
GroupDto group = this.getGroupService().updateGroup(groupCode, groupRequest.getName());
return new ResponseEntity<>(new SimpleRestResponse<>(group), HttpStatus.OK);
}
use of org.entando.entando.web.common.annotation.RestAccessControl in project entando-core by entando.
the class EntandoOauth2Interceptor method preHandle.
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
if (handler instanceof HandlerMethod) {
HandlerMethod method = (HandlerMethod) handler;
if (method.hasMethodAnnotation(RequestMapping.class)) {
UserDetails user = this.extractOAuthParameters(request);
RestAccessControl rqm = method.getMethodAnnotation(RestAccessControl.class);
if (null == rqm) {
return true;
}
this.checkAuthorization(user, rqm.permission(), request);
}
}
return true;
}
use of org.entando.entando.web.common.annotation.RestAccessControl in project entando-core by entando.
the class DashboardController method getPagesStatus.
@RestAccessControl(permission = Permission.ENTER_BACKEND)
@RequestMapping(value = "/pageStatus", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<SimpleRestResponse<PagesStatusDto>> getPagesStatus() {
logger.debug("getting pages status count");
PagesStatusDto result = this.getPageService().getPagesStatus();
return new ResponseEntity<>(new SimpleRestResponse<>(result), HttpStatus.OK);
}
use of org.entando.entando.web.common.annotation.RestAccessControl in project entando-core by entando.
the class DataObjectModelController method updateDataObjectModel.
@RestAccessControl(permission = Permission.SUPERUSER)
@RequestMapping(value = "/{dataModelId}", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<SimpleRestResponse<DataModelDto>> updateDataObjectModel(@PathVariable String dataModelId, @Valid @RequestBody DataObjectModelRequest dataObjectModelRequest, BindingResult bindingResult) throws JsonProcessingException {
logger.debug("Updating data object model -> {}", dataObjectModelRequest.getModelId());
// field validations
if (bindingResult.hasErrors()) {
throw new ValidationGenericException(bindingResult);
}
this.getDataObjectModelValidator().validateBodyName(dataModelId, dataObjectModelRequest, bindingResult);
if (bindingResult.hasErrors()) {
throw new ValidationGenericException(bindingResult);
}
int result = this.getDataObjectModelValidator().validateBody(dataObjectModelRequest, true, bindingResult);
if (bindingResult.hasErrors()) {
if (404 == result) {
if (1 == bindingResult.getFieldErrorCount("type")) {
throw new ResourceNotFoundException(DataObjectModelValidator.ERRCODE_PUT_DATAOBJECTTYPE_DOES_NOT_EXIST, "type", dataObjectModelRequest.getType());
} else {
throw new ResourceNotFoundException(DataObjectModelValidator.ERRCODE_DATAOBJECTMODEL_ALREADY_EXISTS, "modelId", dataObjectModelRequest.getModelId());
}
} else {
throw new ValidationGenericException(bindingResult);
}
}
DataModelDto dataModelDto = this.getDataObjectModelService().updateDataObjectModel(dataObjectModelRequest);
logger.debug("Main Response -> {}", dataModelDto);
return new ResponseEntity<>(new SimpleRestResponse<>(dataModelDto), HttpStatus.OK);
}
Aggregations