Search in sources :

Example 76 with ResponseEntity

use of org.springframework.http.ResponseEntity in project entando-core by entando.

the class RoleController method getRoleReferences.

@RestAccessControl(permission = Permission.SUPERUSER)
@RequestMapping(value = "/{roleCode}/userreferences", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<RestResponse> getRoleReferences(@PathVariable String roleCode, RestListRequest requestList) {
    logger.debug("loading user references for role {}", roleCode);
    PagedMetadata<UserDto> result = this.getRoleService().getRoleReferences(roleCode, 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 77 with ResponseEntity

use of org.springframework.http.ResponseEntity in project entando-core by entando.

the class ReloadConfigurationController method reloadConfiguration.

@RestAccessControl(permission = Permission.SUPERUSER)
@RequestMapping(method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<RestResponse> reloadConfiguration(HttpServletRequest request) throws Throwable {
    logger.debug("reload configuration: start..");
    ApsWebApplicationUtils.executeSystemRefresh(request);
    logger.debug("reload configuration: done!");
    Map<String, String> result = new HashMap<>();
    result.put("status", "success");
    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 78 with ResponseEntity

use of org.springframework.http.ResponseEntity in project entando-core by entando.

the class UserController method updateUser.

@RestAccessControl(permission = Permission.MANAGE_USERS)
@RequestMapping(value = "/{username}", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> updateUser(@PathVariable String username, @Valid @RequestBody UserRequest userRequest, BindingResult bindingResult) {
    logger.debug("updating user {} with request {}", username, userRequest);
    // field validations
    if (bindingResult.hasErrors()) {
        throw new ValidationGenericException(bindingResult);
    }
    this.getUserValidator().validateBody(username, userRequest.getUsername(), bindingResult);
    if (bindingResult.hasErrors()) {
        throw new ValidationGenericException(bindingResult);
    }
    this.getUserValidator().validatePassword(username, userRequest.getPassword(), bindingResult);
    if (bindingResult.hasErrors()) {
        throw new ValidationGenericException(bindingResult);
    }
    UserDto user = this.getUserService().updateUser(userRequest);
    return new ResponseEntity<>(new RestResponse(user), 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) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException) RestAccessControl(org.entando.entando.web.common.annotation.RestAccessControl) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 79 with ResponseEntity

use of org.springframework.http.ResponseEntity in project entando-core by entando.

the class WidgetController method getWidgets.

@RestAccessControl(permission = Permission.SUPERUSER)
@RequestMapping(value = "/widgets", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<RestResponse> getWidgets(RestListRequest requestList) {
    logger.trace("get widget list {}", requestList);
    this.getWidgetValidator().validateRestListRequest(requestList);
    PagedMetadata<WidgetDto> result = this.widgetService.getWidgets(requestList);
    this.getWidgetValidator().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) WidgetDto(org.entando.entando.aps.system.services.widgettype.model.WidgetDto) RestAccessControl(org.entando.entando.web.common.annotation.RestAccessControl) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 80 with ResponseEntity

use of org.springframework.http.ResponseEntity in project webofneeds by researchstudio-sat.

the class RestUserController method isSignedIn.

/**
 * Method only accessible if the user's still signed in / the session's still valid -> Use it to check the session cookie.
 */
// * @param user user object
// * @param request
// * @param response
// * @return
// 
@ResponseBody
@RequestMapping(value = "/isSignedIn", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.GET)
@Transactional(propagation = Propagation.REQUIRED)
public // public ResponseEntity isSignedIn(@RequestBody User user, HttpServletRequest request, HttpServletResponse response) {
ResponseEntity isSignedIn(HttpServletRequest request, HttpServletResponse response) {
    // Execution will only get here, if the session is still valid, so sending OK here is enough. Spring sends an error
    // code by itself if the session isn't valid any more
    SecurityContext context = SecurityContextHolder.getContext();
    Authentication authentication = null;
    if (context != null) {
        authentication = context.getAuthentication();
    }
    if (authentication == null) {
        authentication = rememberMeServices.autoLogin(request, response);
    } else if (authentication instanceof AnonymousAuthenticationToken) {
        // if we're anonymous, try to see if we can reactivate a remember-me session
        Authentication anonAuth = authentication;
        authentication = rememberMeServices.autoLogin(request, response);
        if (authentication == null) {
            authentication = anonAuth;
        }
    }
    if (authentication == null) {
        return new ResponseEntity("\"User not signed in.\"", HttpStatus.UNAUTHORIZED);
    } else if ("anonymousUser".equals(authentication.getPrincipal())) {
        return new ResponseEntity("\"User not signed in.\"", HttpStatus.UNAUTHORIZED);
    } else {
        User user = ((KeystoreEnabledUserDetails) authentication.getPrincipal()).getUser();
        Map values = new HashMap<String, String>();
        values.put("username", user.getUsername());
        values.put("authorities", user.getAuthorities());
        values.put("role", user.getRole());
        SecurityContextHolder.getContext().setAuthentication(authentication);
        return new ResponseEntity<Map>(values, HttpStatus.OK);
    }
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) User(won.owner.model.User) Authentication(org.springframework.security.core.Authentication) SecurityContext(org.springframework.security.core.context.SecurityContext) CheapInsecureRandomString(won.protocol.util.CheapInsecureRandomString) AnonymousAuthenticationToken(org.springframework.security.authentication.AnonymousAuthenticationToken) Map(java.util.Map) HashMap(java.util.HashMap) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

ResponseEntity (org.springframework.http.ResponseEntity)1188 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)419 HttpHeaders (org.springframework.http.HttpHeaders)398 Test (org.junit.Test)120 ApiOperation (io.swagger.annotations.ApiOperation)116 RestAccessControl (org.entando.entando.web.common.annotation.RestAccessControl)108 HashMap (java.util.HashMap)104 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)103 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)98 HttpStatus (org.springframework.http.HttpStatus)88 ExceptionHandler (org.springframework.web.bind.annotation.ExceptionHandler)85 ArrayList (java.util.ArrayList)80 GetMapping (org.springframework.web.bind.annotation.GetMapping)79 Timed (com.codahale.metrics.annotation.Timed)68 IOException (java.io.IOException)67 List (java.util.List)65 URI (java.net.URI)49 MediaType (org.springframework.http.MediaType)48 Test (org.junit.jupiter.api.Test)46 HttpEntity (org.springframework.http.HttpEntity)46