ingo@2: package de.intevation.flys.client.server; ingo@2: bjoern@3502: import org.w3c.dom.Element; ingo@25: ingo@1367: import org.apache.log4j.Logger; ingo@1367: ingo@25: import de.intevation.artifacts.common.ArtifactNamespaceContext; ingo@25: ingo@25: import de.intevation.artifacts.httpclient.exceptions.ConnectionException; ingo@2: ingo@2: import de.intevation.flys.client.client.services.UserService; bjoern@3692: import de.intevation.flys.client.server.auth.UserClient; ingo@217: import de.intevation.flys.client.shared.exceptions.AuthenticationException; ingo@25: import de.intevation.flys.client.shared.model.DefaultUser; ingo@25: import de.intevation.flys.client.shared.model.User; ingo@2: ingo@2: /** ingo@2: * @author Ingo Weinzierl ingo@2: */ ingo@2: public class UserServiceImpl ingo@2: extends RemoteServiceServlet ingo@2: implements UserService ingo@2: { felix@3860: /** Private logger. */ ingo@1367: private static final Logger logger = Logger.getLogger(UserServiceImpl.class); ingo@1367: ingo@217: public static final String ERROR_NO_SUCH_USER = "error_no_such_user"; ingo@217: felix@3860: public static final String ERROR_NO_USERS = "error_no_users"; felix@3860: raimund@1425: public User getCurrentUser(String locale) ingo@217: throws AuthenticationException ingo@217: { raimund@1425: String url = getServletContext().getInitParameter("server-url"); raimund@1425: bjoern@3692: UserClient client = new UserClient(url); bjoern@3692: de.intevation.flys.client.server.auth.User loginuser = getUser(); ingo@25: sascha@3695: if (loginuser == null) { sascha@3695: logger.debug("no session user"); sascha@3695: throw new AuthenticationException(ERROR_NO_SUCH_USER); sascha@3695: } sascha@3695: ingo@25: try { bjoern@3692: Element user = client.findUser(loginuser); ingo@25: bjoern@3692: if (user != null) { bjoern@3502: String uuid = user.getAttributeNS( bjoern@3502: ArtifactNamespaceContext.NAMESPACE_URI, "uuid"); bjoern@3502: String name = user.getAttributeNS( bjoern@3502: ArtifactNamespaceContext.NAMESPACE_URI, "name"); ingo@25: ingo@25: return new DefaultUser(uuid, name); ingo@25: } ingo@25: } ingo@25: catch (ConnectionException ce) { ingo@1367: logger.error(ce, ce); ingo@25: } ingo@25: ingo@1367: logger.error("No users existing in the server."); felix@3860: throw new AuthenticationException(ERROR_NO_USERS); ingo@2: } ingo@2: } ingo@2: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :