Search in sources :

Example 71 with RestAccessControl

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

Example 72 with RestAccessControl

use of org.entando.entando.web.common.annotation.RestAccessControl 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);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) RestResponse(org.entando.entando.web.common.model.RestResponse) UserAuthorityDto(org.entando.entando.aps.system.services.user.model.UserAuthorityDto) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException) RestAccessControl(org.entando.entando.web.common.annotation.RestAccessControl) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 73 with RestAccessControl

use of org.entando.entando.web.common.annotation.RestAccessControl 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);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) RestResponse(org.entando.entando.web.common.model.RestResponse) UserAuthorityDto(org.entando.entando.aps.system.services.user.model.UserAuthorityDto) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException) RestAccessControl(org.entando.entando.web.common.annotation.RestAccessControl) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 74 with RestAccessControl

use of org.entando.entando.web.common.annotation.RestAccessControl in project entando-core by entando.

the class ProfileTypeController method deleteDataType.

@RestAccessControl(permission = Permission.SUPERUSER)
@RequestMapping(value = "/{profileTypeCode}", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<RestResponse> deleteDataType(@PathVariable String profileTypeCode) throws ApsSystemException {
    logger.debug("Deleting profile type -> {}", profileTypeCode);
    this.getUserProfileTypeService().deleteUserProfileType(profileTypeCode);
    Map<String, String> result = new HashMap<>();
    result.put("code", profileTypeCode);
    return new ResponseEntity<>(new RestResponse(result), HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) HashMap(java.util.HashMap) RestResponse(org.entando.entando.web.common.model.RestResponse) RestAccessControl(org.entando.entando.web.common.annotation.RestAccessControl) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 75 with RestAccessControl

use of org.entando.entando.web.common.annotation.RestAccessControl in project entando-core by entando.

the class ProfileTypeController method getUserProfileTypes.

@RestAccessControl(permission = Permission.SUPERUSER)
@RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<RestResponse> getUserProfileTypes(RestListRequest requestList) throws JsonProcessingException {
    this.getProfileTypeValidator().validateRestListRequest(requestList);
    PagedMetadata<EntityTypeShortDto> result = this.getUserProfileTypeService().getShortUserProfileTypes(requestList);
    logger.debug("Main Response -> {}", result);
    this.getProfileTypeValidator().validateRestListResult(requestList, result);
    return new ResponseEntity<>(new RestResponse(result.getBody(), null, result), HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) RestResponse(org.entando.entando.web.common.model.RestResponse) EntityTypeShortDto(org.entando.entando.aps.system.services.entity.model.EntityTypeShortDto) 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