@RequestMapping(value = "/add", method = RequestMethod.POST) public ResponseEntity<DFS_UserDetails> addNewUser( @RequestBody final DFS_UserDetails userDetails) { DFS_UserDetails newUserDetails = null; try { newUserDetails = userDetailsService.createNewUser(userDetails); } catch (DataIntegrityViolationException ex) { logger.debug("|DEBUG| User already exists", ex); return new ResponseEntity<DFS_UserDetails>(newUserDetails, HttpStatus.OK); } return new ResponseEntity<DFS_UserDetails>(newUserDetails, HttpStatus.CREATED); }
@RequestMapping(value = "/{uuid}/enabled/{enabled}", method = RequestMethod.PUT) public ResponseEntity<UserAuthentication> toggleUser( @ApiParam(value = "User UUID", required = true) @RequestParam(value = "uuid", required = true) final Uuid uuid, @ApiParam(value = "enabled", required = true) @RequestParam(value = "enabled", required = true) final boolean enabled) { DFS_UserDetails userDetails = null; UserAuthentication authentication = null; UserAuthorization authorization = null; try { userDetails = userDetailsService.findOne(uuid); authentication = authenticationService.findOneWithUserName(userDetails.getDfsUserName()); authorization = new UserAuthorization(authentication, UserRoles.ROLE_USER); HttpStatus status = HttpStatus.OK; if (enabled == true) { authentication.setEnabled(true); try { status = authenticationService.enableUser(userDetails); } catch (Exception ex) { logger.error("|ERROR| COULD NOT ENABLE USER " + userDetails.getDfsUserName(), ex); } if (status == HttpStatus.OK) authorizationService.authorize(authorization); } else { System.out.println("DISABLED USER CANNOT BE AUTHORIZED"); } } catch (Exception ex) { } return null; }