view flys-client/src/main/java/de/intevation/flys/client/server/UserServiceImpl.java @ 4740:fb135e1dfa35

Added 'type' attribute to <dc:variable/> element. If an optional 'type' attribute is given the result of the XPATH expression is interpreted as this type. Valid values are 'number', 'bool', 'node' and 'nodeset'. All other defaults to 'string' which also is the default if nor type is given.
author Sascha L. Teichmann <teichmann@intevation.de>
date Wed, 02 Jan 2013 15:31:53 +0100
parents e39ac9767a69
children
line wrap: on
line source
package de.intevation.flys.client.server;

import javax.servlet.http.HttpSession;

import org.w3c.dom.Element;

import org.apache.log4j.Logger;

import de.intevation.artifacts.common.ArtifactNamespaceContext;

import de.intevation.artifacts.httpclient.exceptions.ConnectionException;

import de.intevation.flys.client.client.services.UserService;
import de.intevation.flys.client.server.auth.UserClient;
import de.intevation.flys.client.shared.exceptions.AuthenticationException;
import de.intevation.flys.client.shared.model.DefaultUser;
import de.intevation.flys.client.shared.model.User;

/**
 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
 */
public class UserServiceImpl
extends      RemoteServiceServlet
implements   UserService
{
    /** Private logger. */
    private static final Logger logger = Logger.getLogger(UserServiceImpl.class);

    public static final String ERROR_NO_SUCH_USER = "error_no_such_user";

    public static final String ERROR_NO_USERS = "error_no_users";

    public User getCurrentUser(String locale)
    throws AuthenticationException
    {
        String url = getServletContext().getInitParameter("server-url");

        UserClient client = new UserClient(url);
        de.intevation.flys.client.server.auth.User loginuser = getUser();

        if (loginuser == null) {
            logger.debug("no session user");
            throw new AuthenticationException(ERROR_NO_SUCH_USER);
        }

        try {
            Element user = client.findUser(loginuser);

            if (user != null) {
                String uuid = user.getAttributeNS(
                        ArtifactNamespaceContext.NAMESPACE_URI, "uuid");
                String name = user.getAttributeNS(
                        ArtifactNamespaceContext.NAMESPACE_URI, "name");

                return new DefaultUser(uuid, name);
            }
        }
        catch (ConnectionException ce) {
            logger.error(ce, ce);
        }

        logger.error("No users existing in the server.");
        throw new AuthenticationException(ERROR_NO_USERS);
    }

    public void logoutCurrentUser() {
        HttpSession session = this.getThreadLocalRequest().getSession();
        session.setAttribute("user", null);
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org