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);
}
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);
}
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);
}
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);
}
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);
}
}
Aggregations