title: Spring MVC Web Request and Android Request to Same Method
body: <p>I have an spring mvc web application in which users login to session "session.setAttribute" classically. Whenever I need loggedin user data I use this data. </p>
  
  <p>Now I want to add android app and what I want to learn do I have to add additional methods for each android request and send user data within it?
  Or Is there away to make a request to same methods.</p>
  
  <p>What is the consept for this kind of cloud apps? Do I have to write different methods for android requests? Because it is not possible session.getAttribute when wemake an android request, it returns null.</p>
  
  <pre><code>User user = userService.getByUserNameAndPassword(userName, password);
      if (user != null) {
  
          if (user.isActive()) {
                  Account account = new Account(user, request.getRemoteAddr());
                  HttpSession httpSession = request.getSession(true);
                  AccountRegistry.add(httpSession);
                  httpSession.setAttribute(Constant.ACCOUNT, account);
                  result.put(Constant.REF, Constant.SUCCESS);
  
          }
  </code></pre>
  
  <p>public class Account {</p>
  
  <pre><code>private UserRightsHandler userRightsService = null;
  private User user;
  private String ipAddress;
  private boolean admin;
  
  public Account(User user, String ipAddress) {
      this.user = user;
      this.ipAddress = ipAddress;
      userRightsService = new UserRightsHandler(user);
      setAdmin(userRightsService.isAdmin());
  }
  
  public UserRightsHandler getUserRightsService() {
      return userRightsService;
  }
  
  public User getUser() {
      return this.user;
  }
  
  public String getIpAddress() {
      return ipAddress;
  }
  
  public boolean isAdmin() {
      return admin;
  }
  
  private void setAdmin(boolean admin) {
      this.admin = admin;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>public class AccountRegistry {</p>
  
  <pre><code>private static final Map&lt;String, HttpSession&gt; sessions = new HashMap&lt;String, HttpSession&gt;();
  
  public static void add(HttpSession session) {
      sessions.put(session.getId(), session);
  }
  
  public static void remove(HttpSession session) {
      if (session != null) {
          sessions.remove(session.getId());
          session.setAttribute(Constant.ACCOUNT, null);
          session.invalidate();
      }
  }
  
  public static HttpSession getByHttpSessionID(String httpSessionID) {
      Set&lt;String&gt; keys = sessions.keySet();
      Iterator it = keys.iterator();
      while (it.hasNext()) {
          String sID = (String) it.next();
          HttpSession session = sessions.get(sID);
          if (sID.equals(httpSessionID)) {
              return session;
          }
      }
      return null;
  }
  
  public static void removeByHttpSessionID(String httpSessionID) {
      HttpSession session = getByHttpSessionID(httpSessionID);
      remove(session);
  }
  
  public static Account getCurrentAccount() {
      HttpServletRequest request = ContextFilter.getCurrentInstance().getRequest();
      HttpSession session = request.getSession();
      return (Account) session.getAttribute(Constant.ACCOUNT);
  }
  </code></pre>
  
  <p>}</p>
  
  <p>@RequestMapping(value = "/changeStatus", method = RequestMethod.POST)
      public @ResponseBody
      String changeStatus(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException {</p>
  
  <pre><code>        User editor = AccountRegistry.getCurrentAccount().getUser();
  
  
      }
  </code></pre>