view gwt-client/src/main/java/org/dive4elements/river/client/server/ServerInfoServiceImpl.java @ 8839:2c8259176c46

Add configurable time tolerance to SAML ticket validation. This allows e.g. to account for time skew between the ISP and the server this servlet is run on.
author Tom Gottfried <tom@intevation.de>
date Wed, 28 Jun 2017 20:09:53 +0200
parents 238fc722f87a
children a805211690f7
line wrap: on
line source
package org.dive4elements.river.client.server;

import java.util.HashMap;
import java.util.Map;

import javax.xml.xpath.XPathConstants;

import org.apache.log4j.Logger;
import org.dive4elements.artifacts.common.ArtifactNamespaceContext;
import org.dive4elements.artifacts.common.utils.XMLUtils;
import org.dive4elements.artifacts.httpclient.http.HttpClient;
import org.dive4elements.artifacts.httpclient.http.HttpClientImpl;
import org.dive4elements.river.client.client.services.ServerInfoService;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

public class ServerInfoServiceImpl extends RemoteServiceServlet implements
        ServerInfoService {

    // This works only because currently there is only one info transmitted
    private static final String XPATH_INFO = "/art:server/art:info";

    private final Logger log = Logger.getLogger(ServerInfoServiceImpl.class);

    @Override
    public Map<String, String> getConfig(String locale) {
        Map<String, String> infoMap = new HashMap<String, String>();
        String url = getServletContext().getInitParameter("server-url");

        Document doc = XMLUtils.newDocument();

        XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator(
            doc,
            ArtifactNamespaceContext.NAMESPACE_URI,
            ArtifactNamespaceContext.NAMESPACE_PREFIX);

        doc.appendChild(ec.create("action"));

        HttpClient client = new HttpClientImpl(url, locale);

        try {
            Document res = client.callService(url, "server-info", doc);

            NodeList info = (NodeList) XMLUtils.xpath(res,
                    XPATH_INFO,
                    XPathConstants.NODESET,
                    ArtifactNamespaceContext.INSTANCE);

            for (int n = 0; n < info.getLength(); n++) {
                Element el = (Element)info.item(n);
                String key = el.getAttributeNS(
                        ArtifactNamespaceContext.NAMESPACE_URI, "key");
                String val = el.getAttributeNS(
                        ArtifactNamespaceContext.NAMESPACE_URI, "value");
                infoMap.put(key, val);

                log.debug("ServerInfoServiceImpl: " + key + "=" + val);
            }
        }
        catch (Exception ex) {
            log.error(ex, ex);
        }

        return infoMap;
    }


}

http://dive4elements.wald.intevation.org