1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portlet.webproxy.action;
24  
25  import com.liferay.portal.kernel.portlet.ConfigurationAction;
26  import com.liferay.portal.kernel.servlet.SessionMessages;
27  import com.liferay.portal.kernel.util.Constants;
28  import com.liferay.portal.kernel.util.HttpUtil;
29  import com.liferay.portal.kernel.util.ParamUtil;
30  import com.liferay.portal.kernel.util.StringUtil;
31  import com.liferay.portlet.PortletPreferencesFactoryUtil;
32  
33  import javax.portlet.ActionRequest;
34  import javax.portlet.ActionResponse;
35  import javax.portlet.PortletConfig;
36  import javax.portlet.PortletPreferences;
37  import javax.portlet.RenderRequest;
38  import javax.portlet.RenderResponse;
39  
40  /**
41   * <a href="ConfigurationActionImpl.java.html"><b><i>View Source</i></b></a>
42   *
43   * @author Brian Wing Shun Chan
44   *
45   */
46  public class ConfigurationActionImpl implements ConfigurationAction {
47  
48      public void processAction(
49              PortletConfig portletConfig, ActionRequest actionRequest,
50              ActionResponse actionResponse)
51          throws Exception {
52  
53          String cmd = ParamUtil.getString(actionRequest, Constants.CMD);
54  
55          if (!cmd.equals(Constants.UPDATE)) {
56              return;
57          }
58  
59          String initUrl = ParamUtil.getString(actionRequest, "initUrl");
60  
61          if (!initUrl.startsWith("/") &&
62              !StringUtil.startsWith(initUrl, "http://") &&
63              !StringUtil.startsWith(initUrl, "https://") &&
64              !StringUtil.startsWith(initUrl, "mhtml://")) {
65  
66              initUrl = HttpUtil.getProtocol(actionRequest) + "://" + initUrl;
67          }
68  
69          String scope = ParamUtil.getString(actionRequest, "scope");
70          String proxyHost = ParamUtil.getString(actionRequest, "proxyHost");
71          String proxyPort = ParamUtil.getString(actionRequest, "proxyPort");
72          String proxyAuthentication = ParamUtil.getString(
73              actionRequest, "proxyAuthentication");
74          String proxyAuthenticationUsername = ParamUtil.getString(
75              actionRequest, "proxyAuthenticationUsername");
76          String proxyAuthenticationPassword = ParamUtil.getString(
77              actionRequest, "proxyAuthenticationPassword");
78          String proxyAuthenticationHost = ParamUtil.getString(
79              actionRequest, "proxyAuthenticationHost");
80          String proxyAuthenticationDomain = ParamUtil.getString(
81              actionRequest, "proxyAuthenticationDomain");
82          String stylesheet = ParamUtil.getString(actionRequest, "stylesheet");
83  
84          String portletResource = ParamUtil.getString(
85              actionRequest, "portletResource");
86  
87          PortletPreferences preferences =
88              PortletPreferencesFactoryUtil.getPortletSetup(
89                  actionRequest, portletResource);
90  
91          preferences.setValue("initUrl", initUrl);
92          preferences.setValue("scope", scope);
93          preferences.setValue("proxyHost", proxyHost);
94          preferences.setValue("proxyPort", proxyPort);
95          preferences.setValue("proxyAuthentication", proxyAuthentication);
96          preferences.setValue(
97              "proxyAuthenticationUsername", proxyAuthenticationUsername);
98          preferences.setValue(
99              "proxyAuthenticationPassword", proxyAuthenticationPassword);
100         preferences.setValue(
101             "proxyAuthenticationHost", proxyAuthenticationHost);
102         preferences.setValue(
103             "proxyAuthenticationDomain", proxyAuthenticationDomain);
104         preferences.setValue("stylesheet", stylesheet);
105 
106         preferences.store();
107 
108         SessionMessages.add(
109             actionRequest, portletConfig.getPortletName() + ".doConfigure");
110     }
111 
112     public String render(
113             PortletConfig portletConfig, RenderRequest renderRequest,
114             RenderResponse renderResponse)
115         throws Exception {
116 
117         return "/html/portlet/web_proxy/configuration.jsp";
118     }
119 
120 }