ldap-server.jspf 14.8 KB
Newer Older
Gaston Dombiak's avatar
Gaston Dombiak committed
1
<%@ page import="org.jivesoftware.util.LocaleUtils"%>
2 3 4
<%@ page import="org.jivesoftware.util.ParamUtils"%>
<%@ page import="org.jivesoftware.wildfire.ldap.LdapManager"%>
<%@ page import="java.util.*" %>
Gaston Dombiak's avatar
Gaston Dombiak committed
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22

<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt" %>
<%
    String host;
    int port = 389;
    String baseDN;
    String adminDN;
    String adminPassword;
    boolean connectionPoolEnabled = true;
    boolean sslEnabled = false;
    boolean debugEnabled = false;
    boolean referralsEnabled = false;

    // Get parameters
    boolean save = request.getParameter("save") != null;
    boolean test = request.getParameter("test") != null;

23
    LdapManager manager = LdapManager.getInstance();
Gaston Dombiak's avatar
Gaston Dombiak committed
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
    Map<String, String> errors = new HashMap<String, String>();

    if (save || test) {
        host = ParamUtils.getParameter(request, "host");
        if (host == null) {
            errors.put("host", LocaleUtils.getLocalizedString("setup.ldap.server.host_error"));
        }
        port = ParamUtils.getIntParameter(request, "port", port);
        if (port <= 0) {
            errors.put("port", LocaleUtils.getLocalizedString("setup.ldap.server.port_error"));
        }
        baseDN = ParamUtils.getParameter(request, "basedn");
        if (baseDN == null) {
            errors.put("baseDN", LocaleUtils.getLocalizedString("setup.ldap.server.basedn_error"));
        }
        adminDN = ParamUtils.getParameter(request, "admindn");
        adminPassword = ParamUtils.getParameter(request, "adminpwd");
        connectionPoolEnabled =
                ParamUtils.getBooleanParameter(request, "connectionpool", connectionPoolEnabled);
        sslEnabled = ParamUtils.getBooleanParameter(request, "ssl", sslEnabled);
        debugEnabled = ParamUtils.getBooleanParameter(request, "debug", debugEnabled);
        referralsEnabled = ParamUtils.getBooleanParameter(request, "referrals", referralsEnabled);

        if (errors.isEmpty()) {
            // Store settings in a map and keep it in the session
            Map<String, String> settings = new HashMap<String, String>();
            settings.put("ldap.serverType", serverType);
            settings.put("ldap.host", host);
            settings.put("ldap.port", Integer.toString(port));
            settings.put("ldap.baseDN", baseDN);
            settings.put("ldap.adminDN", adminDN);
            settings.put("ldap.adminPassword", adminPassword);
            settings.put("ldap.connectionPoolEnabled",
                    Boolean.toString(connectionPoolEnabled));
            settings.put("ldap.sslEnabled", Boolean.toString(sslEnabled));
            settings.put("ldap.debugEnabled", Boolean.toString(debugEnabled));
            settings.put("ldap.autoFollowReferrals", Boolean.toString(referralsEnabled));
            // Always disable connection pooling so that connections aren't left hanging open.
            settings.put("ldap.connectionPoolEnabled", "false");
            session.setAttribute("ldapSettings", settings);

            if (save) {
                // Save settings and redirect
67 68 69 70 71 72 73 74 75 76 77 78 79 80
                Collection<String> hosts = new ArrayList<String>();
                StringTokenizer st = new StringTokenizer(host, " ,\t\n\r\f");
                while (st.hasMoreTokens()) {
                    hosts.add(st.nextToken());
                }
                manager.setHosts(hosts);
                manager.setPort(port);
                manager.setBaseDN(baseDN);
                manager.setAdminDN(adminDN);
                manager.setAdminPassword(adminPassword);
                manager.setConnectionPoolEnabled(connectionPoolEnabled);
                manager.setSslEnabled(sslEnabled);
                manager.setDebugEnabled(debugEnabled);
                manager.setFollowReferralsEnabled(referralsEnabled);
Gaston Dombiak's avatar
Gaston Dombiak committed
81 82 83 84 85 86

                // Redirect to next step.
                response.sendRedirect(nextPage);
                return;
            }
        }
87
    } else {
Gaston Dombiak's avatar
Gaston Dombiak committed
88
        // See if there are already values for the variables defined.
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
        StringBuilder sb = new StringBuilder();
        for (String aHost : LdapManager.getInstance().getHosts()) {
            sb.append(aHost).append(", ");
        }
        host = sb.toString();
        if (host.trim().length() > 0) {
            host = host.substring(0, host.length() - 2);
        }
        port = manager.getPort();
        baseDN = manager.getBaseDN();
        adminDN = manager.getAdminDN();
        adminPassword = manager.getAdminPassword();
        connectionPoolEnabled = manager.isConnectionPoolEnabled();
        sslEnabled = manager.isSslEnabled();
        debugEnabled = manager.isDebugEnabled();
        referralsEnabled = manager.isFollowReferralsEnabled();
Gaston Dombiak's avatar
Gaston Dombiak committed
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247
    }
%>
<html>
<head>
    <title><fmt:message key="setup.ldap.title" /></title>
    <% for (Map.Entry<String, String> entry : meta.entrySet()) { %>
    <meta name="<%= entry.getKey()%>" content="<%= entry.getValue()%>"/>
    <% } %>
</head>
<body>

    <% if (test && errors.isEmpty()) { %>

        <a href="<%= testPage%>" id="lbmessage" title="<fmt:message key="global.test" />" style="display:none;"></a>
        <script type="text/javascript">
            function loadMsg() {
                var lb = new lightbox(document.getElementById('lbmessage'));
                lb.activate();
            }
            setTimeout('loadMsg()', 250);
        </script>

    <% } %>

    <% if (initialSetup) { %>
    <h1><fmt:message key="setup.ldap.profile" />: <span><fmt:message key="setup.ldap.connection_settings" /></span></h1>
    <% } %>

    <!-- BEGIN jive-contentBox_stepbar -->
	<div id="jive-contentBox_stepbar">
		<span class="jive-stepbar_step"><strong>1. <fmt:message key="setup.ldap.connection_settings" /></strong></span>
		<span class="jive-stepbar_step"><em>2. <fmt:message key="setup.ldap.user_mapping" /></em></span>
		<span class="jive-stepbar_step"><em>3. <fmt:message key="setup.ldap.group_mapping" /></em></span>
	</div>
	<!-- END jive-contentBox-stepbar -->

    <!-- BEGIN jive-contentBox -->
    <div class="jive-contentBox jive-contentBox_for-stepbar">

	<h2><fmt:message key="setup.ldap.step_one" />: <span><fmt:message key="setup.ldap.connection_settings" /></span></h2>
	<p><fmt:message key="setup.ldap.server.description" /></p>

    <%  if (errors.size() > 0) { %>

    <div class="error">
        <% for (String error:errors.values()) { %>
            <%= error%><br/>
        <% } %>
    </div>

    <%  } %>

    <form action="<%= currentPage%>" method="post">
		<!-- BEGIN jive-contentBox_bluebox -->
		<div class="jive-contentBox_bluebox">
			<table border="0" cellpadding="0" cellspacing="2">
			<tr>
			    <td colspan="4"><strong><fmt:message key="setup.ldap.server.ldap_server" /></strong></td>
			</tr>
            <% if (initialSetup) { %>
            <tr>
                <td align="right" width="1%" nowrap="nowrap"><fmt:message key="setup.ldap.server.type" />:</td>
                <td colspan="3" nowrap>
                    <select name="servertype" size="1" id="jiveLDAPserverType" style="width:90%;">
                        <option value="1" <%= serverType == null ? "selected" : "" %>><fmt:message key="setup.ldap.server.type_select" /></option>
                        <option value="2" <%= "activedirectory".equals(serverType) ? "selected" : "" %>>Active Directory</option>
                        <option value="3" <%= "openldap".equals(serverType) ? "selected" : "" %>>OpenLDAP</option>
                        <option value="4" <%= "other".equals(serverType) ? "selected" : "" %>><fmt:message key="setup.ldap.server.type_other" /></option>
                    </select><span class="jive-setup-helpicon" onmouseover="domTT_activate(this, event, 'content', '<fmt:message key="setup.ldap.server.type_help" />', 'styleClass', 'jiveTooltip', 'trail', true, 'delay', 300, 'lifetime', 8000);"></span>
                </td>
			</tr>
            <% } %>
            <tr>
			    <td align="right" width="1%" nowrap="nowrap"><fmt:message key="setup.ldap.server.host" />:</td>
                <td width="1%">
                    <table cellpadding="0" cellspacing="0" border="0" width="100%">
                    <tr>
                        <td width="1%" nowrap="nowrap">
                            <input type="text" name="host" id="jiveLDAPphost" size="22" maxlength="50" value="<%= host!=null?host:"" %>">
                        </td>
                        <td width="99%">
                            <span class="jive-setup-helpicon" onmouseover="domTT_activate(this, event, 'content', '<fmt:message key="setup.ldap.server.host_help" />', 'styleClass', 'jiveTooltip', 'trail', true, 'delay', 300, 'lifetime', 8000);"></span>
                        </td>
                    </tr>
                    </table>
                </td>
                <td align="right" width="1%" nowrap="nowrap">&nbsp;&nbsp; <fmt:message key="setup.ldap.server.port" />:</td>
                <td><input type="text" name="port" id="jiveLDAPport" size="5" maxlength="5" value="<%= port %>"><span class="jive-setup-helpicon" onmouseover="domTT_activate(this, event, 'content', '<fmt:message key="setup.ldap.server.port_help" />', 'styleClass', 'jiveTooltip', 'trail', true, 'delay', 300, 'lifetime', 8000);"></span></td>
			</tr>
			<tr>
                <td align="right"><fmt:message key="setup.ldap.server.basedn" />:</td>
                <td colspan="3">
                    <input type="text" name="basedn" id="jiveLDAPbasedn" size="40" maxlength="150" value="<%= baseDN!=null?baseDN:""%>" style="width:90%;">
                    <span class="jive-setup-helpicon" onmouseover="domTT_activate(this, event, 'content', '<fmt:message key="setup.ldap.server.basedn_help" />', 'styleClass', 'jiveTooltip', 'trail', true, 'delay', 300, 'lifetime', 16000);"></span>
                </td>
			</tr>
            <tr><td colspan="4">&nbsp;</td></tr>
            <tr>
			    <td colspan="4"><strong><fmt:message key="setup.ldap.server.auth" />:</strong></td>
			</tr>
			<tr>
                <td align="right" width="1%" nowrap="nowrap"><fmt:message key="setup.ldap.server.admindn" />:</td>
                <td colspan="3">
                    <input type="text" name="admindn" id="jiveLDAPadmindn" size="40" maxlength="150" value="<%= adminDN!=null?adminDN:""%>" style="width:90%;">
                    <span class="jive-setup-helpicon" onmouseover="domTT_activate(this, event, 'content', '<fmt:message key="setup.ldap.server.admindn_help" />', 'styleClass', 'jiveTooltip', 'trail', true, 'delay', 300, 'lifetime', -1);"></span>
                </td>
			</tr>
			<tr>
                <td align="right" width="1%" nowrap="nowrap"><fmt:message key="setup.ldap.server.password" />:</td>
                <td colspan="3"><input type="password" name="adminpwd" id="jiveLDAPadminpwd" size="22" maxlength="30" value="<%= adminPassword!=null?adminPassword:""%>"> <span class="jive-setup-helpicon" onmouseover="domTT_activate(this, event, 'content', '<fmt:message key="setup.ldap.server.password_help" />', 'styleClass', 'jiveTooltip', 'trail', true, 'delay', 300, 'lifetime', 8000);"></span></td>
			</tr>
			</table>
		</div>
		<!-- END jive-contentBox_bluebox -->


		<!-- BEGIN jiveAdvancedButton -->
		<div class="jiveAdvancedButton">
			<a href="#" onclick="togglePanel(jiveAdvanced); return false;" id="jiveAdvancedLink"><fmt:message key="setup.ldap.advanced" /></a>
		</div>
		<!-- END jiveAdvancedButton -->

		<!-- BEGIN jiveAdvancedPanelcs (advanced connection settings) -->
		<div class="jiveadvancedPanelcs" id="jiveAdvanced" style="display: none;">
			<div>
				<table border="0" cellpadding="0" cellspacing="1">
				<thead>
				<tr>
					<th width="10%"></th>
					<th></th>
					<th width="50"><fmt:message key="global.yes" /></th>
					<th width="50"><fmt:message key="global.no" /></th>
				</tr>
				</thead>
				<tbody>
				<tr>
					<td class="jive-advancedLabel" nowrap>
						<fmt:message key="setup.ldap.server.connection_pool" />:
					</td>
					<td class="jive-advancedDesc jive-advancedBorderBottom jive-advancedBorderRight">
					    <fmt:message key="setup.ldap.server.connection_pool_help" />
					</td>
					<td class="jive-advancedBorderBottom jive-advancedBorderRight" align="center">
248
						<input type="radio" name="connectionpool" value="true" <% if (connectionPoolEnabled) { %>checked <% } %>>
Gaston Dombiak's avatar
Gaston Dombiak committed
249 250
					</td>
					<td class="jive-advancedBorderBottom" align="center">
251
						<input type="radio" name="connectionpool" value="false" <% if (!connectionPoolEnabled) { %>checked <% } %>>
Gaston Dombiak's avatar
Gaston Dombiak committed
252 253 254 255 256 257 258 259 260 261
					</td>
				</tr>
				<tr>
					<td class="jive-advancedLabel" nowrap>
						<fmt:message key="setup.ldap.server.ssl" />:
					</td>
					<td class="jive-advancedDesc jive-advancedBorderBottom jive-advancedBorderRight">
						<fmt:message key="setup.ldap.server.ssl_help" />
					</td>
					<td class="jive-advancedBorderBottom jive-advancedBorderRight" align="center">
262
						<input type="radio" name="ssl" value="true" <% if (sslEnabled) { %>checked <% } %>>
Gaston Dombiak's avatar
Gaston Dombiak committed
263 264
					</td>
					<td class="jive-advancedBorderBottom" align="center">
265
						<input type="radio" name="ssl" value="false" <% if (!sslEnabled) { %>checked <% } %>>
