Mercurial > dive4elements > river
comparison gwt-client/src/main/java/org/dive4elements/river/client/server/UserServiceImpl.java @ 5838:5aa05a7a34b7
Rename modules to more fitting names.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Thu, 25 Apr 2013 15:23:37 +0200 |
parents | flys-client/src/main/java/org/dive4elements/river/client/server/UserServiceImpl.java@821a02bbfb4e |
children | 172338b1407f |
comparison
equal
deleted
inserted
replaced
5837:d9901a08d0a6 | 5838:5aa05a7a34b7 |
---|---|
1 package org.dive4elements.river.client.server; | |
2 | |
3 import javax.servlet.http.HttpSession; | |
4 | |
5 import org.w3c.dom.Element; | |
6 | |
7 import org.apache.log4j.Logger; | |
8 | |
9 import org.dive4elements.artifacts.common.ArtifactNamespaceContext; | |
10 | |
11 import org.dive4elements.artifacts.httpclient.exceptions.ConnectionException; | |
12 | |
13 import org.dive4elements.river.client.client.services.UserService; | |
14 import org.dive4elements.river.client.server.auth.UserClient; | |
15 import org.dive4elements.river.client.shared.exceptions.AuthenticationException; | |
16 import org.dive4elements.river.client.shared.model.DefaultUser; | |
17 import org.dive4elements.river.client.shared.model.User; | |
18 | |
19 /** | |
20 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | |
21 */ | |
22 public class UserServiceImpl | |
23 extends RemoteServiceServlet | |
24 implements UserService | |
25 { | |
26 /** Private logger. */ | |
27 private static final Logger logger = Logger.getLogger(UserServiceImpl.class); | |
28 | |
29 public static final String ERROR_NO_SUCH_USER = "error_no_such_user"; | |
30 | |
31 public static final String ERROR_NO_USERS = "error_no_users"; | |
32 | |
33 public User getCurrentUser(String locale) | |
34 throws AuthenticationException | |
35 { | |
36 String url = getServletContext().getInitParameter("server-url"); | |
37 | |
38 UserClient client = new UserClient(url); | |
39 org.dive4elements.river.client.server.auth.User loginuser = getUser(); | |
40 | |
41 if (loginuser == null) { | |
42 logger.debug("no session user"); | |
43 throw new AuthenticationException(ERROR_NO_SUCH_USER); | |
44 } | |
45 | |
46 try { | |
47 Element user = client.findUser(loginuser); | |
48 | |
49 if (user != null) { | |
50 String uuid = user.getAttributeNS( | |
51 ArtifactNamespaceContext.NAMESPACE_URI, "uuid"); | |
52 String name = user.getAttributeNS( | |
53 ArtifactNamespaceContext.NAMESPACE_URI, "name"); | |
54 | |
55 return new DefaultUser(uuid, name); | |
56 } | |
57 } | |
58 catch (ConnectionException ce) { | |
59 logger.error(ce, ce); | |
60 } | |
61 | |
62 logger.error("No users existing in the server."); | |
63 throw new AuthenticationException(ERROR_NO_USERS); | |
64 } | |
65 | |
66 public void logoutCurrentUser() { | |
67 HttpSession session = this.getThreadLocalRequest().getSession(); | |
68 session.setAttribute("user", null); | |
69 } | |
70 } | |
71 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |