diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2015-05-10 18:11:40 +1200 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2015-05-10 18:11:40 +1200 |
commit | bd09a39f12c4471bdc342e5a16fbabdffdc645d1 (patch) | |
tree | db94476ee604c2026c5653975c526352093d5628 /src/org/traccar/http/BaseServlet.java | |
parent | 953852e6e984f8a639cf1a5ac4116fff755d538a (diff) | |
download | trackermap-server-bd09a39f12c4471bdc342e5a16fbabdffdc645d1.tar.gz trackermap-server-bd09a39f12c4471bdc342e5a16fbabdffdc645d1.tar.bz2 trackermap-server-bd09a39f12c4471bdc342e5a16fbabdffdc645d1.zip |
Refactor web app architecture
Diffstat (limited to 'src/org/traccar/http/BaseServlet.java')
-rw-r--r-- | src/org/traccar/http/BaseServlet.java | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/src/org/traccar/http/BaseServlet.java b/src/org/traccar/http/BaseServlet.java index 9249b33d8..122dbe70b 100644 --- a/src/org/traccar/http/BaseServlet.java +++ b/src/org/traccar/http/BaseServlet.java @@ -26,10 +26,11 @@ import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; +import org.traccar.model.User; public abstract class BaseServlet extends HttpServlet { - public static final String USER_ID = "userId"; + public static final String USER_KEY = "user"; @Override protected final void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { @@ -46,16 +47,16 @@ public abstract class BaseServlet extends HttpServlet { protected abstract boolean handle(String command, HttpServletRequest req, HttpServletResponse resp) throws Exception; public long getUserId(HttpSession session) { - Long userId = (Long) session.getAttribute(USER_ID); - if (userId == null) { + User user = (User) session.getAttribute(USER_KEY); + if (user == null) { throw new AccessControlException("User is not logged in"); } - return userId; + return user.getId(); } - public void sendResponse(Writer writer) throws IOException { + public void sendResponse(Writer writer, boolean success) throws IOException { JsonObjectBuilder result = Json.createObjectBuilder(); - result.add("success", true); + result.add("success", success); writer.write(result.build().toString()); } |