@Override public WUser isAuthorized() throws IllegalArgumentException { Logger.getLogger(getClass()).debug("called isAuthorized()"); if (Session.Instance().getValue(this, USER_TOKEN) != null) { final String authToken = Session.Instance().getValue(this, USER_TOKEN).toString(); WUser user = new WUser(); user.setToken(authToken); return user; } return null; }
@Override public WUser login(WUser user) throws IllegalArgumentException { Logger.getLogger(getClass()).debug("called login()"); JsonLoginRequest request = new JsonLoginRequest(user.getLogin(), user.getPassword(), serverUrl); JsonLoginResponse response = new JsonLoginResponse(); response.parseJson(request.doRequest()); if (response.getAuthString() == null) { return null; } else { WUser newUser = new WUser(user.getLogin(), user.getPassword()); newUser.setToken(response.getAuthString()); newUser.setStatus(Response.STATUS_SUCCES); Session.Instance().addValue(this, USER_TOKEN, newUser.getToken()); return newUser; } }
@Override public boolean logout() throws IllegalArgumentException { Session.Instance().removeValue(this, USER_TOKEN); return true; }