Gaston Dombiak's avatar
Gaston Dombiak committed
266 267 268 269 270 271 272 273 274 275
					</td>
				</tr>
				<tr>
					<td class="jive-advancedLabel" nowrap>
						<fmt:message key="setup.ldap.server.debug" />:
					</td>
					<td class="jive-advancedDesc jive-advancedBorderBottom jive-advancedBorderRight">
						<fmt:message key="setup.ldap.server.debug_help" />
					</td>
					<td class="jive-advancedBorderBottom jive-advancedBorderRight" align="center">
276
						<input type="radio" name="debug" value="true" <% if (debugEnabled) { %>checked <% } %>>
Gaston Dombiak's avatar
Gaston Dombiak committed
277 278
					</td>
					<td class="jive-advancedBorderBottom" align="center">
279
						<input type="radio" name="debug" value="false" <% if (!debugEnabled) { %>checked <% } %>>
Gaston Dombiak's avatar
Gaston Dombiak committed
280 281 282 283 284 285 286 287 288 289
					</td>
				</tr>
				<tr>
					<td class="jive-advancedLabel" nowrap>
						<fmt:message key="setup.ldap.server.referral" />:
					</td>
					<td class="jive-advancedDesc jive-advancedBorderBottom jive-advancedBorderRight">
						<fmt:message key="setup.ldap.server.referral_help" />
					</td>
					<td class="jive-advancedBorderBottom jive-advancedBorderRight" align="center">
290
						<input type="radio" name="referrals" value="true" <% if (referralsEnabled) { %>checked <% } %>>
Gaston Dombiak's avatar
Gaston Dombiak committed
291 292
					</td>
					<td class="jive-advancedBorderBottom" align="center">
293
						<input type="radio" name="referrals" value="false" <% if (!referralsEnabled) { %>checked <% } %>>
Gaston Dombiak's avatar
Gaston Dombiak committed
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326
					</td>
				</tr>
				</tbody>
				</table>
			</div>
		</div>
		<!-- END jiveAdvancedPanelcs (advanced connection settings) -->


		<!-- BEGIN jive-buttons -->
		<div class="jive-buttons">

			<!-- BEGIN right-aligned buttons -->
			<div align="right">

                <input type="Submit" name="test" value="<fmt:message key="setup.ldap.test" />" id="jive-setup-test" border="0">

                <input type="Submit" name="save" value="<fmt:message key="setup.ldap.continue" />" id="jive-setup-save" border="0">
			</div>
			<!-- END right-aligned buttons -->

		</div>
		<!-- END jive-buttons -->

	</form>

	</div>
	<!-- END jive-contentBox -->



</body>
</html>