teichmann@5861: /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde teichmann@5861: * Software engineering by Intevation GmbH teichmann@5861: * teichmann@5993: * This file is Free Software under the GNU AGPL (>=v3) teichmann@5861: * and comes with ABSOLUTELY NO WARRANTY! Check out the teichmann@5993: * documentation coming with Dive4Elements River for details. teichmann@5861: */ teichmann@5861: teichmann@5835: package org.dive4elements.river.client.server; ingo@2: bjoern@4214: import javax.servlet.http.HttpSession; bjoern@4214: bjoern@3502: import org.w3c.dom.Element; ingo@25: ingo@1367: import org.apache.log4j.Logger; ingo@1367: teichmann@5835: import org.dive4elements.artifacts.common.ArtifactNamespaceContext; ingo@2: teichmann@5835: import org.dive4elements.artifacts.httpclient.exceptions.ConnectionException; teichmann@5835: teichmann@5835: import org.dive4elements.river.client.client.services.UserService; teichmann@5835: import org.dive4elements.river.client.server.auth.UserClient; teichmann@5835: import org.dive4elements.river.client.shared.exceptions.AuthenticationException; teichmann@5835: import org.dive4elements.river.client.shared.model.DefaultUser; teichmann@5835: import org.dive4elements.river.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: ingo@3548: UserClient client = new UserClient(url); teichmann@5835: org.dive4elements.river.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 { ingo@3548: Element user = client.findUser(loginuser); ingo@25: ingo@3548: 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: bh@6188: return new DefaultUser(uuid, name, bh@6188: loginuser.getSamlXMLBase64()); 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: } bjoern@4214: bjoern@4214: public void logoutCurrentUser() { bjoern@4214: HttpSession session = this.getThreadLocalRequest().getSession(); bjoern@4214: session.setAttribute("user", null); bjoern@4214: } ingo@2: } ingo@2: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :