Search in sources :

Example 46 with RestAccessControl

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);
}
Also used : ComponentUsage(org.entando.entando.web.component.ComponentUsage) RestAccessControl(org.entando.entando.web.common.annotation.RestAccessControl)

Example 47 with RestAccessControl

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);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) GroupDto(org.entando.entando.aps.system.services.group.model.GroupDto) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException) RestAccessControl(org.entando.entando.web.common.annotation.RestAccessControl)

Example 48 with RestAccessControl

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;
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) RestAccessControl(org.entando.entando.web.common.annotation.RestAccessControl) HandlerMethod(org.springframework.web.method.HandlerMethod)

Example 49 with RestAccessControl

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);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) PagesStatusDto(org.entando.entando.aps.system.services.page.model.PagesStatusDto) RestAccessControl(org.entando.entando.web.common.annotation.RestAccessControl) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 50 with RestAccessControl

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);
}
Also used : DataModelDto(org.entando.entando.aps.system.services.dataobjectmodel.model.DataModelDto) ResponseEntity(org.springframework.http.ResponseEntity) ResourceNotFoundException(org.entando.entando.aps.system.exception.ResourceNotFoundException) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException) RestAccessControl(org.entando.entando.web.common.annotation.RestAccessControl) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

RestAccessControl (org.entando.entando.web.common.annotation.RestAccessControl)118 ResponseEntity (org.springframework.http.ResponseEntity)108 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)84 ValidationGenericException (org.entando.entando.web.common.exceptions.ValidationGenericException)45 RestResponse (org.entando.entando.web.common.model.RestResponse)42 HashMap (java.util.HashMap)36 ResourceNotFoundException (org.entando.entando.aps.system.exception.ResourceNotFoundException)9 ActivityStreamAuditable (org.entando.entando.web.common.annotation.ActivityStreamAuditable)9 PageDto (org.entando.entando.aps.system.services.page.model.PageDto)8 UserDto (org.entando.entando.aps.system.services.user.model.UserDto)7 ArrayList (java.util.ArrayList)6 DataModelDto (org.entando.entando.aps.system.services.dataobjectmodel.model.DataModelDto)6 WidgetConfigurationDto (org.entando.entando.aps.system.services.page.model.WidgetConfigurationDto)5 RoleDto (org.entando.entando.aps.system.services.role.model.RoleDto)5 ActionLogRecordDto (org.entando.entando.aps.system.services.actionlog.model.ActionLogRecordDto)4 CategoryDto (org.entando.entando.aps.system.services.category.model.CategoryDto)4 LabelDto (org.entando.entando.aps.system.services.label.model.LabelDto)4 PageConfigurationDto (org.entando.entando.aps.system.services.page.model.PageConfigurationDto)4 ValidationConflictException (org.entando.entando.web.common.exceptions.ValidationConflictException)4 DataTypeDto (org.entando.entando.aps.system.services.dataobject.model.DataTypeDto)3