@RequestMapping(value = "/Users", produces = "application/json", consumes = "application/json", method = POST) public RestEntity writeEntry(@RequestBody RestUser user, HttpServletRequest request) throws RestException { RequestContext requestContext = ControllerUtil.getRequestContext(request); if(requestContext.isSecure()) { if(StringUtils.stringNotEmpty(user.getUsername()) && StringUtils.stringNotEmpty(user.getAllowedHost()) && StringUtils.stringNotEmpty(user.getPassword())) { try { userManager.addUser(requestContext.getUserSession(), user.getUsername(), user.getAllowedHost(), user.getPassword()); return new RestUser(user.getUsername(), user.getAllowedHost(), null); } catch(JasDBStorageException e) { LOG.error("", e); throw new RestException("Unable to create user", e); } } else { throw new RestException("Incomplete user details"); } } else { throw new RestException("Unable to create user, unsecure connection"); } }
public RestUserList(List<String> userList) { users = new ArrayList<>(userList.size()); for(String user: userList) { users.add(new RestUser(user, null, null)); } }
@Override public List<String> getUsers(RemotingContext context) throws RemoteException { ClientResponse clientResponse = doRequest(context, "Users"); try { RestUserList userList = new JsonRestResponseHandler().deserialize(RestUserList.class, clientResponse.getEntityInputStream()); List<String> userNames = new ArrayList<>(); for(RestUser restUser : userList.getUsers()) { userNames.add(restUser.getUsername()); } return userNames; } catch(RestException e) { throw new RemoteException("Unable to retrieve remote user list", e); } }
@Override public void addUser(RemotingContext context, String username, String host, String password) throws RemoteException { try { byte[] serializedUser = toBytes(new RestUser(username, host, password)); doInternalRequest(context, "Users", new HashMap<>(), serializedUser, REQUEST_MODE.POST); } catch(RestException e) { throw new RemoteException("Unable to add user", e); } }