001/*
002 * This library is part of OpenCms -
003 * the Open Source Content Management System
004 *
005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com)
006 *
007 * This library is free software; you can redistribute it and/or
008 * modify it under the terms of the GNU Lesser General Public
009 * License as published by the Free Software Foundation; either
010 * version 2.1 of the License, or (at your option) any later version.
011 *
012 * This library is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015 * Lesser General Public License for more details.
016 *
017 * For further information about Alkacon Software, please see the
018 * company website: http://www.alkacon.com
019 *
020 * For further information about OpenCms, please see the
021 * project website: http://www.opencms.org
022 *
023 * You should have received a copy of the GNU Lesser General Public
024 * License along with this library; if not, write to the Free Software
025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
026 */
027
028package org.opencms.ui.client.login;
029
030import org.opencms.gwt.shared.CmsGwtConstants;
031import org.opencms.ui.shared.login.I_CmsLoginTargetRpc;
032
033import com.google.gwt.dom.client.Document;
034import com.google.gwt.dom.client.Element;
035import com.google.gwt.dom.client.FormElement;
036import com.google.gwt.dom.client.InputElement;
037import com.google.gwt.user.client.Window;
038import com.vaadin.client.ServerConnector;
039import com.vaadin.client.extensions.AbstractExtensionConnector;
040import com.vaadin.shared.ui.Connect;
041
042/**
043 * Connector for the login target opener widget.<p>
044 */
045@Connect(org.opencms.ui.login.CmsLoginTargetOpener.class)
046public class CmsLoginTargetOpenerConnector extends AbstractExtensionConnector {
047
048    /** Default version id. */
049    private static final long serialVersionUID = 1L;
050
051    /**
052     * Creates a new instance.<p>
053     */
054    public CmsLoginTargetOpenerConnector() {
055
056    }
057
058    /**
059     * @see com.vaadin.client.extensions.AbstractExtensionConnector#extend(com.vaadin.client.ServerConnector)
060     */
061    @Override
062    protected void extend(ServerConnector extendedComponent) {
063
064        registerRpc(I_CmsLoginTargetRpc.class, new I_CmsLoginTargetRpc() {
065
066            private static final long serialVersionUID = 1L;
067
068            public void openTargetForPrivatePc(String target) {
069
070                // Post a hidden form with user name and password fields,
071                // to hopefully trigger the browser's password manager
072                Document doc = Document.get();
073                FormElement formEl = (FormElement)doc.getElementById("opencms-login-form");
074
075                // make sure user name and password are children of the form
076                Element user = doc.getElementById("hidden-username");
077                Element password = doc.getElementById("hidden-password");
078
079                if ((user != null) && !formEl.isOrHasChild(user)) {
080                    formEl.appendChild(user);
081                }
082                if ((password != null) && !formEl.isOrHasChild(password)) {
083                    formEl.appendChild(password);
084                }
085
086                InputElement requestedResourceField = doc.createTextInputElement();
087                requestedResourceField.setName(CmsGwtConstants.PARAM_LOGIN_REDIRECT);
088                requestedResourceField.setValue(target);
089
090                formEl.appendChild(requestedResourceField);
091                formEl.submit();
092            }
093
094            public void openTargetForPublicPc(String target) {
095
096                // in this case we do not want to trigger the browsers password manager, just call the login target
097                Window.Location.assign(target);
098            }
099        });
100    }
101
102}